A query language transpiler framework for JavaScript
Modular transformer to transform a SPARQL 1.1 AST generated by Traqula to SPARQL 1.1 algebra. There is also support for 'non-algebra' entities such as ASK, FROM, etc. to make sure the output contains all relevant information from the query.
npm install @traqula/algebra-sparql-1-2
or
yarn add @traqula/algebra-sparql-1-2
Either through ESM import:
import { toAst, toAlgebra } from '@traqula/algebra-sparql-1-2';
or CJS require:
const { toAst, toAlgebra } = require('@traqula/algebra-sparql-1-2');
Input for the translation function should be a Traqula AST, by calling Traqula parser.
Algebra operations are modeled as objects of the structure { name: string; input: Operation[] }.
The transformation is detailed by section 18.3 of the SPARQL 1.2 specification.
The example bellow demonstrates this package usage where we parse a query string and transform it to algebra, from the algebra we will go back to a query string. Note that unlike the AST level, we do not provide round tripping on algebra level.
import { Parser } from '@traqula/parser-sparql-1-2';
import { Generator } from '@traqula/generator-sparql-1-2';
import { toAlgebra, fromAlgebra } from '@traqula/algebra-sparql-1-2';
// Initialize required variables.
const parser = new Parser();
const generator = new Generator();
const query = `SELECT * { ?s ?p ?o }`;
const ast = parser.parse(query);
const algebra = toAlgebra(ast);
const generatedAst = toAst(algebra);
const generatedQuery = generator.generate(generatedAst);
The algebra transformer for SPARQL 1.2 is a modification of the SPARQL 1.1 algebra transformer; therefore, much of the documentation of that transformer holds here too.