Search code examples
sparqljenaapache-jenajena-querybuilder

getting the WHERE from an apache JENA ARQ Query


Is it possible to get the WHERE Clause from a Query org.apache.jena.query.Query ? Haven't found no info enywhere, no documentation anywhere.

Imagine I create a query from a String

String queryString = "    
SELECT ?name ?mbox
    WHERE
      { ?x foaf:name ?name .
        ?x foaf:mbox ?mbox }";

Query query = QueryFactory.create() ;

For example, I can get the variables that the query will request using the query.getResultVars()), but I cannot get any manner to get the WHERE clause/expression or however you wanna call. Just interested in getting this part:

  { ?x foaf:name ?name .
    ?x foaf:mbox ?mbox }

Here's Query API: https://jena.apache.org/documentation/javadoc/arq/org/apache/jena/query/Query.html


Solution

  • Query::getQueryPattern() returns an object of type Element, which is basically the part of the WHERE clause.