Jena Sparql and construct

南笙酒味 提交于 2019-12-01 04:51:39

问题


CONSTRUCT is an alternative SPARQL result clause to SELECT. Instead of returning a table of result values, CONSTRUCT returns an RDF graph. For instance, running this query in the following Java code produces an HttpException: 406 Unacceptable. But if instead of the CONSTRUCT block, I choose SELECT ?x, it's just fine. Does Jena support CONSTRUCT, and if so, how? Both queries are acceptable to 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);

回答1:


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

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

Model is Jena's interface for accessing RDF graphs, see the javadocs for details.




回答2:


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



来源:https://stackoverflow.com/questions/2976809/jena-sparql-and-construct

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!