User:Aude/wikidata-guide

Introduction edit

Wikidata is one of the newest sister projects of the Wikipedia.

  • launched in 2012
    • Now (as of January 2017) there are more than 24 million items
    • 130 million statements
  • provides centralized, multilingual structured data repository
  • linked data - connects to other resources about a topic, such as through site links to pages on Wikimedia projects or through identifiers for external databases and resources.
  • data is licensed under Creative Commons Zero (CC-0), essentially public domain.
  • powered by Wikibase, a set of MediaWiki extensions that allow storing structured data (json blobs) in place of wikitext.
  • Wikidata items are editable, with revision history and other standard features that MediaWiki provides.* Data is machine readable, thus more easily queryable and reusable in third-party applications.

Videos edit

https://www.youtube.com/watch?v=7xyPiYvy0GA (Introduction by Asaf Bartov at WikiConference India) https://www.youtube.com/watch?v=qGfSDna3cJM (Presentation by Lydia)

Anatomy of a Wikidata item edit

Item with a statement edit

 

Item with multiple statements (statement group) edit

 

See also edit

Wikidata in other languages edit

Labels, descriptions and aliases in other languages can be viewed and edited by clicking on "in more languages" / "All entered languages".

Interface language can be changed (currently only for logged-in users), using the language selector at the top of the page:

 

Properties edit

Property data types available edit

  • Commons media (image, flag image, video, …)
  • Globe coordinate (coordinate location, …)
  • Identifier (geonames id, VIAF identifier, ...)
  • Math (defining formula)
  • Monolingual text (motto text, official name, …)
  • Quantity - optionally, with units (area, population, …)
  • String (formatter URL, serials ordinal, …)
  • Time (date of birth, point in time, …)
  • URL (official website, …)
  • Wikibase item (instance of, head of government, …)
  • Wikibase property (inverse of, subproperty of, …)

Further information edit

Bots edit

Request a bot to help edit

Creating a bot edit

Data donations edit

Wikipedia integration edit

  • TODO

Videos edit

Wikidata Query Service edit

RDF edit

The query service uses RDF representation of Wikidata items.

RDF triples:

Subject : Predicate : Object
Q38 (Italy) : P36 (Capital) : Q220 (Rome)

using URIs (concept URIs):

http://www.wikidata.org/entity/Q38 : http://www.wikidata.org/prop/direct/P36 : http://www.wikidata.org/entity/Q220

Turtle edit

Flavor of RDF (Terse RDF Triple Language)

@prefix wd: http://www.wikidata.org/entity/ @prefix wdt: http://www.wikidata.org/prop/direct/

wd:Q38 : wdt:P36 : wd:Q220

SPARQL edit

SPARQL is a W3C standardized RDF query language.

Example:

Return all items with "instance of" (P31) = cat (Q146).

PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>

SELECT ?subject
WHERE {
  ?subject wdt:P31 wd:Q146
}

GUI edit

There is a graphical user interface on https://query.wikidata.org for exploring the query service and building / running queries.

Cats edit

 

 

Cats with images edit

 

 

 

United States Presidents queries edit

List of all U.S. Presidents, sorted by label edit

SELECT ?item ?itemLabel
WHERE
{
  ?item wdt:P39 wd:Q11696 .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
ORDER BY ?itemLabel

List of all U.S. Presidents, sorted by label, excluding fictional characters (only instance of = human) edit

SELECT ?item ?itemLabel
WHERE
{
  ?item wdt:P39 wd:Q11696 .
  ?item wdt:P31 wd:Q5 .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
ORDER BY ?itemLabel

Pets edit

SELECT ?petLabel ?ownerLabel {
  ?pet wdt:P31/wdt:P279* wd:Q622852 .
  ?pet wdt:P127 ?owner
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}

Presidential pets edit

SELECT DISTINCT ?pet ?petLabel ?ownerLabel {
  ?pet wdt:P31/wdt:P279* wd:Q622852 .
  ?pet wdt:P127 ?owner .
  ?owner wdt:P39 wd:Q11696 . 
  ?pet wdt:P18 ?image .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}

Presidential pets with images edit

SELECT ?petLabel ?ownerLabel ?image {
  ?pet wdt:P31/wdt:P279* wd:Q622852 .
  ?pet wdt:P127 ?owner .
  ?owner wdt:P39 wd:Q11696 . 
  ?pet wdt:P18 ?image .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}

Presidential pets, one image per pet edit

SELECT DISTINCT ?pet ?petLabel ?ownerLabel (SAMPLE(?image) as ?image) {
  ?pet wdt:P31/wdt:P279* wd:Q622852 .
  ?pet wdt:P127 ?owner .
  ?owner wdt:P39 wd:Q11696 . 
  ?pet wdt:P18 ?image .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
GROUP BY ?pet ?petLabel ?ownerLabel

Presidential pets, with image if one exists edit

SELECT DISTINCT ?pet ?petLabel ?ownerLabel (SAMPLE(?image) as ?image) {
  ?pet wdt:P31/wdt:P279* wd:Q622852 .
  ?pet wdt:P127 ?owner .
  ?owner wdt:P39 wd:Q11696 .
  OPTIONAL {
    ?pet wdt:P18 ?image .
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
GROUP BY ?pet ?petLabel ?ownerLabel

Species named after a U.S. President edit

SELECT ?taxon ?taxonLabel ?name WHERE {
  ?taxon wdt:P31 wd:Q16521;
         wdt:P138 ?namedAfter .
  ?namedAfter wdt:P39 wd:Q11696 .
  OPTIONAL { ?taxon wdt:P225 ?name. }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}

U.S. Presidents, with date and place of birth edit

SELECT ?item ?itemLabel ?dateOfBirth ?placeOfBirth
WHERE
{
  BIND(wd:Q11696 AS ?president)
  ?item wdt:P31 wd:Q5 .
  ?item wdt:P39 ?president .
  ?item wdt:P19 ?placeOfBirth .
  ?item wdt:P569 ?dateOfBirth .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
ORDER BY ?dateOfBirth

U.S. Presidents, date and cause of death edit

SELECT ?item ?itemLabel ?dateOfDeath ?causeOfDeathLabel
WHERE
{
  BIND(wd:Q11696 AS ?president)
  ?item wdt:P31 wd:Q5 .
  ?item wdt:P39 ?president .
  ?item wdt:P570 ?dateOfDeath .
  ?item wdt:P509 ?causeOfDeath .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
ORDER BY ?dateOfDeath

U.S. Presidents that died of stroke or heart attack edit

SELECT ?item ?itemLabel ?dateOfDeath ?causeOfDeathLabel
WHERE
{
  BIND(wd:Q11696 AS ?president)
  ?item wdt:P31 wd:Q5 .
  ?item wdt:P39 ?president .
  ?item wdt:P570 ?dateOfDeath .
  ?item wdt:P509 ?causeOfDeath .
  FILTER (?causeOfDeath = wd:Q12202 || ?causeOfDeath = wd:Q12152)
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
ORDER BY ?dateOfDeath

U.S. Presidents, cause of death, grouped by cause edit

SELECT ?causeOfDeathLabel (COUNT(?causeOfDeathLabel) as ?count)
WHERE
{
  BIND(wd:Q11696 AS ?president)
  ?item wdt:P31 wd:Q5 .
  ?item wdt:P39 ?president .
  ?item wdt:P509 ?causeOfDeath .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
GROUP BY ?causeOfDeathLabel ?count
ORDER BY DESC(?count)

U.S. Presidents, place of birth edit

SELECT ?placeOfBirthLabel ?itemLabel ?placeOfBirthCoord
WHERE
{
  BIND(wd:Q11696 AS ?president)
  ?item wdt:P31 wd:Q5 .
  ?item wdt:P39 ?president .
  ?item wdt:P19 ?placeOfBirth .
  ?placeOfBirth wdt:P625 ?placeOfBirthCoord .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
ORDER BY ?placeOfBirthLabel

U.S. Presidents who were born, died and/or lived in New York City edit

SELECT DISTINCT ?item ?itemLabel ?birthplaceLabel ?placeOfDeathLabel ?residenceLabel
WHERE {
  ?item wdt:P39 wd:Q11696.
  ?item wdt:P31 wd:Q5.
  { 
    ?item wdt:P19|wdt:P20|wdt:P551 wd:Q60.
  } UNION { 
    ?item wdt:P19|wdt:P20|wdt:P551 ?place . ?place wdt:P131* wd:Q60
  }
  OPTIONAL { ?item wdt:P19 ?birthplace. }
  OPTIONAL { ?item wdt:P20 ?placeOfDeath. }  
  OPTIONAL { ?item wdt:P551 ?residence. ?residence wdt:P131* wd:Q60 }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
GROUP BY ?item ?itemLabel ?birthplaceLabel ?placeOfDeathLabel ?residenceLabel
ORDER BY ?itemLabel

List of U.S. Presidents, sorted by label, excluding fictional characters (only instance of = human) (Alternative) edit

SELECT ?item ?itemLabel ?statement
WHERE
{
  BIND(wd:Q11696 AS ?president)
  ?item wdt:P31 wd:Q5 .
  ?item p:P39 ?statement .
  ?statement ps:P39 ?president .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
ORDER BY ?itemLabel

U.S. Presidents, each listed only once edit

SELECT ?item ?itemLabel
WHERE
{
  BIND(wd:Q11696 AS ?president)
  ?item wdt:P31 wd:Q5 .
  ?item p:P39 ?statement .
  ?statement ps:P39 ?president .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
GROUP BY ?item ?itemLabel
ORDER BY ?itemLabel

List of U.S. Presidents, sorted by label, with start date edit

SELECT ?item ?itemLabel ?start
WHERE
{
  BIND(wd:Q11696 AS ?president)
  ?item wdt:P31 wd:Q5 .
  ?item p:P39 ?statement .
  ?statement ps:P39 ?president .
  ?statement pq:P580 ?start
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
ORDER BY ?itemLabel

List of U.S. Presidents, sorted by label, with earliest start date edit

SELECT ?item ?itemLabel (MIN(?start) as ?start)
WHERE
{
  BIND(wd:Q11696 AS ?president)
  ?item wdt:P31 wd:Q5 .
  ?item p:P39 ?statement .
  ?statement ps:P39 ?president .
  ?statement pq:P580 ?start
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
GROUP BY ?item ?itemLabel
ORDER BY ?itemLabel

List of U.S. Presidents, sorted by start date edit

SELECT ?item ?itemLabel (MIN(?start) as ?start)
WHERE
{
  BIND(wd:Q11696 AS ?president)
  ?item wdt:P31 wd:Q5 .
  ?item p:P39 ?statement .
  ?statement ps:P39 ?president .
  ?statement pq:P580 ?start
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
GROUP BY ?item ?itemLabel
ORDER BY ?start

Number of children of each U.S. President edit

SELECT ?item ?itemLabel (COUNT(?child) as ?count)
WHERE
{
  ?item wdt:P31 wd:Q5 .
  ?item wdt:P39 wd:Q11696 .
  ?item wdt:P40 ?child .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
GROUP BY ?item ?itemLabel ?count
ORDER BY DESC(?count) ?itemLabel 

Count of children on Presidents' items vs. "number of children" (P1971) edit

SELECT ?item ?itemLabel ?numOfChildren (COUNT(?child) as ?count)
WHERE
{
  ?item wdt:P31 wd:Q5 .
  ?item wdt:P39 wd:Q11696 .
  ?item wdt:P1971 ?numOfChildren .
  ?item wdt:P40 ?child .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
GROUP BY ?item ?itemLabel ?count ?numOfChildren
ORDER BY DESC(?numOfChildren) ?itemLabel 

List of children of U.S. Presidents edit

SELECT ?item ?itemLabel ?childLabel (MIN(?start) as ?start)
WHERE
{
  BIND(wd:Q11696 AS ?president)
  ?item wdt:P31 wd:Q5 .
  ?item wdt:P40 ?child .
  ?item p:P39 ?statement .
  ?statement ps:P39 ?president .
  ?statement pq:P580 ?start .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
GROUP BY ?item ?itemLabel ?childLabel ?start
ORDER BY ?start

Children of U.S. Presidents, with child's date of birth edit

SELECT ?item ?itemLabel ?childLabel ?childDateOfBirth
WHERE
{
  BIND(wd:Q11696 AS ?president)
  ?item wdt:P31 wd:Q5 .
  ?item wdt:P40 ?child .
  ?item p:P39 ?statement .
  ?statement ps:P39 ?president .
  ?statement pq:P580 ?start .
  ?child wdt:P569 ?childDateOfBirth .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
GROUP BY ?item ?itemLabel ?childLabel ?childDateOfBirth
ORDER BY ?start

Children of U.S. Presidents, sorted by child's date of birth edit

SELECT ?childLabel ?itemLabel ?childDateOfBirth
WHERE
{
  BIND(wd:Q11696 AS ?president)
  ?item wdt:P31 wd:Q5 .
  ?item wdt:P40 ?child .
  ?item p:P39 ?statement .
  ?statement ps:P39 ?president .
  ?statement pq:P580 ?start .
  ?child wdt:P569 ?childDateOfBirth .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
GROUP BY ?itemLabel ?childLabel ?childDateOfBirth
ORDER BY ?childDateOfBirth

Daughters of U.S. Presidents, sorted by child's date of birth edit

SELECT ?childLabel ?itemLabel ?childDateOfBirth
WHERE
{
  BIND(wd:Q11696 AS ?president)
  ?item wdt:P31 wd:Q5 .
  ?item wdt:P40 ?child .
  ?item p:P39 ?statement .
  ?statement ps:P39 ?president .
  ?statement pq:P580 ?start .
  ?child wdt:P569 ?childDateOfBirth .
  ?child wdt:P21 wd:Q6581072 .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
GROUP BY ?itemLabel ?childLabel ?childDateOfBirth
ORDER BY ?childDateOfBirth

Children of U.S. Presidents, born in New York State edit

SELECT ?childLabel ?itemLabel ?childDateOfBirth
WHERE
{
  BIND(wd:Q11696 AS ?president)
  ?item wdt:P31 wd:Q5 .
  ?item wdt:P40 ?child .
  ?item p:P39 ?statement .
  ?statement ps:P39 ?president .
  ?statement pq:P580 ?start .
  ?child wdt:P569 ?childDateOfBirth .
  ?child wdt:P19 ?placeOfBirth .
  ?placeOfBirth wdt:P131/wdt:P279* wd:Q1384
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
GROUP BY ?itemLabel ?childLabel ?childDateOfBirth
ORDER BY ?childDateOfBirth

Children of U.S. Presidents with an article in German Wikipedia edit

SELECT ?childLabel ?itemLabel ?childDateOfBirth
WHERE
{
  BIND(wd:Q11696 AS ?president)
  ?item wdt:P39 wd:Q11696 .
  ?item wdt:P31 wd:Q5 .
  ?item wdt:P40 ?child .
  ?child wdt:P569 ?childDateOfBirth .
  ?sitelink schema:about ?child .
  FILTER EXISTS {
    ?article schema:about ?child .
    ?article schema:inLanguage "de" .
    ?article schema:isPartOf <https://de.wikipedia.org/>
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
GROUP BY ?itemLabel ?childLabel ?childDateOfBirth
ORDER BY ?childDateOfBirth

Children of U.S. Presidents without an article in German Wikipedia edit

SELECT ?childLabel ?itemLabel ?childDateOfBirth
WHERE
{
  BIND(wd:Q11696 AS ?president)
  ?item wdt:P39 wd:Q11696 .
  ?item wdt:P31 wd:Q5 .
  ?item wdt:P40 ?child .
  ?child wdt:P569 ?childDateOfBirth .
  ?sitelink schema:about ?child .
  FILTER NOT EXISTS {
    ?article schema:about ?child .
    ?article schema:inLanguage "de" .
    ?article schema:isPartOf <https://de.wikipedia.org/>
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
GROUP BY ?itemLabel ?childLabel ?childDateOfBirth
ORDER BY ?childDateOfBirth

Query tutorials and examples edit

Tutorials edit

Example queries edit

Request a query edit

Videos edit

Statistics edit

Communication edit