简体   繁体   中英

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?

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.

Your query returns some odd results, for two different reasons:

1.Brad Pitt was married a second time, to Angelina Jolie (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). In particular, as @UninformedUser pointed out, Justin's page has no end date for their marriage. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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