Search code examples
sparqlrdf4j

RDF4j ParsedQuery or TupleExpr to String Represenation


I have a SPARQL query and I want to replace some of the URIs it contains based on a dictionary. I constructed a AbstractQueryModelVisitor that does that, i.e., it substitutes the URIs I want. But once they are substituted, I'm not sure how to get back the string representation of the SPARQL query. I only have the ParsedQuery or TupleExpr of it. Is it possible to convert these representations back to a String representation?

Thank you


Solution

  • There is a SPARQLQueryRenderer class which can convert a ParsedQuery back to a SPARQL query string, however it has not been updated past SPARQL 1.0. It may serve your purposes, depending on how complex your query is, but for anything involving 1.1 features such as subqueries or aggregates, it's unlikely to work.