本文介绍了耶拿·斯帕克(Jena Sparql)和构建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CONSTRUCTSELECT的替代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,但是要获得结果,您需要调用其他方法,因为execSelectResultSet仅用于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)和构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 09:19