简体   繁体   English

Jena Sparql和构造

[英]Jena Sparql and construct

CONSTRUCT is an alternative SPARQL result clause to SELECT . CONSTRUCTSELECT的替代SPARQL结果子句。 Instead of returning a table of result values, CONSTRUCT returns an RDF graph. CONSTRUCT返回结果值表,而是返回RDF图。 For instance, running this query in the following Java code produces an HttpException: 406 Unacceptable . 例如,在以下Java代码中运行此查询会产生HttpException: 406 Unacceptable But if instead of the CONSTRUCT block, I choose SELECT ?x , it's just fine. 但是如果不是CONSTRUCT块,我选择SELECT ?x ,它就好了。 Does Jena support CONSTRUCT , and if so, how? Jena是否支持CONSTRUCT ,如果支持,如何支持? Both queries are acceptable to the DBpedia endpoint . 这两个查询都可以被DBpedia端点接受。

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);

Jena supports CONSTRUCT , but to get the result you need to call a different method, because execSelect and ResultSet are only for SELECT queries. Jena支持CONSTRUCT ,但要获得结果,您需要调用另一个方法,因为execSelectResultSet仅用于SELECT查询。 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. Model是Jena用于访问RDF图的界面,有关详细信息,请参阅javadocs

ResultSetFormatter.out(System.out,results,query)找不到符号和标识符此时发生预期错误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM