WikidataData

and ExternalIdentifier

and a little bit of SPARQL

Toni Schindler
2019-10-31

What is Wikidata?

Wiki for Data

Item about Isaac Newton: http://www.wikidata.org/entity/Q935

Statements:

Used by Wikipedia, Commons, ....

Wikipedia Infoboxes, any language. French:

Wikimedia Commons, “depicts”:
      ->    
credit: MadMona on commons, license CC BY-SA 4.0.

Query interface

Coal-fired power stations in Germany:
      ->  
Link to query. Map data © OpenStreetMap contributors.

Wikidata contents

Items, properties, lexemes, ...

Items

Q1: Universe
Q2: Earth
...
Q5: human
...
Q937: Albert Einstein
...
Q11173: chemical compound
...
Q11573: metre
...
Q36253: length
...
Q60235: caffeine
Q60236: Marie-Louise von Franz
...
Q107715: physical quantity
...
Q550147: snowflake
...
Q13359969: Die Feuerzangenbowle
...
Q22683173: GW150914
...
Q55865798: Die Grundlage der allgemeinen Relativitätstheorie
....
-----------------------------------------------------------------------
65 254 038 items

Properties

P18: image
...
P31: instance of
...
P279: subclass of
...
P361: part of
...
P569: date of birth
P570: date of death
P571: inception
...
P957: ISBN-10
...
P1082: population
...
P1549: demonym
...
P2067: mass
...
P4839: Wolfram Language entity code
...
-----------------------------------------------------------------------
> 6000 properties

Property types

Needs["GraphStore`"];
Grid[
SPARQLExecute["https://query.wikidata.org/sparql","
select ?type (count(*) as ?count) where {
  ?prop a wikibase:Property .
  ?prop wikibase:propertyType ?type .
}
group by ?type
order by desc(?count)
"]//Map[{Last[StringSplit[First[#type],"#"]],#count}&],
Alignment->Left
]//TraditionalForm

WikidataData quick start

WikidataSearch["newton"]

WikidataSearch["Property"->"birth date"]

WikidataData[(ExternalIdentifier[ExternalIdentifier["WikidataID","Q935",\[LeftAssociation]"Label"->"Isaac Newton","Description"->"British physicist and mathematician and founder of modern classical physics"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["Isaac Newton", http://www.wikidata.org/entity/Q935]), "Wikidata ID"]),(ExternalIdentifier[ExternalIdentifier["WikidataID","P569",\[LeftAssociation]"Label"->"date of birth","Description"->"date on which the subject was born"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["date of birth", http://www.wikidata.org/entity/P569]), "Wikidata ID"])]

SPARQL: A refresher

endpoint="https://query.wikidata.org/sparql";

query="select * where {
  ?item wdt:P31 wd:Q6558431 . # instance of -> coal-fired power station
  ?item wdt:P17 wd:Q183 . # country -> Germay
  ?item wdt:P625 ?pos .
  ?item rdfs:label ?itemLabel .
    filter (lang(?itemLabel) = \"de\")
}";

Needs["GraphStore`"]

data=SPARQLExecute[endpoint,query];

First[data]

GeoListPlot[Labeled[First[#pos],First[#itemLabel]]&/@data]

Quantity

WikidataData[
{(ExternalIdentifier[ExternalIdentifier["WikidataID","Q243",\[LeftAssociation]"Label"->"Eiffel Tower","Description"->"tower located on the Champ de Mars in Paris, France"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["Eiffel Tower", http://www.wikidata.org/entity/Q243]), "Wikidata ID"]),(ExternalIdentifier[ExternalIdentifier["WikidataID","Q2294",\[LeftAssociation]"Label"->"proton","Description"->"nucleon (constituent of the nucleus of the atom) that has positive electric charge; symbol p"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["proton", http://www.wikidata.org/entity/Q2294]), "Wikidata ID"]),(ExternalIdentifier[ExternalIdentifier["WikidataID","Q16389425",\[LeftAssociation]"Label"->"Kepler-186","Description"->"star in the constellation Cygnus"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["Kepler-186", http://www.wikidata.org/entity/Q16389425]), "Wikidata ID"])},
(ExternalIdentifier[ExternalIdentifier["WikidataID","P2067",\[LeftAssociation]"Label"->"mass","Description"->"mass (in colloquial usage also known as weight) of the item"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["mass", http://www.wikidata.org/entity/P2067]), "Wikidata ID"]),
"Association"
]//Map[Mean]

Quantity objects, comparable:

ListLogPlot[%,AxesLabel->Automatic]

Remember: quantity ≃ number + unit

Statement

The “preferred” value:

WikidataData[(ExternalIdentifier[ExternalIdentifier["WikidataID","Q16389425",\[LeftAssociation]"Label"->"Kepler-186","Description"->"star in the constellation Cygnus"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["Kepler-186", http://www.wikidata.org/entity/Q16389425]), "Wikidata ID"]),(ExternalIdentifier[ExternalIdentifier["WikidataID","P1215",\[LeftAssociation]"Label"->"apparent magnitude","Description"->"apparent magnitude of an astronomic object"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["apparent magnitude", http://www.wikidata.org/entity/P1215]), "Wikidata ID"])]

Include qualifiers and sources:

WikidataData[(ExternalIdentifier[ExternalIdentifier["WikidataID","Q16389425",\[LeftAssociation]"Label"->"Kepler-186","Description"->"star in the constellation Cygnus"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["Kepler-186", http://www.wikidata.org/entity/Q16389425]), "Wikidata ID"]),(ExternalIdentifier[ExternalIdentifier["WikidataID","P1215",\[LeftAssociation]"Label"->"apparent magnitude","Description"->"apparent magnitude of an astronomic object"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["apparent magnitude", http://www.wikidata.org/entity/P1215]), "Wikidata ID"]),"StatementFormat"->"Association"]

All non-deprecated statements for this property:

WikidataData[(ExternalIdentifier[ExternalIdentifier["WikidataID","Q16389425",\[LeftAssociation]"Label"->"Kepler-186","Description"->"star in the constellation Cygnus"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["Kepler-186", http://www.wikidata.org/entity/Q16389425]), "Wikidata ID"]),(ExternalIdentifier[ExternalIdentifier["WikidataID","P1215",\[LeftAssociation]"Label"->"apparent magnitude","Description"->"apparent magnitude of an astronomic object"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["apparent magnitude", http://www.wikidata.org/entity/P1215]), "Wikidata ID"]),"StatementFormat"->"Dataset","StatementRank"->"NonDeprecated"]//Dataset

Wikidata data model: single statement

Graph[
{
Labeled["Isaac Newton"->"statement node","claim\n(position held)"],
Labeled["statement node"->"president of the Royal Society","simple value\n(position held)"],
Labeled["statement node"->"reference node","reference\n(position held)"],
Labeled["reference node"->"some great book","reference value\n(stated in)"],
Labeled["statement node"->1703,"qualifier simple value\n(start time)"],
Labeled["statement node"->1727,"qualifier simple value\n(end time)"]
},
VertexLabels->"Name",
VertexLabelStyle->Bold,
EdgeLabelStyle->Directive[Background->White],
GraphLayout->{"LayeredEmbedding","RootVertex"->"Isaac Newton","LeafDistance"->2}
]

SPARQL

SPARQLExecute[endpoint,"select * where {
  wd:Q935 p:P39 [               # Isaac Newton -> position held statement node
    ps:P39 ?position ;
    pq:P580 ?startTime ;
    pq:P582 ?endTime ;          # no references to keep this example simple
  ] .
  ?position rdfs:label ?positionLabel .
    filter (lang(?positionLabel) = \"en\")
}"]//Dataset

WikidataData

WikidataData[(ExternalIdentifier[ExternalIdentifier["WikidataID","Q935",\[LeftAssociation]"Label"->"Isaac Newton","Description"->"British physicist and mathematician and founder of modern classical physics"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["Isaac Newton", http://www.wikidata.org/entity/Q935]), "Wikidata ID"]),(ExternalIdentifier[ExternalIdentifier["WikidataID","P39",\[LeftAssociation]"Label"->"position held","Description"->"subject currently or formerly holds the object position or public office"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["position held", http://www.wikidata.org/entity/P39]), "Wikidata ID"]),"StatementFormat"->All]//Dataset

Time series

Life expectancy in different countries:

lifeExpData=WikidataData[
{(ExternalIdentifier[ExternalIdentifier["WikidataID","Q28",\[LeftAssociation]"Label"->"Hungary","Description"->"republic in Central Europe"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["Hungary", http://www.wikidata.org/entity/Q28]), "Wikidata ID"]),(ExternalIdentifier[ExternalIdentifier["WikidataID","Q29",\[LeftAssociation]"Label"->"Spain","Description"->"constitutional monarchy in Southwest Europe"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["Spain", http://www.wikidata.org/entity/Q29]), "Wikidata ID"]),(ExternalIdentifier[ExternalIdentifier["WikidataID","Q183",\[LeftAssociation]"Label"->"Germany","Description"->"federal parliamentary republic in central-western Europe"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["Germany", http://www.wikidata.org/entity/Q183]), "Wikidata ID"]),(ExternalIdentifier[ExternalIdentifier["WikidataID","Q41",\[LeftAssociation]"Label"->"Greece","Description"->"republic in Southeast Europe"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["Greece", http://www.wikidata.org/entity/Q41]), "Wikidata ID"])},
(ExternalIdentifier[ExternalIdentifier["WikidataID","P2250",\[LeftAssociation]"Label"->"life expectancy","Description"->"life expectancy for this group or species"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["life expectancy", http://www.wikidata.org/entity/P2250]), "Wikidata ID"]),
"Association",
"StatementRank"->"NonDeprecated",
"StatementFormat"->All
];

Extract date-value pairs:

TimeSeries[Cases[#,KeyValuePattern[{(ExternalIdentifier[ExternalIdentifier["WikidataID","P585",\[LeftAssociation]"Label"->"point in time","Description"->"time and date something took place, existed or a statement was true"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["point in time", http://www.wikidata.org/entity/P585]), "Wikidata ID"])->{date_},"Value"->value_}]:>{date,value}]]&/@lifeExpData

DateListPlot[%]

By the way - what are those white boxes?

Identifier:

ExternalIdentifier["WikidataID","Q1"]

Include a label:

ExternalIdentifier["WikidataID","Q1",<|"Label"->"Universe"|>]

Other identifier types:

ExternalIdentifier["ISBN10","0-7167-0344-0"]

ExternalIdentifier["MusicBrainzArtistID","a7389752-9e5d-406d-9a02-9141600e4315"]

ExternalIdentifier["CASRegistryNumber","7439-89-6"]

Identifiers

Wikidata ID to other ID

WikidataData[(ExternalIdentifier[ExternalIdentifier["WikidataID","Q5597987",\[LeftAssociation]"Label"->"Gravitation","Description"->"book by Charles W. Misner"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["Gravitation", http://www.wikidata.org/entity/Q5597987]), "Wikidata ID"]),{"ISBN10","OCLCControlNumber",(ExternalIdentifier[ExternalIdentifier["WikidataID","P675",\[LeftAssociation]"Label"->"Google Books ID","Description"->"identifier for a book that Google has scanned"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["Google Books ID", http://www.wikidata.org/entity/P675]), "Wikidata ID"])},"Dataset"]

Other ID to Wikidata ID

WikidataData[(ExternalIdentifier[ExternalIdentifier["DOI","10.1002/ANDP.19163540702"], (ExternalIdentifierLabelHyperlink["10.1002/ANDP.19163540702", https://doi.org/10.1002/ANDP.19163540702]), "DOI"]),{"WikidataID",(ExternalIdentifier[ExternalIdentifier["WikidataID","P1476",\[LeftAssociation]"Label"->"title","Description"->"published title of a work, such as a newspaper article, a literary work, a website, or a performance work"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["title", http://www.wikidata.org/entity/P1476]), "Wikidata ID"]),(ExternalIdentifier[ExternalIdentifier["WikidataID","P50",\[LeftAssociation]"Label"->"author","Description"->"main creator(s) of a written work (use on works, not humans); use P2093 when Wikidata item is unknown or does not exist"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["author", http://www.wikidata.org/entity/P50]), "Wikidata ID"]),(ExternalIdentifier[ExternalIdentifier["WikidataID","P577",\[LeftAssociation]"Label"->"publication date","Description"->"date or point in time when a work was first published or released"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["publication date", http://www.wikidata.org/entity/P577]), "Wikidata ID"])},"Dataset"]

Entities

Entity to Wikidata

WikidataData[(Entity["Amazon", Entity["River","Amazon::n9532"], "Entity[\"River\", \"Amazon::n9532\"]", "river"]),"Dataset"]

Wikidata to Entity

WikidataData[(ExternalIdentifier[ExternalIdentifier["WikidataID","Q3783",\[LeftAssociation]"Label"->"Amazon","Description"->"longest river in South America"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["Amazon", http://www.wikidata.org/entity/Q3783]), "Wikidata ID"]),"Entity"]

%[[1]]["Dataset"]

Entity classes: A refresher

Longest rivers in Hungary:

rivers=EntityClass["River",{(EntityProperty["countries", EntityProperty["River","Countries"], "EntityProperty[\"River\", \"Countries\"]"])->(Entity["Hungary", Entity["Country","Hungary"], "Entity[\"Country\", \"Hungary\"]", "country"]),(EntityProperty["length", EntityProperty["River","Length"], "EntityProperty[\"River\", \"Length\"]"])->TakeLargest[5]}];

Instances of this class:

EntityList[rivers]

Data about class members:

rivers["Dataset"]

Entity classes: Wikidata

Again, longest rivers in Hungary:

rivers=EntityClass["River",{(EntityProperty["countries", EntityProperty["River","Countries"], "EntityProperty[\"River\", \"Countries\"]"])->(Entity["Hungary", Entity["Country","Hungary"], "Entity[\"Country\", \"Hungary\"]", "country"]),(EntityProperty["length", EntityProperty["River","Length"], "EntityProperty[\"River\", \"Length\"]"])->TakeLargest[5]}];

Data:

WikidataData[rivers,"Dataset"]

Entity(?) classes: Wiki-classes

Wikidata ID as “type”:

WikidataData[
EntityClass[(ExternalIdentifier[ExternalIdentifier["WikidataID","Q223662",\[LeftAssociation]"Label"->"SI base unit","Description"->"one of the seven units of measurement that define the Metric System"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["SI base unit", http://www.wikidata.org/entity/Q223662]), "Wikidata ID"]),{}],
{"Quantity",(ExternalIdentifier[ExternalIdentifier["WikidataID","P111",\[LeftAssociation]"Label"->"measured physical quantity","Description"->"value of a physical property expressed as number multiplied by a unit"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["measured physical quantity", http://www.wikidata.org/entity/P111]), "Wikidata ID"])},
"Dataset"
]

More Wiki-classes

Early paintings by van Gogh:

images=WikidataData[
EntityClass[(ExternalIdentifier[ExternalIdentifier["WikidataID","Q3305213",\[LeftAssociation]"Label"->"painting","Description"->"surface artistically covered with paint"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["painting", http://www.wikidata.org/entity/Q3305213]), "Wikidata ID"]),{
(ExternalIdentifier[ExternalIdentifier["WikidataID","P170",\[LeftAssociation]"Label"->"creator","Description"->"maker of this creative work or other object (where no more specific property exists). Paintings with unknown painters, use \"anonymous\" (Q4233718) as value."\[RightAssociation]], (ExternalIdentifierLabelHyperlink["creator", http://www.wikidata.org/entity/P170]), "Wikidata ID"])->(ExternalIdentifier[ExternalIdentifier["WikidataID","Q5582",\[LeftAssociation]"Label"->"Vincent van Gogh","Description"->"Dutch painter (1853–1890)"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["Vincent van Gogh", http://www.wikidata.org/entity/Q5582]), "Wikidata ID"]),
(ExternalIdentifier[ExternalIdentifier["WikidataID","P571",\[LeftAssociation]"Label"->"inception","Description"->"date or point in time when the subject came into existence as defined"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["inception", http://www.wikidata.org/entity/P571]), "Wikidata ID"])->TakeSmallest[16]
}],
(ExternalIdentifier[ExternalIdentifier["WikidataID","P18",\[LeftAssociation]"Label"->"image","Description"->"image of relevant illustration of the subject; if available, use more specific properties (sample: coat of arms image, locator map, flag image, signature image, logo image, collage image); only images which exist on Wikimedia Commons are acceptable"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["image", http://www.wikidata.org/entity/P18]), "Wikidata ID"])
];

A collage:

ImageCollage[Cases[images,{u_URL,___}:>Thumbnail[u]]]

Your entities

A collection of books:

EntityRegister[EntityStore[{
"myLibraryBook"-><|
"Label"->"my library book",

"Entities"-><|
"divorcioEnBuda"-><|"WikidataID"->"Q2881822","Label"->"Divorcio en Buda"|>,
"faust1"-><|"WikidataID"->"Q13221881","Label"->"Faust. Eine Tragödie."|>,
"gravitation"-><|"WikidataID"->"Q5597987","Label"->"Gravitation"|>
|>,

"Properties"-><|
"author"-><|"WikidataID"->"P50","Label"->"author"|>,
"genre"-><|"WikidataID"->"P136","Label"->"genre"|>,
"publicationDate"-><|"WikidataID"->"P577","Label"->"publication date"|>
|>
|>
}]]

EntityList["myLibraryBook"]

Why store date, author, ... locally? Ask Wikidata:

WikidataData[(Entity["Faust. Eine Tragödie.", Entity["myLibraryBook","faust1"], "Entity[\"myLibraryBook\", \"faust1\"]", "my library book"]),"Dataset"]

Hand-selected properties:

Select[EntityProperties["myLibraryBook"],!MissingQ[#["WikidataID"]]&]

WikidataData[EntityList["myLibraryBook"],%,"Dataset"]

Wikidata data model: quantity - a composite value

Graph[
{
Labeled["Moon"->"statement node","claim\n(mass)"],
Labeled["statement node"->"value node","complex value\n(mass)"],
Labeled["value node"->73.477,"quantity amount"],
Labeled["value node"->"Q613726","quantity unit"],
Labeled["Q613726"->"yottagram","label"],
Labeled["Q613726"->"Yottagrams","simple value\n(WL unit code)"]
},
VertexLabels->"Name",
VertexLabelStyle->Bold,
EdgeLabelStyle->Directive[Background->White],
GraphLayout->{"LayeredEmbedding","RootVertex"->"Moon","LeafDistance"->2}
]

SPARQL

SPARQLExecute[endpoint,"select * where {
  wd:Q405 p:P2067 / psv:P2067 [
    wikibase:quantityAmount ?amount ;
    wikibase:quantityUnit ?unit ;
  ] .
  ?unit rdfs:label ?unitLabel .
    filter (lang(?unitLabel) = \"en\")
  ?unit wdt:P7007 ?unitCode .
}"]//N

WikidataData

WikidataData[(ExternalIdentifier[ExternalIdentifier["WikidataID","Q405",\[LeftAssociation]"Label"->"Moon","Description"->"only natural satellite of Earth"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["Moon", http://www.wikidata.org/entity/Q405]), "Wikidata ID"]),(ExternalIdentifier[ExternalIdentifier["WikidataID","P2067",\[LeftAssociation]"Label"->"mass","Description"->"mass (in colloquial usage also known as weight) of the item"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["mass", http://www.wikidata.org/entity/P2067]), "Wikidata ID"])]

Unit code?

https://www.wikidata.org/wiki/Q613726#P7007

Unit coverage

Aligned units

units=WikidataData[EntityClass[(ExternalIdentifier[ExternalIdentifier["WikidataID","Q47574",\[LeftAssociation]"Label"->"unit of measurement","Description"->"real scalar quantity, defined and adopted by convention, with which any other quantity of the same kind can be compared to express the ratio of the two quantities as a number"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["unit of measurement", http://www.wikidata.org/entity/Q47574]), "Wikidata ID"]),(ExternalIdentifier[ExternalIdentifier["WikidataID","P7007",\[LeftAssociation]"Label"->"Wolfram Language unit code","Description"->"input form for a unit of measurement in the Wolfram Language"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["Wolfram Language unit code", http://www.wikidata.org/entity/P7007]), "Wikidata ID"])->Not@*MissingQ],"Quantity","Association"];

Length[units]

RandomSample[units,5]

Units without alignment to WL unit

missingUnits=WikidataData[EntityClass[(ExternalIdentifier[ExternalIdentifier["WikidataID","Q47574",\[LeftAssociation]"Label"->"unit of measurement","Description"->"real scalar quantity, defined and adopted by convention, with which any other quantity of the same kind can be compared to express the ratio of the two quantities as a number (International vocabulary of metrology)"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["unit of measurement", http://www.wikidata.org/entity/Q47574]), "Wikidata ID"]),(ExternalIdentifier[ExternalIdentifier["WikidataID","P7007",\[LeftAssociation]"Label"->"Wolfram Language unit code","Description"->"input form for a unit of measurement in the Wolfram Language"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["Wolfram Language unit code", http://www.wikidata.org/entity/P7007]), "Wikidata ID"])->MissingQ],"WikidataID"][[All,1]];

Length[missingUnits]

RandomSample[Select[missingUnits,!MissingQ[#["Label"]]&],8]

Overall coverage

Fraction of all (individual) quantities in Wikidata having a translation to the WL:

SPARQLExecute[endpoint,"
select (?wlUnitCount / ?unitCount as ?wlUnitUsage) where {
  { select (count( * ) as ?wlUnitCount) where { [] wikibase:quantityUnit / wdt:P7007 [] } }
  { select (count( * ) as ?unitCount) where { [] wikibase:quantityUnit [] } }
}
"]//N

Remaining problems

Type 1

Not all historical units exists in the WL (yet):

WikidataData[(ExternalIdentifier[ExternalIdentifier["WikidataID","Q3774493",\[LeftAssociation]"Label"->"pes","Description"->"Ancient Roman unit of length; approximately 29.6 cm"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["pes", http://www.wikidata.org/entity/Q3774493]), "Wikidata ID"]),(ExternalIdentifier[ExternalIdentifier["WikidataID","P2442",\[LeftAssociation]"Label"->"conversion to standard unit","Description"->"translation of the value of a measurement to different units"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["conversion to standard unit", http://www.wikidata.org/entity/P2442]), "Wikidata ID"])]

Type 2

Suboptimal classification on Wikidata:

WikidataData[(ExternalIdentifier[ExternalIdentifier["WikidataID","Q359156",\[LeftAssociation]"Label"->"thermal transmittance","Description"->"rate of transfer of heat through matter, expressed as a U-value"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["thermal transmittance", http://www.wikidata.org/entity/Q359156]), "Wikidata ID"]),(ExternalIdentifier[ExternalIdentifier["WikidataID","P31",\[LeftAssociation]"Label"->"instance of","Description"->"that class of which this subject is a particular example and member (subject typically an individual member with a proper name label); different from P279; using this property as a qualifier is deprecated—use P2868 or P3831 instead"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["instance of", http://www.wikidata.org/entity/P31]), "Wikidata ID"])]

Type 3

Typos (year as unit instead of date qualifier):

GeoPosition

Not on earth:

WikidataData[(ExternalIdentifier[ExternalIdentifier["WikidataID","Q620980",\[LeftAssociation]"Label"->"Moltke","Description"->"lunar crater"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["Moltke", http://www.wikidata.org/entity/Q620980]), "Wikidata ID"]),(ExternalIdentifier[ExternalIdentifier["WikidataID","P625",\[LeftAssociation]"Label"->"coordinate location","Description"->"geocoordinates of the subject. For Earth, please note that only WGS84 coordinating system is supported at the moment"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["coordinate location", http://www.wikidata.org/entity/P625]), "Wikidata ID"])]

GeoListPlot[%]

Relevant property: Wolfram Language Entity Code (P4839)
https://www.wikidata.org/wiki/Q405#P4839

Geo queries

Physicists born around Ulm:

WikidataData[
EntityClass[(ExternalIdentifier[ExternalIdentifier["WikidataID","Q5",\[LeftAssociation]"Label"->"human","Description"->"common name of Homo sapiens, unique extant species of the genus Homo"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["human", http://www.wikidata.org/entity/Q5]), "Wikidata ID"]),{
(ExternalIdentifier[ExternalIdentifier["WikidataID","P106",\[LeftAssociation]"Label"->"occupation","Description"->"occupation of a person; see also \"field of work\" (Property:P101), \"position held\" (Property:P39)"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["occupation", http://www.wikidata.org/entity/P106]), "Wikidata ID"])->(ExternalIdentifier[ExternalIdentifier["WikidataID","Q169470",\[LeftAssociation]"Label"->"physicist","Description"->"scientist who does research in physics"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["physicist", http://www.wikidata.org/entity/Q169470]), "Wikidata ID"]),
(ExternalIdentifier[ExternalIdentifier["WikidataID","P19",\[LeftAssociation]"Label"->"place of birth","Description"->"most specific known (e.g. city instead of country, or hospital instead of city) birth location of a person, animal or fictional character"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["place of birth", http://www.wikidata.org/entity/P19]), "Wikidata ID"])->GeoDisk[(Entity["Ulm", Entity["City",{"Ulm","BadenWurttemberg","Germany"}], "Entity[\"City\", {\"Ulm\", \"BadenWurttemberg\", \"Germany\"}]", "city"]),(Quantity[20, "km", kilometers, "Kilometers"])]
}],
{(ExternalIdentifier[ExternalIdentifier["WikidataID","P569",\[LeftAssociation]"Label"->"date of birth","Description"->"date on which the subject was born"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["date of birth", http://www.wikidata.org/entity/P569]), "Wikidata ID"]),(ExternalIdentifier[ExternalIdentifier["WikidataID","P166",\[LeftAssociation]"Label"->"award received","Description"->"award or recognition received by a person, organisation or creative work"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["award received", http://www.wikidata.org/entity/P166]), "Wikidata ID"])},
"Dataset"
]

Implicit “location” property:

WikidataData[
EntityClass[(ExternalIdentifier[ExternalIdentifier["WikidataID","Q23397",\[LeftAssociation]"Label"->"lake","Description"->"body of relatively still water, localized in a basin"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["lake", http://www.wikidata.org/entity/Q23397]), "Wikidata ID"]),{
GeoDisk[(Entity["Budapest", Entity["City",{"Budapest","Budapest","Hungary"}], "Entity[\"City\", {\"Budapest\", \"Budapest\", \"Hungary\"}]", "city"]),(Quantity[200, "km", kilometers, "Kilometers"])],
(ExternalIdentifier[ExternalIdentifier["WikidataID","P2046",\[LeftAssociation]"Label"->"area","Description"->"area occupied by an object"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["area", http://www.wikidata.org/entity/P2046]), "Wikidata ID"])->GreaterThan[(Quantity[50, (("km")^2), kilometers squared, (("Kilometers")^2)])]
}],
{(ExternalIdentifier[ExternalIdentifier["WikidataID","P2046",\[LeftAssociation]"Label"->"area","Description"->"area occupied by an object"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["area", http://www.wikidata.org/entity/P2046]), "Wikidata ID"]),(ExternalIdentifier[ExternalIdentifier["WikidataID","P625",\[LeftAssociation]"Label"->"coordinate location","Description"->"geocoordinates of the subject. For Earth, please note that only WGS84 coordinating system is supported at the moment"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["coordinate location", http://www.wikidata.org/entity/P625]), "Wikidata ID"]),"Entity"},
"Dataset"
]

GeoListPlot[Values[%[All,Key[(ExternalIdentifier[ExternalIdentifier["WikidataID","P625",\[LeftAssociation]"Label"->"coordinate location","Description"->"geocoordinates of the subject. For Earth, please note that only WGS84 coordinating system is supported at the moment"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["coordinate location", http://www.wikidata.org/entity/P625]), "Wikidata ID"])],1]]]

Order-limit queries

By quantity

Large telescopes:

WikidataData[EntityClass[(ExternalIdentifier[ExternalIdentifier["WikidataID","Q2920313",\[LeftAssociation]"Label"->"optical system","Description"->"assembly of optical components, or equivalently a system consisting of regions of material with varying refractive indices"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["optical system", http://www.wikidata.org/entity/Q2920313]), "Wikidata ID"]),(ExternalIdentifier[ExternalIdentifier["WikidataID","P2151",\[LeftAssociation]"Label"->"focal length","Description"->"focal length of lens (telescope, etc.)"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["focal length", http://www.wikidata.org/entity/P2151]), "Wikidata ID"])->TakeLargest[3]],(ExternalIdentifier[ExternalIdentifier["WikidataID","P2151",\[LeftAssociation]"Label"->"focal length","Description"->"focal length of lens (telescope, etc.)"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["focal length", http://www.wikidata.org/entity/P2151]), "Wikidata ID"]),"Association"]

Units are taken into account:

WikidataData[EntityClass[(ExternalIdentifier[ExternalIdentifier["WikidataID","Q2920313",\[LeftAssociation]"Label"->"optical system","Description"->"assembly of optical components, or equivalently a system consisting of regions of material with varying refractive indices"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["optical system", http://www.wikidata.org/entity/Q2920313]), "Wikidata ID"]),(ExternalIdentifier[ExternalIdentifier["WikidataID","P2151",\[LeftAssociation]"Label"->"focal length","Description"->"focal length of lens (telescope, etc.)"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["focal length", http://www.wikidata.org/entity/P2151]), "Wikidata ID"])->TakeSmallest[3]],(ExternalIdentifier[ExternalIdentifier["WikidataID","P2151",\[LeftAssociation]"Label"->"focal length","Description"->"focal length of lens (telescope, etc.)"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["focal length", http://www.wikidata.org/entity/P2151]), "Wikidata ID"]),"Association"]

By date

Latest Tarantino movies:

WikidataData[EntityClass[(ExternalIdentifier[ExternalIdentifier["WikidataID","Q11424",\[LeftAssociation]"Label"->"film","Description"->"sequence of images that give the impression of movement"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["film", http://www.wikidata.org/entity/Q11424]), "Wikidata ID"]),{
(ExternalIdentifier[ExternalIdentifier["WikidataID","P57",\[LeftAssociation]"Label"->"director","Description"->"director(s) of film, TV-series, stageplay, video game or similar"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["director", http://www.wikidata.org/entity/P57]), "Wikidata ID"])->(ExternalIdentifier[ExternalIdentifier["WikidataID","Q3772",\[LeftAssociation]"Label"->"Quentin Tarantino","Description"->"American film director, screenwriter, producer, and actor"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["Quentin Tarantino", http://www.wikidata.org/entity/Q3772]), "Wikidata ID"]),
(ExternalIdentifier[ExternalIdentifier["WikidataID","P577",\[LeftAssociation]"Label"->"publication date","Description"->"date or point in time when a work was first published or released"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["publication date", http://www.wikidata.org/entity/P577]), "Wikidata ID"])->TakeLargest[3]
}],(ExternalIdentifier[ExternalIdentifier["WikidataID","P577",\[LeftAssociation]"Label"->"publication date","Description"->"date or point in time when a work was first published or released"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["publication date", http://www.wikidata.org/entity/P577]), "Wikidata ID"]),"Association"]

Property paths (experimental design)

Countries whose capital’s head of government’s birth place is in Greece:

WikidataData[
EntityClass[
(ExternalIdentifier[ExternalIdentifier["WikidataID","Q6256",\[LeftAssociation]"Label"->"country","Description"->"distinct region in geography; a broad term that can include political divisions or regions associated with distinct political characteristics"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["country", http://www.wikidata.org/entity/Q6256]), "Wikidata ID"]),
{(ExternalIdentifier[ExternalIdentifier["WikidataID","P36",\[LeftAssociation]"Label"->"capital","Description"->"primary city of a country, province, state or other type of administrative territorial entity"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["capital", http://www.wikidata.org/entity/P36]), "Wikidata ID"]),(ExternalIdentifier[ExternalIdentifier["WikidataID","P6",\[LeftAssociation]"Label"->"head of government","Description"->"head of the executive power of this town, city, municipality, state, country, or other governmental body"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["head of government", http://www.wikidata.org/entity/P6]), "Wikidata ID"]),(ExternalIdentifier[ExternalIdentifier["WikidataID","P19",\[LeftAssociation]"Label"->"place of birth","Description"->"most specific known (e.g. city instead of country, or hospital instead of city) birth location of a person, animal or fictional character"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["place of birth", http://www.wikidata.org/entity/P19]), "Wikidata ID"]),(ExternalIdentifier[ExternalIdentifier["WikidataID","P17",\[LeftAssociation]"Label"->"country","Description"->"sovereign state of this item; don't use on humans"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["country", http://www.wikidata.org/entity/P17]), "Wikidata ID"])}->(ExternalIdentifier[ExternalIdentifier["WikidataID","Q41",\[LeftAssociation]"Label"->"Greece","Description"->"republic in Southeast Europe"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["Greece", http://www.wikidata.org/entity/Q41]), "Wikidata ID"])
],
(ExternalIdentifier[ExternalIdentifier["WikidataID","P36",\[LeftAssociation]"Label"->"capital","Description"->"primary city of a country, province, state or other type of administrative territorial entity"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["capital", http://www.wikidata.org/entity/P36]), "Wikidata ID"]),
"Association"
]

Design question: How to retrieve the capital’s head of government?

(* wrong *)
WikidataData[
(ExternalIdentifier[ExternalIdentifier["WikidataID","Q209065",\[LeftAssociation]"Label"->"Kingdom of Greece","Description"->"kingdom in Southern Europe during the 19th and 20th century"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["Kingdom of Greece", http://www.wikidata.org/entity/Q209065]), "Wikidata ID"]),
{(ExternalIdentifier[ExternalIdentifier["WikidataID","P36",\[LeftAssociation]"Label"->"capital","Description"->"primary city of a country, province, state or other type of administrative territorial entity"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["capital", http://www.wikidata.org/entity/P36]), "Wikidata ID"]),(ExternalIdentifier[ExternalIdentifier["WikidataID","P6",\[LeftAssociation]"Label"->"head of government","Description"->"head of the executive power of this town, city, municipality, state, country, or other governmental body"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["head of government", http://www.wikidata.org/entity/P6]), "Wikidata ID"])}
]

Homework: Why is this wrong?
Bonus: Design suggestions?

SPARQL and WikidataData

Why?
- Query that can’t be expressed using EntityClass.
- Focus on the conditions, WikidataData does the rest.

Pattern for “children of Einstein”:

pattern=RDFTriple[URL[(URLArgument["http://www.wikidata.org/entity/Q937"])],URL[(URLArgument["http://www.wikidata.org/prop/direct/P40"])],SPARQLVariable["Entity"]];

Execute a SELECT query:

SPARQLExecute[endpoint,SPARQLSelect[pattern]]

Get labels, descriptions, property values, result formats, ... for free:

WikidataData[pattern,(ExternalIdentifier[ExternalIdentifier["WikidataID","P569",\[LeftAssociation]"Label"->"date of birth","Description"->"date on which the subject was born"\[RightAssociation]], (ExternalIdentifierLabelHyperlink["date of birth", http://www.wikidata.org/entity/P569]), "Wikidata ID"]),"Association"]

Wikibase

Setup

Install docker.

Git clone wikibase-docker.

Terminal: “docker-compose up -d”

Enter data

Main page.

Use data

Query.

Or...

Needs["GraphStore`Wikibase`"]

Configuration:

wbConfig=WikibaseObject[<|
"ConceptBaseURI"->"http://example.org/entity/",
"ConceptType"->"ExampleID",
"SPARQLEndpoint"->"http://localhost:8989/bigdata/sparql",
"SearchEndpoint"->"http://localhost:8181/w/api.php"
|>];

myPictureSearch[keywords_]:=WikibaseSearch[wbConfig,keywords];
myPictureData[args__]:=WikibaseData[wbConfig,args];

Search:

myPictureSearch["picture of a rose"]

Look up data:

myPictureData[(ExternalIdentifier[ExternalIdentifier["ExampleID","Q2",\[LeftAssociation]"Label"->"picture of a rose"\[RightAssociation]], (ExternalIdentifierLabel["picture of a rose"]), "Example ID"]),"Dataset"]

Thanks.

WikidataSearch["thanks",MaxItems->5]

WikidataSearch["Danke",Language->"German",MaxItems->5]

WikidataSearch["merci",Language->"French",MaxItems->5]

WikidataSearch["gracias",Language->"Spanish",MaxItems->5]

FirstCase[GroupBy[Join[%,%%,%%%,%%%%],#["ID"]&],{_,_,_,_}]