1

With python's rdflib I can parse a SPARQL query string and translate its algebraic form with following syntax:

statement = "Select ?s ?p ?o where {?s ?p ?o.}"
query_tree = parser.parseQuery(statement) # query parse-tree
q_algebra = algebra.translateQuery(query_tree) # query algebra
algebra.pprintAlgebra(q_algebra)

This is how the algebra tree of above query looks like:

SelectQuery(
    p = Project(
        p = BGP(
            triples = [(rdflib.term.Variable('s'), rdflib.term.Variable('p'), rdflib.term.Variable('o'))]
            _vars = {rdflib.term.Variable('s'), rdflib.term.Variable('p'), rdflib.term.Variable('o')}
            )
        PV = [rdflib.term.Variable('s'), rdflib.term.Variable('p'), rdflib.term.Variable('o')]
        _vars = {rdflib.term.Variable('s'), rdflib.term.Variable('p'), rdflib.term.Variable('o')}
        )
    datasetClause = None
    PV = [rdflib.term.Variable('s'), rdflib.term.Variable('p'), rdflib.term.Variable('o')]
    _vars = {rdflib.term.Variable('s'), rdflib.term.Variable('p'), rdflib.term.Variable('o')}
    )

After updating the query algebra by e.g. using algebra.traverse(q_algebra, update_function) I want to get a query string again. I searched quiet a lot through the rdflib module but could not find a way how to back translate the algebra. Is there a function that takes the SPARQL query algebra as an input and returns a SPARQL query string?

Greenfish
  • 358
  • 2
  • 5
  • 19

1 Answers1

0

No, and thanks to you Greenfish for providing this functionality in rdflib 6.0.0 yourself at https://github.com/RDFLib/rdflib/pull/1322

Nicholas Car
  • 1,164
  • 4
  • 7