SPARQL查询返回同一个人的多个生日 [英] SPARQL query returns multiple birth dates for same person

查看:105
本文介绍了SPARQL查询返回同一个人的多个生日的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过研究> https://www.joe0.com/2014/09/22/how-to-use-sparql-to-query-dbpedia-and-freebase/ 。我正在测试查询以返回约翰·列侬的出生日期,并且正在 http://dbpedia.org/sparql中运行查询。查询是:

I am learning SPARQL and dbpedia by working through the queries in https://www.joe0.com/2014/09/22/how-to-use-sparql-to-query-dbpedia-and-freebase/ . I am testing a query to return John Lennon's date of birth and I am running my queries in http://dbpedia.org/sparql . The query is:

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
SELECT DISTINCT ?x0 ?x1 WHERE {
?x0 rdf:type foaf:Person.
?x0 rdfs:label "John Lennon"@en.
?x0 dbpedia-owl:birthDate ?x1.
}

它返回包含相同日期(1940年10月9日)的两行。我的问题是:即使查询使用DISTINCT,为什么查询仍返回两行?在问这个问题之前,我检查了以下内容:

It returns two rows containing the same date (9 Oct 1940). My question is: why does the query return two rows even though it uses DISTINCT? Prior to asking this question I checked the following:

  • Why does my SPARQL query duplicate results?
  • Duplicate rows when making SPARQL queries

但是我不认为它们会解释重复的日期。

but I don't think they explain the duplicate dates.

编辑:我将结果转换为文本并粘贴到下面

Edit: I converted the results to text and pasted them below

-------------------------------------- -----------------------------------------------------
x0                                      x1
--------------------------------------- -----------------------------------------------------
http://dbpedia.org/resource/John_Lennon 1940-10-09 
http://dbpedia.org/resource/John_Lennon "1940-10-9"^^<http://www.w3.org/2001/XMLSchema#date>


推荐答案

如上所述,dbpedia实际上有两个日期-10-09(有效)和1940-10-9(无效)。答案是添加一个过滤器,该过滤器将日期转换为字符串,并且仅允许符合YYYY-MM-DD的日期。

As stated it seems dbpedia actually has two dates, 1940-10-09 (valid) and 1940-10-9 (invalid). The answer is to add a FILTER that converts the date to a string and only allows dates conforming to YYYY-MM-DD. Anyway it works!

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
SELECT DISTINCT ?x0 ?x1 STR(?x1) WHERE {
?x0 rdf:type foaf:Person.
?x0 rdfs:label "John Lennon"@en.
?x0 dbpedia-owl:birthDate ?x1.
FILTER (REGEX(STR(?x1),"[0-9]{4}-[0-9]{2}-[0-9]{2}")).
} 

这篇关于SPARQL查询返回同一个人的多个生日的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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