繁体   English   中英

Jena Sparql和构造

[英]Jena Sparql and construct

CONSTRUCTSELECT的替代SPARQL结果子句。 CONSTRUCT返回结果值表,而是返回RDF图。 例如,在以下Java代码中运行此查询会产生HttpException: 406 Unacceptable 但是如果不是CONSTRUCT块,我选择SELECT ?x ,它就好了。 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);

Jena支持CONSTRUCT ,但要获得结果,您需要调用另一个方法,因为execSelectResultSet仅用于SELECT查询。 请改用:

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

Model是Jena用于访问RDF图的界面,有关详细信息,请参阅javadocs

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

暂无
暂无

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

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