
Product
Introducing GitHub Actions Scanning Support
Detect malware, unsafe data flows, and license issues in GitHub Actions with Socket’s new workflow scanning support.
@comunica/expression-evaluator
Advanced tools
Previously called sparqlee - sparql expression evaluator. A simple spec-compliant SPARQL 1.1 expression evaluator package.
Learn more about the expression evaluator.
This module is part of the Comunica framework, and should only be used by developers that want to build their own query engine.
Click here if you just want to query with Comunica.
$ yarn add @comunica/expression-evaluator
AsyncEvaluator: An evaluator for SPARQL expressions working with Promises.IAsyncEvaluatorContext: Context used to configure the AsyncEvaluator. See Config.SyncEvaluator: An evaluator for SPARQL expressions working without Promises.ISyncEvaluatorContext: Context used to configure the SyncEvaluator. See Config.AggregateEvaluator: An evaluator for SPARQL aggregate expressions working without promises. See Aggregates.ExpressionError: An error class for SPARQL expression errors as defined in the error section.isExpressionError: A way to check if an error is of type ExpressionError.orderTypes: A function to order types according to the SPARQL ORDER BY specification.AsyncAggregateEvaluator: An evaluator for SPARQL aggregate expressions working with promises. See Aggregates.yarn and node.yarn install.package.json):
yarn run buildyarn run benchFunctions are defined in the functions directory, and you can add or fix them there. All definitions are defined using a builder model defined in Helpers.ts.
Three kinds exists:
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 AlgebraTransformer.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.
The testing environment is set up to do a lot of tests with little code.
The files responsible for fluent behaviour reside in the test/util module.
Most tests can be run by running the runTestTable method in utils.
This method expects a TestTable. Multiple test are run over a TestTable (one for every line).
A TestTable may contain aliases if the aliases are also provided
(Some handy aliases reside in Aliases.ts).
This means that when testing something like "3"^^xsd:integer equals "3"^^xsd:integer is "true"^^xsd:boolean.
We would write a small table (for this example some more tests are added) and test it like this:
import { bool, merge, numeric } from './util/Aliases';
import { Notation } from './util/TruthTable';
import { runTestTable } from './util/utils';
runTestTable({
testTable: `
3i 3i = true
3i -5i = false
-0f 0f = true
NaN NaN = false
`,
arity: 2,
operation: '=',
aliases: merge(numeric, bool),
notation: Notation.Infix,
});
More options can be provided and are explained with the type definition of the argument of runTestTable.
We can also provide an errorTable to the runTestTable method.
This is used when we want to test if calling certain functions on certain arguments throws the error we want.
An example is testing whether Unknown named operator error is thrown when
we don't provide the implementation for an extension function.
import { bool, merge, numeric } from './util/Aliases';
import { Notation } from './util/TruthTable';
import { runTestTable } from './util/utils';
runTestTable({
errorTable: `
3i 3i = 'Unknown named operator'
3i -5i = 'Unknown named operator'
-0f 0f = 'Unknown named operator'
NaN NaN = 'Unknown named operator'
`,
arity: 2,
operation: '<https://example.org/functions#equal>',
aliases: merge(numeric, bool),
notation: Notation.Infix,
});
When you don't care what the error is, you can just test for ''.
In case the tables are too restrictive for your test, and you need an evaluation.
You should still use the generalEvaluate function from generalEvaluation.ts.
This function will automatically run both async and sync when possible.
This increases your tests' coverage.
v3.2.1 - 2024-08-07
<a name="v3.2.0"></a>
FAQs
A simple SPARQL expression evaluator
The npm package @comunica/expression-evaluator receives a total of 1,176 weekly downloads. As such, @comunica/expression-evaluator popularity was classified as popular.
We found that @comunica/expression-evaluator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Detect malware, unsafe data flows, and license issues in GitHub Actions with Socket’s new workflow scanning support.

Product
Add real-time Socket webhook events to your workflows to automatically receive pull request scan results and security alerts in real time.

Research
The Socket Threat Research Team uncovered malicious NuGet packages typosquatting the popular Nethereum project to steal wallet keys.