Omri Myers
Omri Myers

Reputation: 51

Querying wikidata for "property constraint"

TL;DR
How to query (sparql) about properties of a property?

Or..
So as part of my project I need to find the properties in wikidata that have any time constraint, to be specific both "start time" and "end time". I tried this query:

SELECT DISTINCT ?prop WHERE {
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  ?person wdt:P31 wd:Q5.
  ?person ?prop ?statement.
  ?statement pq:P580 ?starttime.
  ?statement pq:P582 ?endtime.
}
LIMIT 200

**yeah the properties should be related to humans Anyway, I do get some good results like:
http://www.wikidata.org/prop/P26
http://www.wikidata.org/prop/P39
But I also get some other properties that definitely wrong.

so, basically what i'm trying to do is to get a list of properties that has the property constraint (P2302) of- allowed qualifiers constraint (Q21510851) with Start time (P580) and End Time (P582) is that even possible: I tried some queries like:

SELECT DISTINCT ?property ?propertyLabel ?propertyDescription ?subpTypeOf ?subpTypeOfLabel 
WHERE
{
    ?property rdf:type wikibase:Property .

    ?property wdt:P2302  ?subpTypeOf.
    SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }   
}

but does not get the results I wanted. is it even possible to query this kind of stuff?

Thanks

Upvotes: 2

Views: 568

Answers (1)

Stanislav Kralin
Stanislav Kralin

Reputation: 11469

Qualifiers are used on property pages too. Your second query should be:

SELECT DISTINCT ?prop ?propLabel {
  ?prop p:P2302 [ ps:P2302 wd:Q21510851 ; pq:P2306 wd:P580, wd:P582 ] ;
        p:P2302 [ ps:P2302 wd:Q21503250 ; pq:P2308 wd:Q5 ; pq:P2309 wd:Q21503252 ] .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }   
} ORDER BY ASC(xsd:integer(strafter(str(?prop), concat(str(wd:), "P"))))

Try it!

Your first query is correct, but note that this is an 'as-is' query. For example, wd:P410 does not have respective constraints, but look at wd:Q83855.

Upvotes: 1

Related Questions