My question is how I can extract all properties and their respective labels that are also rendered on the webpage from wikidata preferably over SPARQL.
Take for example the Google entry on wikidata. For the property P414 (stock exchange) or P159 there are subproperties like P969 (located at street address). They actually show up once you query wbgetentities
as qualifieres. The problem with wbgetentities
is that the labels are missing. I get the desired output (e.g. wdt:P17 => country => United States of America
) with the following SPARQL query:
SELECT ?prop_id ?prop_label ?prop_val_label WHERE {
VALUES (?company) {
(wd:Q95)
}
?company ?prop_id ?company_item.
?wd wikibase:directClaim ?prop_id.
?wd rdfs:label ?prop_label.
OPTIONAL {
?company_item rdfs:label ?prop_val.
FILTER((LANG(?prop_val)) = "en")
}
BIND(COALESCE(?prop_val, ?companyItem) AS ?prop_val_label)
FILTER((LANG(?prop_label)) = "en")
}
But those "subproperties" are missing because they are not under direct claims. To extract a single statements qualifier I can do:
SELECT ?company ?hq ?country WHERE {
wd:Q95 p:P159 ?company.
OPTIONAL {
?company ps:P159 ?hq.
?company pq:P17 ?country.
}
}
But the question is if there is a way to combine everything to one query?
Useful links on the Wikidata data model:
Your query should be of this kind:
SELECT ?wdLabel ?ps_Label ?wdpqLabel ?pq_Label {
VALUES (?company) {(wd:Q95)}
?company ?p ?statement .
?statement ?ps ?ps_ .
?wd wikibase:claim ?p.
?wd wikibase:statementProperty ?ps.
OPTIONAL {
?statement ?pq ?pq_ .
?wdpq wikibase:qualifier ?pq .
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
} ORDER BY ?wd ?statement ?ps_
Try it!
Only qualifiers and their values are included in the result. Neither provenance references nor value annotations (e.g. time precision) are included. Please write a comment if you need to add them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With