Jena Sparql 和构建
CONSTRUCT
是 SELECT
的替代 SPARQL 结果子句。 CONSTRUCT
返回一个 RDF 图,而不是返回结果值表。例如,在以下 Java 代码中运行此查询会产生 HttpException: 406 Unacceptable
。但如果我选择 SELECT ?x
而不是 CONSTRUCT
块,那就没问题了。 Jena 是否支持 CONSTRUCT
?如果支持,如何支持? 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);
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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Jena 支持
CONSTRUCT
,但要获取结果,您需要调用不同的方法,因为execSelect
和ResultSet
仅适用于SELECT< /code> 查询。请使用它:
Model
是 Jena 用于访问 RDF 图的接口,请参阅 javadocs 了解详细信息。Jena supports
CONSTRUCT
, but to get the result you need to call a different method, becauseexecSelect
andResultSet
are only forSELECT
queries. Use this instead:Model
is Jena's interface for accessing RDF graphs, see the javadocs for details.ResultSetFormatter.out(System.out, results, query) 找不到符号和标识符此时发生预期错误
ResultSetFormatter.out(System.out, results, query) cannot find symbol and identifier expected error occurs at this point