Wikidata:WikiProject Biography/Query

From Wikidata
Jump to navigation Jump to search

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)  View with Reasonator View with SQID
    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)  View with Reasonator View with SQID, sex or gender (P21)  View with Reasonator View with SQID, sports discipline competed in (P2416)  View with Reasonator View with SQID, country of citizenship (P27)  View with Reasonator View with SQID
    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)  View with Reasonator View with SQID, medical condition (P1050)  View with Reasonator View with SQID, subclass of (P279)  View with Reasonator View with SQID
    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)  View with Reasonator View with SQID, sex or gender (P21)  View with Reasonator View with SQID, ethnic group (P172)  View with Reasonator View with SQID, country of citizenship (P27)  View with Reasonator View with SQID, religion or worldview (P140)  View with Reasonator View with SQID, sexual orientation (P91)  View with Reasonator View with SQID, developer (P178)  View with Reasonator View with SQID
    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)  View with Reasonator View with SQID, subclass of (P279)  View with Reasonator View with SQID
    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)  View with Reasonator View with SQID
    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)  View with Reasonator View with SQID, subclass of (P279)  View with Reasonator View with SQID
    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)  View with Reasonator View with SQID, subclass of (P279)  View with Reasonator View with SQID, sex or gender (P21)  View with Reasonator View with SQID, population (P1082)  View with Reasonator View with SQID, head of government (P6)  View with Reasonator View with SQID
    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