Nicolas Raoul
Nicolas Raoul

Reputation: 60193

SPARQL to encompass all sub-properties of a property

I want all Wikidata items that have ended, so I wrote this:

?item wdt:P582 ?endtime.

Problem: it does not include items that have been "abolished".
abolished is a subproperty of end time.

QUESTION: How to encompass all subproperties?


Current query that does not include subproperties:

SELECT
    ?item ?endtime
WHERE {
    ?item p:P31/ps:P31/wdt:P279* wd:Q3917681. # Embassies...
    ?item wdt:P582 ?endtime. # ... that have ended
}

I could do a UNION with all known sub-properies, but new sub-properties may appear in the future.

Upvotes: 3

Views: 983

Answers (2)

phil294
phil294

Reputation: 10822

Like Stanislav wrote in his comment, you have to get the prefixes right and also include directClaim:

?p_ wdt:P1647* wd:P582 .
?p_ wikibase:directClaim ?p .
?item ?p ?endtime .

I have found this to return duplicate rows per item though (due to the *) which I couldn't get rid off, even with proper GROUP BY logic. I solved this by doing what the question suggested, UNION with all known sub-properies

Upvotes: 0

Joshua Taylor
Joshua Taylor

Reputation: 85813

If Wikidata includes subproperty relationships, you just need:

?p rdfs:subPropertyOf* wdt:P582 .
?item ?p ?endtime.

Upvotes: 2

Related Questions