Wikidata:WikiProject Government/Queries

From Wikidata
Jump to navigation Jump to search

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)  View with Reasonator View with SQID, subclass of (P279)  View with Reasonator View with SQID, part of (P361)  View with Reasonator View with SQID, country (P17)  View with Reasonator View with SQID, applies to jurisdiction (P1001)  View with Reasonator View with SQID, dissolved, abolished or demolished date (P576)  View with Reasonator View with SQID, officeholder (P1308)  View with Reasonator View with SQID, start time (P580)  View with Reasonator View with SQID
    #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)  View with Reasonator View with SQID, start time (P580)  View with Reasonator View with SQID
    #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)  View with Reasonator View with SQID, start time (P580)  View with Reasonator View with SQID
    #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:

  • Properties: instance of (P31)  View with Reasonator View with SQID, subclass of (P279)  View with Reasonator View with SQID, country (P17)  View with Reasonator View with SQID, dissolved, abolished or demolished date (P576)  View with Reasonator View with SQID
    #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

[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)  View with Reasonator View with SQID, country (P17)  View with Reasonator View with SQID, dissolved, abolished or demolished date (P576)  View with Reasonator View with SQID, replaced by (P1366)  View with Reasonator View with SQID, head of government (P6)  View with Reasonator View with SQID, start time (P580)  View with Reasonator View with SQID
    #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)  View with Reasonator View with SQID, subclass of (P279)  View with Reasonator View with SQID
    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)  View with Reasonator View with SQID

#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]