使用Jena在DBpedia上创建SPARQL查询 [英] Using Jena to create a SPARQL query on DBpedia

查看:106
本文介绍了使用Jena在DBpedia上创建SPARQL查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用Jena创建一个SPARQL查询来查询DBpedia。

Im trying to create a SPARQL query using Jena to query DBpedia.

当我将它与独立工具(Twinkle)一起使用时,查询正在运行,但当我将其插入此Java代码时,它返回一个空集。

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?

推荐答案

问题是你的 FROM< ...> 条款。删除它,一切都很好。使用该子句我怀疑端点是将查询限制为具有该名称的图形,但是不存在这样的图形,因此没有结果。

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.

令人困惑的事情似乎查询适用于 http://dbpedia.org/sparql 上的表单。但是,设置了默认图形URI,因此查询也会覆盖该图形。清除它,查询不起作用。作为替代方案,您可以将其设置为检索远程数据。拉出了命名的rdf,它提到了三个出生地。

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:

{ <http://dbpedia.org/resource/Daphne_Oram> dbont:birthPlace ?place . }

这篇关于使用Jena在DBpedia上创建SPARQL查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆