问题描述
CONSTRUCT
是SELECT
的替代SPARQL结果子句. CONSTRUCT
而不是返回结果值表,而是返回RDF图.例如,在以下Java代码中运行此查询将生成HttpException: 406 Unacceptable
.但是,如果选择SELECT ?x
而不是CONSTRUCT
块,那就很好了.耶拿(Jena)是否支持CONSTRUCT
,如果支持,怎么支持? DBpedia端点都可以接受这两个查询.
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);
推荐答案
Jena支持CONSTRUCT
,但是要获得结果,您需要调用其他方法,因为execSelect
和ResultSet
仅用于SELECT
查询.改用它:
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
是耶拿访问RDF图的界面,请参见 javadocs 了解详情.
Model
is Jena's interface for accessing RDF graphs, see the javadocs for details.
这篇关于耶拿·斯帕克(Jena Sparql)和构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!