Traqula docs
    Preparing search index...

    Migration Guide: SparqlAlgebra to Traqula

    In this guide we explain how one can migrate from SPARQLAlgebra.js to Traqula. Migrating from SPARQLAlgebra.js to Traqula is a breeze.

    The algebra object generated by SPARQLAlgebra.js and Traqula differ only in one component: VALUES. Within SPARQLAlgebra.js the keys of a VALUES object are prefixed with a ? (because this was also the case for sparqljs), in Traqula the key is just the value/ name of the variable. Concretely, in SPARQLAlgebra.js you have { type: "values", variables: [ ... ], bindings: { ?somevar: { ... } } } while in Traqula that is simplified to { type: "values", variables: [ ... ], bindings: { somevar: { ... } } }.

    SPARQLAlgebra.js allowed you to provide a query string to toAlgebra, Traqula does not allow this. The reason is that Traqula tries to force you to reuse your parser since creating one is quite resource intensive.

    In SPARQLAlgebra.js you would write:

    import { translate } from 'sparqlalgebrajs';
    const algebra = translate('SELECT * WHERE { ?x ?y ?z }');

    In Traqula, you would first choose a parser and transform the AST afterward:

    import { Parser } from '@traqula/parser-sparql-1-1';
    import { toAlgebra } from '@traqula/algebra-sparql-1-1';
    const parser = new Parser();
    const ast = parser.parse('SELECT * WHERE { ?x ?y ?z }');
    const algebra = toAlgebra(ast);

    To go from algebra to a SPARQL query string, you would write the following in SPARQLAlgebra.js:

    const { toSparql } = require('sparqlalgebrajs');
    const sparqlQuery = toSparql(algebra)

    In Traqula, you would first need to choose a sparql generator and then:

    import { Generator } from '@traqula/generator-sparql-1-1';
    import { toAST } from '@traqula/algebra-sparql-1-1';
    const generator = new Generator();
    const genAst = toAST(algebra);
    const sparqlQuery = generator.generate(genAst);

    In Traqula, all operations now have a type and an optional subType. In sparqlAlgebra.js you would have ExpressionOperations with a expressionType, in Traqula, expression have a subType.

    SparqlAlgebra.js exposed a Util class to help you manipulate the algebra. In Traqula, we expose a modernized alternative called algebraUtils: algebraUtils contains a few usefully functions (e.g.: mapOperation, mapOperationSub, visitOperation, visitOperationSub, and resolveIRI).

    import { algebraUtils } from "@traqula/algebra-transformations-1-1";
    

    In case you are using TypeScript, mapOperation and mapOperationSub will provide you the type of the operation you are mapping at a particular moment. However, since the values of the operation being mapped might have been changed by deeper mapOperations, the values will be of type unknown. In case you do now want this behaviour, you should call mapoperation like so:

    mapOperation<'unsafe', typeof operation>(operation, {})