Jena Sparql and build

CONSTRUCT is an alternative SPARQL result SELECT before SELECT . Instead of returning a table of result values, CONSTRUCT returns an RDF graph. For example, running this query in the following Java code raises an HttpException: 406 Unacceptable . But if instead of the CONSTRUCT block I select SELECT ?x , this is just fine. Does Jena support CONSTRUCT , and if so, how? Both queries are acceptable for the DBpedia endpoint .

 PREFIX : <http://dbpedia.org/resource/> PREFIX onto: <http://dbpedia.org/ontology/> CONSTRUCT { :France onto:anthem ?x } WHERE { :France onto:anthem ?x . } 
 Query query = QueryFactory.create("the query goes here"); QueryExecution qexec = QueryExecutionFactory.sparqlService("http://dbpedia.org/sparql", query); ResultSet results = qexec.execSelect(); ResultSetFormatter.out(System.out, results, query); 
+4
source share
2 answers

Jena supports CONSTRUCT , but you need to call another method to get the result, because execSelect and ResultSet are only for SELECT queries. Use this instead:

 Model results = qexec.execConstruct(); results.write(System.out, "TURTLE"); 

Model is the Jena interface for accessing RDF charts, see javadocs for more details.

+11
source

ResultSetFormatter.out (System.out, results, query) cannot find the expected symbol and identifier error at this point

+2
source

Source: https://habr.com/ru/post/1311901/


All Articles