I will answer my own question, then. In rdflib/plugins/sparql/algebra.py, the function translateQuery uses the traverse function to translate the second part of the query (after the prologue), and then further translates to create the query algebra. The answer to my question then would be:
* The traverse function acts on the Query syntax producing by parsing the query. There is no real included capability to do a transform on the algebra. * To use traverse yourself, first use rdflib.plugins.sparql.parser.parseQuery to parse the query, and then use traverse to modify that query. * To translate it into algebra, pass it to rdflib.plugins.sparql.algebra.translateQuery directly. However, there is no good way to unparse the query that I see. On Wednesday, April 3, 2019 at 10:32:06 AM UTC-4, Dan Davis wrote: > > Does rdflib.plugins.sparql have any facilities for doing transforms? > I've tried to figure this out, but I cannot quite see the right way to do > it. > It looks like it ought to be possible, but the documentation doesn't quite > get me there. > > I can prepare a query and print the query algebra: > > query = prepareQuery(querytext) > query.algebra > > I also see that there is a function > rdflib.plugins.sparql.algebra.traverse, but I'm not quite sure how to > transform a query with that. > > A simple example would be great. > > Also, if there's anyway to do a transformation on the SPARQL syntax tree > separate from the algebra, that would be great too. > > Thanks, > > -Dan > > > -- http://github.com/RDFLib --- You received this message because you are subscribed to the Google Groups "rdflib-dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/rdflib-dev/01ee05a9-81ad-4131-b267-3c00be0fcf4e%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
