【发布时间】:2014-06-14 10:48:51
【问题描述】:
我测试了那个查询:
SELECT ?comment WHERE {<http://pt.dbpedia.org/resource/Portugal> dcterms:subject ?comment}
http://pt.dbpedia.org/sparql 我得到了正确的结果:
http://pt.dbpedia.org/resource/Categoria:Portugal
但我正在使用 Jena,当我尝试使用 Jena 进行查询时,我没有得到任何结果。 这就是我对 Jena 进行查询的方式:
private String getComment(String uri) {
RDFNode node;
String comment = "";
final String QUERY =
"PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n" +
"PREFIX dcterms: <http://purl.org/dc/terms/subject>\n" +
"SELECT ?comment WHERE {" +
"<" + uri + "> dcterms:subject ?comment." +
"}";
final String ENDPOINT = "http://pt.dbpedia.org/sparql";
final ResultSet rs = QueryExecutionFactory.sparqlService( ENDPOINT, QUERY ).execSelect();
while( rs.hasNext() ) {
QuerySolution querySolution = rs.next();
node = querySolution.get("comment");
comment = node.toString();
}
return comment;
}
有什么问题吗? 谢谢!
【问题讨论】:
-
你还没有展示你是怎么称呼它的。调用时
uri的值是多少? -
哦,对不起!值为:pt.dbpedia.org/resource/Portugal
-
我在http中使用它,正如上面第一个查询中写的那样,这是因为当我将它粘贴到cmets时,它会改变它的形式。
-
您可以在评论(和帖子)中用反引号 (
`) 将文本括起来以使其成为代码,而不是降价文本。
标签: java sparql jena dbpedia dublin-core