A simple SPARQL expression evaluator library.
This package is available on npm, type definitions are provided.
;;// Create an evaluator (a sync evaluator will exist in the future too)// evaluate it as a term;// or evaluate it as an Effective Boolean Value (for e.g in FILTER);
Note: If you want to use aggregates, or exists you should check out the stream section.
Sparqlee exports an Error class called
ExpressionError from which all SPARQL related errors inherit. These might include unbound variables, wrong types, invalid lexical forms, and much more. More info on errors here. These errors can be caught, and may impact program execution in an expected way. All other errors are unexpected, and are thus programmer mistakes or mistakes in this library.
There is also the utility function
isExpressionError for detecting these cases.
// Make sure to catch errors if you don't control binding inputtrycatch error
'Aggregates' and 'Exists' operations are annoying problems to tackle in the context of an expression evaluator, since they make the whole thing stateful. They might span entire streams and, depending on the use case, have very different requirements for speed and memory consumption. Sparqlee has therefore decided to delegate this responsibility back to you (and might provide utility in the future). It accepts functions that will resolve the respective aggregate and exists operators, and will use those when needed. This way, the library can still be optimized for simple use cases, both in it's API as in it's development time, while it can still support the full spec.
NOTE: Aggregates and Exists are not implemented yet.
TODO Add section about differences from the spec and which functions are affected (and which are implemented). See also extensible value testing and error handling.
TODO String literals (plain literals etc...)
TODO Replace with check marks
|+ (unary plus)||✓||✓|
|- (unary minus)||✓||✓|
|Notes||Spec compliance depends on #13 and #14|
|On RDF Terms|
|On Dates and Times|
|XPath Constructor Functions|
|str (see 'On Terms')||✓||✓||✓|
- Use these evident commands (or check
- building once:
yarn run build
- build and watch:
yarn run watch
yarn run test
yarn run bench
- building once:
Adding unimplemented functions
Three kinds exists:
- Regular functions: Functions with a uniform interface, that only need their arguments to calculate their result.
- Special functions: whose behaviour deviates enough from the norm to warrant the implementations taking full control over type checking and evaluation (these are mostly the functional forms).
- Named functions: which correspond to the SPARQLAlgebra Named Expressions.
TODO: Explain this hot mess some more.
Layout and control flow
The only important external facing API is creating an Evaluator. When you create one, the SPARQL Algebra expression that is passed will be transformed to an internal representation (see Transformation.ts). This will build objects (see expressions module) that contain all the logic and data for evaluation, for example the implementations for SPARQL functions (see functions module). After transformation, the evaluator will recursively evaluate all the expressions.
Running tests will generate a
test-report.html in the root dir.
TODO Explain test organizatian and expression tables