User:Ijon/Queries

Queries tutorials edit

Asaf's Query examples edit

Breakdown of item types (instance of) for a given country (Israel, here) edit

The following query uses these:

  • Properties: country (P17)     , instance of (P31)     
    # breakdown of item types (instance of) for a given country (Israel, here)
    SELECT ?instanceLabel (COUNT(?item) as ?count) 
    WHERE { 
      ?item wdt:P17 wd:Q801 . 
      ?item wdt:P31 ?instance . 
      ?instance rdfs:label ?instanceLabel  
      FILTER(LANG(?instanceLabel) = "he")
    }
    GROUP BY ?instanceLabel
    ORDER BY DESC(?count)
    LIMIT 30
    

Albums known to be from a certain country (Israel, here) edit

The following query uses these:

Ukrainian politicians by birth oblast edit

The following query uses these:

People born somewhere in Zhytomyr oblast, with fallback languages marked edit

The following query uses these:

  • Properties: instance of (P31)     , place of birth (P19)     , located in the administrative territorial entity (P131)     
    # People born somewhere in Zhytomyr oblast, with fallback languages marked
    SELECT ?shtuka ?shtukaLabel (LANG(?shtukaLabel) as ?lang) 
    WHERE 
    {
      { ?shtuka wdt:P31 wd:Q5 . # all the humans
      ?shtuka wdt:P19 ?place . # who have a place of birth
      
      ?place wdt:P131 wd:Q40637 .} # which is in Zhytomyr oblast
      
      SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],ru,pl,be,cs,bg,sr,en". }
    }
    

Editors-in-chief and their employers edit

The following query uses these:

  • Properties: instance of (P31)     , position held (P39)     , employer (P108)     
    # Editors-in-chief and their employers
    SELECT ?editor ?editorLabel ?empLabel
    WHERE 
    {
      ?editor wdt:P31 wd:Q5.
      ?editor wdt:P39 wd:Q589298 . # holding editor-in-chief positions
      OPTIONAL {
                ?editor p:P39 ?prop .
               ?prop ps:P39 wd:Q589298 .
               ?prop pq:P108 ?emp . }
      SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
    }
    

Best-described items in Te Papa museum edit

The following query uses these:

  • Properties: collection (P195)     , location (P276)     , instance of (P31)     
    # best-described items in Te Papa museum
    SELECT DISTINCT ?q ?stcount WHERE {
      { ?q wdt:P195 wd:Q915603 .} # in Te Papa's collection 
      UNION 
      { ?q wdt:P276 wd:Q915603 .} # or "located in" Te Papa }
      # ?q wdt:P31 wd:Q3305213 . # limit to paintings (to not timeout)
      ?q wikibase:statements ?stcount .
    } GROUP BY ?q ?stcount
    ORDER BY DESC(?stcount)
    

Most-used properties to describe poems edit

The following query uses these:

  • Properties: instance of (P31)     
    SELECT ?prop ?propLabel ?count 
    WHERE 
    {
        {
            SELECT ?prop (COUNT(DISTINCT ?item) AS ?count) WHERE {
               
               hint:Query hint:optimizer "None" .
               ?item wdt:P31 wd:Q5185279 .
               ?item ?p ?id .
               ?prop wikibase:directClaim ?p .
            }  GROUP BY ?prop
        }
      
        SERVICE wikibase:label {
            bd:serviceParam wikibase:language "en" .
        }
    } ORDER BY DESC (?count)
    

Australian women covered in other Wikipedias but not in English edit

The following query uses these:

  • Properties: instance of (P31)     , sex or gender (P21)     , country of citizenship (P27)     
    # Australian women covered in other Wikipedias but not in English
    SELECT ?person ?personLabel ?personDescription (COUNT(DISTINCT ?sitelink) as ?linkcount) WHERE {
      ?person wdt:P31 wd:Q5 . # human
      ?person wdt:P21 wd:Q6581072 . # woman
      ?person wdt:P27 wd:Q408 . # Australian
      ?sitelink schema:about ?person . # get Wikimedia pages about the person
      FILTER NOT EXISTS {
        ?links schema:about ?person . # get Wikimedia pages about the person
        ?links schema:isPartOf <https://en.wikipedia.org/> . # but exclude English Wikipedia.
      }
      SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
    } GROUP BY ?person ?personLabel ?personDescription
    ORDER BY DESC(?linkcount) 
    LIMIT 20
    

People who won the Nobel Prize more than once edit

The following query uses these:

  • Properties: instance of (P31)     , award received (P166)     
    # People who won the Nobel Prize more than once
    SELECT ?winnerLabel ?wins
    {
      {
        SELECT ?winner (COUNT(?prize) AS ?wins)
        WHERE  
        { 
          ?winner wdt:P31 wd:Q5 . # human
          ?winner wdt:P166 ?prize . # who has won some prize
          ?prize wdt:P31 wd:Q7191 . # and where that prize is a kind of Nobel prize
        }
        GROUP BY ?winner
        ORDER BY DESC(?wins)
      }
      FILTER( ?wins > 1)
      SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
    }
    

Population timeline of a city edit

The following query uses these:

  • Properties: population (P1082)     , point in time (P585)     
    #defaultView:Timeline
    #title: Timeline of population size of Jerusalem, Israel
    SELECT ?pop ?time WHERE {
      wd:Q1218 p:P1082 [ ps:P1082 ?pop ; pq:P585 ?time ] .
    }
    

Model items by type edit

The following query uses these:

  • Properties: model item (P5869)     
    # model items
    SELECT ?conceptLabel ?item ?itemLabel 
    WHERE 
    {
      ?concept wdt:P5869 ?item.
      SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
    } ORDER BY ?conceptLabel
    

Most important missing item labels in a language edit

(The Twi language in this example)

The following query uses these:

  • Properties: instance of (P31)     , subclass of (P279)     
    # 100 most significant items missing labels in Twi 
    # (change the "tw" below to another language code to get the same query for another language)
    
    SELECT ?item ?sitelinks WHERE {
      ?item wikibase:sitelinks ?sitelinks. hint:Prior hint:rangeSafe true.
      FILTER(?sitelinks >= 100) # use at-least-100-sitelinks as an indicator of significance
    
      MINUS { ?item wdt:P31/wdt:P279* wd:Q58494026} # exclude Wikimedia internal items (categories, templates, etc.)
    
      MINUS { ?item rdfs:label ?label FILTER(LANG(?label) = "tw") } # <-- change language here
    
    } ORDER BY DESC(?sitelinks)
    LIMIT 100
    

Queries Asaf is too lazy to paste here edit

Other people's queries to stealadapt edit