So, still cannot see how to unparse, but if I already know the structure of the query a bit, I can manipulate as follows
import rdflib from rdflib.plugins.sparql.parser import parseQuery q = parseQuery(something) if q[1].where.part[2].triples[0][2] == rdflib.Variable('parent'): q[1].where.part[2].triples[0][2] = rdflib.URIRef('http://example.org/fubar#4') This doesn't quite help with the SPARQLWrapper, because there is no great way to "unparse" the query, but it almost does. On Thursday, April 4, 2019 at 2:31:32 PM UTC-4, Dan Davis wrote: > > 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. > >> >> -- 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 rdflib-dev+unsubscr...@googlegroups.com. To post to this group, send email to rdflib-dev@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/rdflib-dev/9c9baf92-9df9-474a-95d6-03f78be1bb5d%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.