Sparql 查询出错,导致 + 上的地理信息不正确我所需的属性的结果不存在
我正在使用 ARC2 php 库来发出 sparql 查询,并且我陷入了这个问题(我不认为它与该库有关)。
这个查询工作得很好 - 在我的应用程序和 dbpedia snorql 中:
PREFIX dbo:<http://dbpedia.org/ontology/>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX : <http://dbpedia.org/resource/>
PREFIX dbpedia2: <http://dbpedia.org/property/>
PREFIX dbpedia: <http://dbpedia.org/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX geo: <http://www.geonames.org/ontology#>
SELECT * WHERE {
?c rdf:type dbo:Country;
foaf:name "someCountryName"@en.
}
另一方面,这个查询不起作用:
SELECT * WHERE {
?c rdf:type dbo:Country;
foaf:name "someCountryName"@en;
geo:lat ?lat.
}
注意:查询是使用上面列出的相同前缀完成的。 我只需要获取纬度和纬度一个国家的长久。我也可以尝试 Freebase,但我真的需要让它在这里工作。第二个查询在 snorql 中有效,不明白为什么它在我的应用程序中不起作用? 非常感谢任何帮助!
I'm using ARC2 library for php to issue sparql queries, and i got stuck on this issue (I don't think it has something to do with the lib).
This query works just fine - in my app, and in dbpedia snorql:
PREFIX dbo:<http://dbpedia.org/ontology/>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX : <http://dbpedia.org/resource/>
PREFIX dbpedia2: <http://dbpedia.org/property/>
PREFIX dbpedia: <http://dbpedia.org/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX geo: <http://www.geonames.org/ontology#>
SELECT * WHERE {
?c rdf:type dbo:Country;
foaf:name "someCountryName"@en.
}
On the other hand, this query doesn't work:
SELECT * WHERE {
?c rdf:type dbo:Country;
foaf:name "someCountryName"@en;
geo:lat ?lat.
}
Note: the query is done using the same prefixes as listed above.
I just need to take lat & long of a country. I could also try Freebase, but i really need to make it work here. The 2nd query works in snorql, can't see why it doesn't also work in my app?
Any help is much appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
注意:此文本由 @IrinaM 提供,但作为修订版 因为八小时的限制。现在已经晚了很多,@IrinaM 发布作为答案的建议尚未得到执行。这是包含该文本的稍微编辑过的 CW 答案。
问题中的代码有几个错误。
第二个nd查询(没有“工作”的查询)将返回几个结果。如果我搜索带有
foaf:name "Romania"
的国家/地区,它将返回"共产主义罗马尼亚"
、"瓦拉几亚罗马尼亚"
、"罗马尼亚”
等。在这些结果中,只有一个包含geo:lat
和geo:long
。基本上,当所有结果都不满足所需属性时,将不会返回任何结果。
geo
使用了错误的本体;它应该是
。需要过滤掉其他奇怪的结果,以仅保留所需的唯一结果。在这种情况下,在
dbpedia-owl:dissolutionDate
不存在之后进行过滤是有效的。使用
FILTER (?name="someCountryName"^^xsd:string)
精确匹配 foaf:name 不起作用。下面是成功检索给定国家/地区的纬度和经度值的代码(请注意,在搜索正确的国家/地区时可能需要一些其他过滤器):
对于那些热衷于 ARC2 PHP 库的人,这是进行查询的方法(注意:don不要忘记包含 ARC2.php 文件):
Note: This text was provided by @IrinaM, but put into the question as a revision because of the eight hour limit. It's now much later and the suggestion that @IrinaM post as an answer hasn't been acted upon. Here's a slightly edited CW answer containing that text.
There are several mistakes in the code in the question.
The 2nd query (the one that didn't “work”) would return several results. If I searched countries with
foaf:name "Romania"
, it would return"Communist Romania"
,"Wallachian Romania"
,"Romania"
, etc. Out of these results, only one would havegeo:lat
andgeo:long
.Basically, when a required property isn't satisfied by all the results, then no results will be returned.
The wrong ontology is used for
geo
; it should be<http://www.w3.org/2003/01/geo/wgs84_pos#>
.The other odd results need to be filtered out, to only keep the desired unique results. In this case, filtering after the inexistence of
dbpedia-owl:dissolutionDate
works.Exact matches of foaf:name using
FILTER (?name="someCountryName"^^xsd:string)
do not work.Here's code that retrieves successfully the latitude and longitude values for a given country (beware, some other filters may be needed when searching for the right country):
For those passionate about ARC2 PHP lib, this is how to make the queries (note:don't forget to include the ARC2.php file):