简体   繁体   English

维基数据 SPARQL 查询。 并非结果中的所有属性

[英]Wikidata SPARQL Query. Not all properties in the result

Can anybody help me to understand why the ?sEnd attribute is empty for the last record here?任何人都可以帮助我理解为什么 ?sEnd 属性对于这里的最后一条记录是空的?

SELECT ?sLabel ?sStart ?sEnd
WHERE {
BIND(wd:Q32522 as ?p).
?s wdt:P26 ?p .
OPTIONAL { ?s p:P26 [pq:P580 ?sStart] }
OPTIONAL { ?s p:P26 [pq:P582 ?sEnd] }
SERVICE wikibase:label { bd:serviceParam wikibase:language 'en' }
}

Basically, what I want to retrieve is Jennifer Aniston's spouses with marriage start and end dates.基本上,我要检索的是詹妮弗安妮斯顿的配偶,以及婚姻开始和结束日期。

Thanks in advance!提前致谢!

The issue seems to be that you are querying for the marriage dates of Jennifer Aniston's spouses, as opposed to hers directly.问题似乎是您要查询 Jennifer Aniston 配偶的结婚日期,而不是直接查询她的结婚日期。

Your query returns some odd results, for two different reasons:您的查询返回一些奇怪的结果,原因有两个:

1.Brad Pitt was married a second time, to Angelina Jolie (2014-19). 1.布拉德皮特第二次与安吉丽娜朱莉结婚(2014-19)。 Your query is therefore returning those dates as well.因此,您的查询也会返回这些日期。

2.The data for Justin Theroux and Jennifer Aniston are inconsistent (this is a Wikidata issue). 2. Justin Theroux 和 Jennifer Aniston 的数据不一致(这是一个维基数据问题)。 In particular, as @UninformedUser pointed out, Justin's page has no end date for their marriage.特别是,正如@UninformedUser 指出的那样,贾斯汀的页面没有他们婚姻的结束日期。 Jennifer Aniston's data on her marriage with Justin is more specific than his data and has both start and end date.詹妮弗安妮斯顿关于她与贾斯汀婚姻的数据比他的数据更具体,并且有开始和结束日期。

Reasoning is something that can be used to deal with this sort of issues, and some triplestores have it.推理是可以用来处理这类问题的东西,一些三元组有它。

The query you need is this nonetheless:尽管如此,您需要的查询是:

SELECT ?spouseLabel ?sStart ?sEnd
WHERE {
BIND(wd:Q32522 as ?person).
?person p:P26 ?marriage .
?marriage pq:P580 ?sStart ;
         ps:P26 ?spouse .
OPTIONAL{?marriage pq:P582 ?sEnd}
                     
SERVICE wikibase:label { bd:serviceParam wikibase:language 'en' }
}

This gives the required result.这给出了所需的结果。 Notice that the namespace for the properties of the wedding changes depending on what the object is.请注意,婚礼属性的命名空间根据对象的不同而变化。 See here for more.请参阅此处了解更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM