使用 Jena 在 DBpedia 上创建 SPARQL 查询
我正在尝试使用 Jena 创建 SPARQL 查询来查询 DBpedia。
当我将其与独立工具 (Twinkle) 一起使用时,该查询可以正常工作,但是当我将其插入此 Java 代码时,它会返回一个空集。
String sparqlQueryString1 = "PREFIX dbont: <http://dbpedia.org/ontology/> " +
"PREFIX dbp: <http://dbpedia.org/property/>" +
"PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>" +
" SELECT ?musician ?place" +
" FROM<http://dbpedia.org/resource/Daphne_Oram>" +
" WHERE { " +
" ?musician dbont:birthPlace ?place ." +
" }";
Query query = QueryFactory.create(sparqlQueryString1);
QueryExecution qexec = QueryExecutionFactory.sparqlService("http://dbpedia.org/sparql", query);
ResultSet results = qexec.execSelect();
ResultSetFormatter.out(System.out, results, query);
qexec.close() ;
有什么想法我做错了吗?
Im trying to create a SPARQL query using Jena to query DBpedia.
The query is working when I use it with standalone tools (Twinkle) but when I plug it in this Java code it returns an empty set.
String sparqlQueryString1 = "PREFIX dbont: <http://dbpedia.org/ontology/> " +
"PREFIX dbp: <http://dbpedia.org/property/>" +
"PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>" +
" SELECT ?musician ?place" +
" FROM<http://dbpedia.org/resource/Daphne_Oram>" +
" WHERE { " +
" ?musician dbont:birthPlace ?place ." +
" }";
Query query = QueryFactory.create(sparqlQueryString1);
QueryExecution qexec = QueryExecutionFactory.sparqlService("http://dbpedia.org/sparql", query);
ResultSet results = qexec.execSelect();
ResultSetFormatter.out(System.out, results, query);
qexec.close() ;
Any ideas what I'm doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是您的
FROM <...>
子句。删除它,一切都好。有了该子句,我怀疑端点将查询限制为具有该名称的图,但不存在这样的图,因此没有结果。令人困惑的是,查询似乎在 http://dbpedia.org/sparql 的表单上运行。但是,设置了默认图形 URI,因此查询也会遍历该图形。清除它,查询就不起作用。作为替代方案,您可以将其设置为检索远程数据。这会引入指定的 rdf,其中提到了三个出生地。
如果您想找到该音乐家的出生地,请使用:
The problem is your
FROM <...>
clause. Remove it and all is well. With that clause in place I suspect the endpoint is limiting the query to the graph with that name, but no such graph exists and thus there is no result.The confusing thing is that it seems like the query works on the form at http://dbpedia.org/sparql. However there a default graph URI is set, so the query goes over that graph too. Clear it and the query doesn't work. As an alternative you can set it to retrieve remote data. That pulls in the named rdf which mentions three birthplaces.
If you're trying to find the birth place of that musician use: