Algebra
On this page
Like most query engines, instead of internally working directly with a SPARQL query string, Comunica works with an algebraic representation of a SPARQL query, corresponding to the SPARQL 1.1 algebra. This SPARQL algebra makes it easier for operating on SPARQL operators in a consistent manner, and for applying transformations during query optimization.
Query Operation Actors
All actors on the Query Operation bus
correspond to exactly one SPARQL algebra operator type.
For example, @comunica/actor-query-operation-construct
handles algebra operations with type 'construct'.
Traqula
Converting a query string to SPARQL algebra
happens in the SPARQL Parse bus.
The @comunica/actor-query-parse-sparql actor
on this bus makes use of the Traqula framework.
Examples on how the conversion between SPARQL query string and SPARQL algebra happens can be found in the specific SPARQL algebra 1.2 package. Example transformations can be found as part of Traqula's test suite.
Converting a SPARQL query into algebra
If you want to quickly check what the algebra of a given SPARQL query string looks like, you can make use of Comunica's explain functionality as follows:
$ comunica-sparql https://fragments.dbpedia.org/2016-04/en -q 'SELECT * { ?s ?p ?o }' --explain parsed { "type": "project", "input": { "type": "bgp", "patterns": [ { "termType": "Quad", "value": "", "subject": { "termType": "Variable", "value": "s" }, "predicate": { "termType": "Variable", "value": "p" }, "object": { "termType": "Variable", "value": "o" }, "graph": { "termType": "DefaultGraph", "value": "" }, "type": "pattern" } ] }, "variables": [ { "termType": "Variable", "value": "s" }, { "termType": "Variable", "value": "p" }, { "termType": "Variable", "value": "o" } ] }
This tool is therefore useful if you want to implement support for a SPARQL operator, but you need to find out to what algebra operation this corresponds.
[!note] Before implementing support for a SPARQL operator, read our tutorial on contributing an actor and contributing a new operator.