Wikidata:WikiProject Government/Queries

Home

 

Items & Properties

 

Reports

 

Queries

 

Discussions

 


Please document interesting SPARQL queries here!

SPARQL query template :

{{SPARQL2|query=
SELECT ...
WHERE {
  ...
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
  }
}}

Ministries of Iceland

edit

There should be twelve.

The following query uses these:

All current ministers of Iceland

edit

There should be twelve.

The following query uses these:

  • 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

edit

There 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

edit

There 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

edit

There should be ten.

The following query uses these:

Municipalities of Iceland

edit

There should be 64

The following query uses these:

All current majors of municipalities of Iceland

edit

There 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

edit

There should be six.

The following query uses these:

Regions of Iceland

edit

There should be eight.

The following query uses these:

Municipalities of Greenland

edit

There 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

edit

The municipalities of Greenland have been moved from municipality of Greenland (Q16511251) to municipality of Greenland (Q16423979)!

The following query uses these:

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]