2

Suppose I have some jena query object :

String query = "SELECT * WHERE{ ?s <some_uri> ?o ...etc. }";
Query q = QueryFactory.create(query, Syntax.syntaxARQ);

How would one go about getting information about the jena query object and adding in triples to it iteratively in an effective manner? For example, suppose I wanted to add in the triples

?o dcterms:title "TheBestTitle".
?o dcterms:date ?date.

to the query, and perhaps more.
Is there some way to add in these triples to the query, or do some magic to create a new query object which looks like the original with those triples added in? Assume that I may need to grab information from the original version of the query as well (for example, List resultVars = q.getResultVars();).

Some leads I have are to use the AlgebraGenerator and Op Classes provided by the Jena API, but I can't seem to find any reasonable use cases in a context such as this.

Thanks!

Nick Bartlett
  • 4,315
  • 1
  • 20
  • 37

1 Answers1

2

http://jena.apache.org/documentation/query/manipulating_sparql_using_arq.html

  1. Construct an algebra expression and convert to a query (OpAsQuery)
  2. The Query object, which is the cleaned up parsed struture, can be manipulated (Query.getQueryPattern)
  3. Do it by string manipulation before parsing.
AndyS
  • 14,989
  • 15
  • 20