Wikidata:WikiProject Government/Queries
Please document interesting SPARQL queries here!
SPARQL query template :
{{SPARQL2|query= SELECT ... WHERE { ... SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } } }}
Ministries of Iceland
editThere should be twelve.
The following query uses these:
- Properties: instance of (P31) , dissolved, abolished or demolished date (P576)
#title: Icelandic ministries (should be 12) SELECT DISTINCT ?item ?itemLabel WHERE { ?item wdt:P31 wd:Q119788347 . MINUS { ?item wdt:P576 []} SERVICE wikibase:label { bd:serviceParam wikibase:language "en,is". } }
All current ministers of Iceland
editThere should be twelve.
The following query uses these:
- Items: public office (Q294414) , minister (Q83307) , Government of Iceland (Q12351757) , Iceland (Q189)
- Properties: instance of (P31) , subclass of (P279) , part of (P361) , country (P17) , applies to jurisdiction (P1001) , dissolved, abolished or demolished date (P576) , officeholder (P1308) , start time (P580)
#title: Current ministers of Iceland (should be 12) SELECT ?item ?itemLabel ?currentMinister ?currentMinisterLabel ?startTime { ?item wdt:P31 wd:Q294414 . ?item wdt:P279* wd:Q83307 . ?item wdt:P361 wd:Q12351757 . ?item wdt:P17/wdt:P1001* wd:Q189 . MINUS { ?item wdt:P576 [] } # Get ministers and their start times ?item p:P1308 ?statement . ?statement ps:P1308 ?currentMinister . ?statement pq:P580 ?startTime . ?currentMinister rdfs:label ?currentMinisterLabel . FILTER(LANG(?currentMinisterLabel) = "en") # Current ministers are the ones that have the most recent start time FILTER NOT EXISTS { ?item p:P1308 ?otherStatement . ?otherStatement ps:P1308 ?otherMinister . ?otherStatement pq:P580 ?otherStartTime . FILTER (?otherStartTime > ?startTime) } SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } }
All prime ministers of Iceland
editThere should be four
The following query uses these:
- Properties: officeholder (P1308) , start time (P580)
#title: All prime ministers of Iceland SELECT ?currentPrimeMinisters ?currentPrimeMinistersLabel ?startTime WHERE { # Prime minister of Iceland wd:Q19190022 p:P1308 ?statement . # Get all values of the officeholder statement ?statement ps:P1308 ?currentPrimeMinisters . # Get the start time (P580) of the officeholder statement ?statement pq:P580 ?startTime . # Get the label of the prime ministers ?currentPrimeMinisters rdfs:label ?currentPrimeMinistersLabel . FILTER(LANG(?currentPrimeMinistersLabel) = "en") }
The current prime minister of Iceland
editThere should be one.
The following query uses these:
- Properties: officeholder (P1308) , start time (P580)
#title: The current prime minister of Iceland (should be 1) SELECT ?currentPrimeMinisters ?currentPrimeMinistersLabel ?startTime WHERE { # Prime minister of Iceland wd:Q19190022 p:P1308 ?statement . # Get all values of the officeholder statement ?statement ps:P1308 ?currentPrimeMinisters . # Get the start time (P580) of the officeholder statement ?statement pq:P580 ?startTime . # Get the label of the prime ministers ?currentPrimeMinisters rdfs:label ?currentPrimeMinistersLabel . FILTER(LANG(?currentPrimeMinistersLabel) = "en") } # Order start time and get 1 value (which is the most recent start date) ORDER BY DESC(?startTime) LIMIT 1
All courts of Iceland
editThere should be ten.
The following query uses these:
- Items: supreme court (Q190752) , appellate court (Q4959031) , district court (Q75029) , Iceland (Q189)
- Properties: instance of (P31) , subclass of (P279) , country (P17) , dissolved, abolished or demolished date (P576)
#title: Courts of Iceland (should be 10) SELECT DISTINCT ?item ?itemLabel WHERE { {?item wdt:P31/wdt:P279* wd:Q190752 .} union {?item wdt:P31/wdt:P279* wd:Q4959031 .} union {?item wdt:P31/wdt:P279* wd:Q75029 .} ?item wdt:P17 wd:Q189 . MINUS { ?item wdt:P576 []} SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } }
Municipalities of Iceland
editThere should be 64
The following query uses these:
- Properties: instance of (P31) , country (P17) , dissolved, abolished or demolished date (P576) , replaced by (P1366)
#title: Municipalities of Iceland (should be 64) SELECT DISTINCT ?item ?itemLabel WHERE { ?item wdt:P31 wd:Q955655 . ?item wdt:P17 wd:Q189 . MINUS { ?item wdt:P576 []} MINUS { ?item wdt:P1366 []} SERVICE wikibase:label { bd:serviceParam wikibase:language "en,is". } }
All current majors of municipalities of Iceland
editThere should be 64
The following query uses these:
- Properties: instance of (P31) , country (P17) , dissolved, abolished or demolished date (P576) , replaced by (P1366) , head of government (P6) , start time (P580)
#title: Current majors of municipalities of Iceland (should be 64) SELECT ?municipality ?municipalityLabel ?currentMayor ?currentMayorLabel ?startDate WHERE { # Find all municipalities in Iceland ?municipality wdt:P31 wd:Q955655 . ?municipality wdt:P17 wd:Q189 . # Exclude municipalities with dissolved date (P576) and qualifiers (P1366) MINUS { ?municipality wdt:P576 [] } MINUS { ?municipality wdt:P1366 [] } # Get the head of government (mayor) statement and its value ?municipality p:P6 ?statement . ?statement ps:P6 ?currentMayor . # Get the start date (P580) of the mayor's term ?statement pq:P580 ?startDate . # Get the label of the current mayor ?currentMayor rdfs:label ?currentMayorLabel . FILTER(LANG(?currentMayorLabel) = "en") # Get the label of the municipality ?municipality rdfs:label ?municipalityLabel . FILTER(LANG(?municipalityLabel) = "en") # Filter out mayors that do not have the most recent start time FILTER NOT EXISTS { ?municipality p:P6 ?otherStatement . ?otherStatement ps:P6 ?otherMayor . ?otherStatement pq:P580 ?otherStartDate . FILTER (?otherStartDate > ?startDate) } }
Regional constituencies of Iceland
editThere should be six.
The following query uses these:
- Properties: instance of (P31) , country (P17) , dissolved, abolished or demolished date (P576)
#title: Constituencies of Iceland (should be 6) SELECT DISTINCT ?item ?itemLabel WHERE { ?item wdt:P31 wd:Q1515437 . ?item wdt:P17 wd:Q189 . MINUS { ?item wdt:P576 []} SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } }
Regions of Iceland
editThere should be eight.
The following query uses these:
- Properties: instance of (P31) , country (P17) , dissolved, abolished or demolished date (P576)
#title: Regions of Iceland (should be 8) SELECT DISTINCT ?item ?itemLabel WHERE { ?item wdt:P31 wd:Q842100 . ?item wdt:P17 wd:Q189 . MINUS { ?item wdt:P576 []} SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } }
Municipalities of Greenland
editThere should be five.
The following query uses these:
- Properties: instance of (P31) , subclass of (P279)
SELECT ?entity ?entityLabel WHERE { ?entity wdt:P31/wdt:P279* wd:Q16511251 ; # Instance of or subclass Municipality of Greenland SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } } ORDER BY ?entityLabel
Make a map of the municipalities of Greenland
editThe municipalities of Greenland have been moved from municipality of Greenland (Q16511251) to municipality of Greenland (Q16423979)!
The following query uses these:
- Properties: instance of (P31) , subclass of (P279) , geoshape (P3896)
Features: map (Q24515275)
#defaultView:Map
SELECT ?entity ?entityLabel ?geoshape
WHERE {
?entity wdt:P31/wdt:P279* wd:Q16423979 . # Instance of or subclass Municipality of Greenland
?entity wdt:P3896 ?geoshape . # Pull the geoshapes
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
ORDER BY ?entityLabel
→ This is what it is supposed to look like [1]