Wikidata:WikiProject Biography/Query

Home

 

Model

 

Query

 

Curate

 

About

 

Discuss

 

These model queries give example interesting datasets from Wikidata.

General interest edit

Olympians edit

The following query uses these:

  • Properties: Olympic.org athlete ID (archived) (P3171)     
    SELECT
      ?person ?personLabel ?sexgenderLabel
    WHERE
    {
      ?person wdt:P3171 ?value .
      SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
    }
    LIMIT 30000
    

Olympians complete edit

The following query uses these:

  • Properties: Olympic.org athlete ID (archived) (P3171)     , sex or gender (P21)     , sports discipline competed in (P2416)     , country of citizenship (P27)     
    SELECT DISTINCT
    ?person ?personLabel ?sexgenderLabel ?sportLabel ?citizenshipLabel
    WITH
    { SELECT DISTINCT ?person 
        WHERE { ?person wdt:P3171 ?value . 
                ?person wikibase:statements ?statements .
                FILTER (?statements > 50) . }
    } as %athletes
    WITH
    { SELECT DISTINCT ?person ?sexgender (GROUP_CONCAT(DISTINCT ?sportLabel_;separator="; ") as ?sportLabel) (GROUP_CONCAT(DISTINCT ?citizenshipLabel_;separator="; ") as ?citizenshipLabel)
             WHERE { INCLUDE %athletes 
                     { ?person wdt:P21 ?sexgender . }
                     { ?person wdt:P2416 ?sport . ?sport rdfs:label ?sportLabel_ . filter(lang(?sportLabel_)="en") }
                     { ?person wdt:P27 ?citizenship . ?citizenship rdfs:label ?citizenshipLabel_ . filter(lang(?citizenshipLabel_)="en") }
    } GROUP BY ?person ?sexgender } as %athletes2
    WHERE
     { INCLUDE %athletes2
       SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
    }
    

People With Sexually-Transmitted Infections edit

The following query uses these:

  • Properties: instance of (P31)     , medical condition (P1050)     , subclass of (P279)     
    SELECT ?person ?personLabel (GROUP_CONCAT(DISTINCT ?conditionLabel;SEPARATOR=', ') AS ?conditions) 
    WHERE
    {
      ?person wdt:P31 wd:Q5 .
      ?person wdt:P1050 ?condition .
      ?condition wdt:P279 wd:Q12198 .
      ?condition rdfs:label ?conditionLabel . FILTER(LANG(?conditionLabel)='en')
      SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
    }
    GROUP BY ?person ?personLabel
    

University of Virginia Employees edit

The following query uses these:

  • Properties: employer (P108)     , sex or gender (P21)     , ethnic group (P172)     , country of citizenship (P27)     , religion or worldview (P140)     , sexual orientation (P91)     , developer (P178)     
    SELECT
      ?person ?personLabel ?sexorgender (GROUP_CONCAT(DISTINCT ?ethnicityLabel;SEPARATOR=', ') AS ?ethnicity) 
      (GROUP_CONCAT(DISTINCT ?citizenshipLabel;SEPARATOR=', ') AS ?citizenship) ?religion 
      ?sexuality ?developed
    WHERE
    {
      ?person wdt:P108 wd:Q213439 .
      ?person rdfs:label ?personLabel . FILTER(LANG(?personLabel)='en')
      OPTIONAL { ?person wdt:P21 ?value .
               ?value rdfs:label ?sexorgender . FILTER(LANG(?sexorgender)='en') }
      OPTIONAL { ?person wdt:P172 ?ethnicity .
               ?ethnicity rdfs:label ?ethnicityLabel . FILTER(LANG(?ethnicityLabel)='en') }
      OPTIONAL { ?person wdt:P27 ?citizenship .
               ?citizenship rdfs:label ?citizenshipLabel . FILTER(LANG(?citizenshipLabel)='en') }
      OPTIONAL { ?person wdt:P140 ?value2 .
               ?value2 rdfs:label ?religion . FILTER(LANG(?religion)='en') }
      OPTIONAL { ?person wdt:P91 ?value3 .
               ?value3 rdfs:label ?sexuality . FILTER(LANG(?sexuality)='en') }
      OPTIONAL { ?person wdt:P178+ ?value4 .
               ?value4 rdfs:label ?developed . FILTER(LANG(?developed)='en') }
    }
    GROUP BY ?person ?personLabel ?sexorgender ?religion ?sexuality ?developed
    

Scope of Wikidata edit

Get 20,000 people, count and list properties edit

The following query uses these:

  • Properties: instance of (P31)     , subclass of (P279)     
    SELECT DISTINCT ?property ?propertyLabel ?count
    WITH {
      SELECT DISTINCT ?item WHERE {
        ?item wdt:P31*/wdt:P279* wd:Q5 .
      }
      LIMIT 20000
      } AS %items 
    WITH {
      SELECT DISTINCT ?property (COUNT(*) AS ?count) WHERE {
      INCLUDE %items.
        ?item ?p [ ] .
        ?property a wikibase:Property;
                    wikibase:claim ?p.
      }
      GROUP BY ?property 
      LIMIT 100
      } AS %results 
    WHERE {
      INCLUDE %results.
      SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
    }
    ORDER BY DESC(?count)
    LIMIT 100
    

Use random sampling process, get 20,000 people, count and list properties edit

The following query uses these:

  • Properties: instance of (P31)     
    SELECT DISTINCT ?property ?propertyLabel ?count
    WITH {
      SELECT DISTINCT ?item WHERE {
        SERVICE bd:sample { ?item wdt:P31 wd:Q5 . bd:serviceParam bd:sample.limit 200000 }       
      }
    } AS %items 
    WITH {
      SELECT DISTINCT ?property (COUNT(*) AS ?count) WHERE {
      INCLUDE %items.
        ?item ?p [ ] .
        ?property a wikibase:Property;
                    wikibase:claim ?p.
      }
      GROUP BY ?property 
      LIMIT 100
      } AS %results 
    WHERE {
      INCLUDE %results.
      SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
    }
    ORDER BY DESC(?count)
    LIMIT 100
    

Most common properties applied to people edit

The following query uses these:

  • Properties: instance of (P31)     , subclass of (P279)     
    SELECT DISTINCT ?property ?propertyLabel ?count
    WITH {
      SELECT DISTINCT ?item WHERE {
        ?item wdt:P31*/wdt:P279* wd:Q5 .
      }
      LIMIT 200
      } AS %items 
    WITH {
      SELECT DISTINCT ?property (COUNT(*) AS ?count) WHERE {
      INCLUDE %items.
        ?item ?p [ ] .
        ?property a wikibase:Property;
                    wikibase:claim ?p.
      }
      GROUP BY ?property 
      LIMIT 200
      } AS %results 
    WHERE {
      INCLUDE %results.
      SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
    }
    ORDER BY DESC(?count)
    LIMIT 200
    

Largest cities with female mayor edit

The following query uses these:

  • Properties: instance of (P31)     , subclass of (P279)     , sex or gender (P21)     , population (P1082)     , head of government (P6)     
    PREFIX q: <http://www.wikidata.org/prop/qualifier/>
    PREFIX v: <http://www.wikidata.org/prop/statement/>
    
    SELECT DISTINCT  ?cityLabel ?population (CONCAT("Mayor of ",?cityLabel," : ",?mayorLabel) as ?description)  ?mayorLabel WHERE {
      ?city wdt:P31/wdt:P279* wd:Q515 .
      ?city p:P6 ?statement .
      ?statement v:P6 ?mayor .
      ?mayor wdt:P21 wd:Q6581072 .
      FILTER NOT EXISTS { ?statement q:P582 ?x }
    
      ?city wdt:P1082 ?population .
      SERVICE wikibase:label {
        bd:serviceParam wikibase:language "en" .
      }
     } ORDER BY DESC(?population) LIMIT 15