Querying Linked Data with SPARQL and the Wikidata Query Service - - PowerPoint PPT Presentation

querying linked data with sparql and the wikidata query
SMART_READER_LITE
LIVE PREVIEW

Querying Linked Data with SPARQL and the Wikidata Query Service - - PowerPoint PPT Presentation

Querying Linked Data with SPARQL and the Wikidata Query Service Lucas Werkmeister 2019-12-27 Lucas Werkmeister https://tinyurl.com/36c3-wdqs 1/20 An example graph happens in is next to Esszimmer is next to Kche is part of happens in


slide-1
SLIDE 1

Querying Linked Data with SPARQL and the Wikidata Query Service

Lucas Werkmeister 2019-12-27

Lucas Werkmeister https://tinyurl.com/36c3-wdqs 1/20

slide-2
SLIDE 2

An example graph

Esszimmer Küche this talk live querying WikipakaWG 2019-12-27T 12:00:00+0100 36C3 Klimawahlen Chaos-West Stage Chaos West is followed by follows happens in happens in is next to is next to is part of is part of is part of starts at starts at happens in is part of is part of

Lucas Werkmeister https://tinyurl.com/36c3-wdqs 2/20

slide-3
SLIDE 3

Example questions

Which talk follows this one? this talk ?talk follows Matching triple: this talk live querying follows

Lucas Werkmeister https://tinyurl.com/36c3-wdqs 3/20

slide-4
SLIDE 4

Example questions

Same question, phrased differently: Which talk is this one followed by? This talk is followed by which one? this talk ?talk is followed by Matching triple: this talk live querying is followed by

Lucas Werkmeister https://tinyurl.com/36c3-wdqs 4/20

slide-5
SLIDE 5

Example questions

Which talk happens in Esszimmer? Esszimmer ?talk happens in Matching triples: Esszimmer this talk live querying happens in happens in

Lucas Werkmeister https://tinyurl.com/36c3-wdqs 5/20

slide-6
SLIDE 6

Example questions

Which talks happen in the WikipakaWG? That is, which talks happen in a room that’s part of the WikipakaWG? ?room ?talk WikipakaWG happens in is part of Matching triples: Esszimmer this talk live querying WikipakaWG happens in happens in is part of

Lucas Werkmeister https://tinyurl.com/36c3-wdqs 6/20

slide-7
SLIDE 7

SPARQL

Esszimmer ?talk happens in might translate into: SELECT * WHERE { ?talk 36c3:happensIn 36c3:Esszimmer. } The 36c3: prefix clarifies which Esszimmer we’re talking about.

Lucas Werkmeister https://tinyurl.com/36c3-wdqs 7/20

slide-8
SLIDE 8

SPARQL

?room ?talk WikipakaWG happens in is part of might translate into: SELECT * WHERE { ?talk 36c3:happensIn ?room. ?room 36c3:isPartOf 36c3:WikipakaWG. }

Lucas Werkmeister https://tinyurl.com/36c3-wdqs 8/20

slide-9
SLIDE 9

SPARQL

?room ?talk WikipakaWG happens in is part of might also translate into: SELECT ?talk WHERE { ?talk 36c3:happensIn [ schema:isPartOf 36c3:WikipakaWG ]. }

Lucas Werkmeister https://tinyurl.com/36c3-wdqs 9/20

slide-10
SLIDE 10

Example queries

Which software is written in Bash?

Lucas Werkmeister https://tinyurl.com/36c3-wdqs 10/20

slide-11
SLIDE 11

Example queries

Which software is written in Bash? ?software Bash programming language

Lucas Werkmeister https://tinyurl.com/36c3-wdqs 10/20

slide-12
SLIDE 12

Example queries

Which software is written in Bash? ?software Bash programming language SELECT ?software WHERE { ?software wdt:P277 wd:Q189248. }

Lucas Werkmeister https://tinyurl.com/36c3-wdqs 10/20

slide-13
SLIDE 13

Example queries

Who was born at sea?

Lucas Werkmeister https://tinyurl.com/36c3-wdqs 11/20

slide-14
SLIDE 14

Example queries

Who was born at sea? ?person at sea place of birth

Lucas Werkmeister https://tinyurl.com/36c3-wdqs 11/20

slide-15
SLIDE 15

Example queries

Who was born at sea? ?person at sea place of birth SELECT ?person WHERE { ?person wdt:P19 wd:Q55438959. }

Lucas Werkmeister https://tinyurl.com/36c3-wdqs 11/20

slide-16
SLIDE 16

Example queries

Which places are located on the White Elster?

Lucas Werkmeister https://tinyurl.com/36c3-wdqs 12/20

slide-17
SLIDE 17

Example queries

Which places are located on the White Elster? ?place White Elster located in or next to body of water

Lucas Werkmeister https://tinyurl.com/36c3-wdqs 12/20

slide-18
SLIDE 18

Example queries

Which places are located on the White Elster? ?place White Elster located in or next to body of water SELECT ?place WHERE { ?place wdt:P206 wd:Q44729. }

Lucas Werkmeister https://tinyurl.com/36c3-wdqs 12/20

slide-19
SLIDE 19

Example queries

Where does The Neverending Story take place?

Lucas Werkmeister https://tinyurl.com/36c3-wdqs 13/20

slide-20
SLIDE 20

Example queries

Where does The Neverending Story take place? The Neverending Story ?place narrative location

Lucas Werkmeister https://tinyurl.com/36c3-wdqs 13/20

slide-21
SLIDE 21

Example queries

Where does The Neverending Story take place? The Neverending Story ?place narrative location SELECT ?place WHERE { wd:Q463108 wdt:P840 ?place. }

Lucas Werkmeister https://tinyurl.com/36c3-wdqs 13/20

slide-22
SLIDE 22

Example queries

Which popes had children?

Lucas Werkmeister https://tinyurl.com/36c3-wdqs 14/20

slide-23
SLIDE 23

Example queries

Which popes had children? ?child ?pope pope father position held

Lucas Werkmeister https://tinyurl.com/36c3-wdqs 14/20

slide-24
SLIDE 24

Example queries

Which popes had children? ?child ?pope pope father position held SELECT ?pope ?child WHERE { ?child wdt:P22 ?pope. ?pope wdt:P39 wd:Q19546. }

Lucas Werkmeister https://tinyurl.com/36c3-wdqs 14/20

slide-25
SLIDE 25

Example queries

Which popes had children?

Lucas Werkmeister https://tinyurl.com/36c3-wdqs 15/20

slide-26
SLIDE 26

Example queries

Which popes had children? pope ?pope ?child position held child

Lucas Werkmeister https://tinyurl.com/36c3-wdqs 15/20

slide-27
SLIDE 27

Example queries

Which popes had children? pope ?pope ?child position held child SELECT ?pope ?child WHERE { ?pope wdt:P39 wd:Q19546; wdt:P40 ?child. }

Lucas Werkmeister https://tinyurl.com/36c3-wdqs 15/20

slide-28
SLIDE 28

Example queries

Which Microsoft software runs on Linux?

Lucas Werkmeister https://tinyurl.com/36c3-wdqs 16/20

slide-29
SLIDE 29

Example queries

Which Microsoft software runs on Linux? Microsoft ?software Linux developer

  • perating system

Lucas Werkmeister https://tinyurl.com/36c3-wdqs 16/20

slide-30
SLIDE 30

Example queries

Which Microsoft software runs on Linux? Microsoft ?software Linux developer

  • perating system

SELECT ?software WHERE { ?software wdt:P178 wd:Q2283; wdt:P306 wd:Q388. }

Lucas Werkmeister https://tinyurl.com/36c3-wdqs 16/20

slide-31
SLIDE 31

Example queries

What are some compositions for organ and orchestra?

Lucas Werkmeister https://tinyurl.com/36c3-wdqs 17/20

slide-32
SLIDE 32

Example queries

What are some compositions for organ and orchestra?

  • rgan

?composition

  • rchestra

instrumentation instrumentation

Lucas Werkmeister https://tinyurl.com/36c3-wdqs 17/20

slide-33
SLIDE 33

Example queries

What are some compositions for organ and orchestra?

  • rgan

?composition

  • rchestra

instrumentation instrumentation SELECT ?composition WHERE { ?composition wdt:P870 wd:Q1444, wd:Q42998. }

Lucas Werkmeister https://tinyurl.com/36c3-wdqs 17/20

slide-34
SLIDE 34

Example queries

Which Nazi party members later received the Order of Merit of the Federal Republic of Germany?

Lucas Werkmeister https://tinyurl.com/36c3-wdqs 18/20

slide-35
SLIDE 35

Example queries

Which Nazi party members later received the Order of Merit of the Federal Republic of Germany? NSDAP ?person human Bundesverdienstkreuz member of political party instance of award received

Lucas Werkmeister https://tinyurl.com/36c3-wdqs 18/20

slide-36
SLIDE 36

Example queries

Which Nazi party members later received the Order of Merit of the Federal Republic of Germany? NSDAP ?person human Bundesverdienstkreuz member of political party instance of award received SELECT ?person WHERE { ?person wdt:P31 wd:Q5; wdt:P102 wd:Q7320; wdt:P166 wd:Q21164. }

Lucas Werkmeister https://tinyurl.com/36c3-wdqs 18/20

slide-37
SLIDE 37

Example queries

What are the largest cities (by population) with a female mayor?

Lucas Werkmeister https://tinyurl.com/36c3-wdqs 19/20

slide-38
SLIDE 38

Example queries

What are the largest cities (by population) with a female mayor? city ?city ?population human ?mayor ?female instance of population head of government instance of gender (Not pictured: the “largest” part.)

Lucas Werkmeister https://tinyurl.com/36c3-wdqs 19/20

slide-39
SLIDE 39

Example queries

What are the largest cities (by population) with a female mayor? SELECT ?city ?mayor ?population WHERE { ?city wdt:P31 wd:Q515; wdt:P1082 ?population; wdt:P6 ?mayor. ?mayor wdt:P31 wd:Q5; wdt:P21 wd:Q6581072. } ORDER BY DESC(?population) LIMIT 10 (Note that this misses some items that are e. g. “instance of: big city” rather than “instance of: city”.)

Lucas Werkmeister https://tinyurl.com/36c3-wdqs 19/20

slide-40
SLIDE 40

Example queries

What are the largest cities (by population) with a female mayor? SELECT ?city WHERE { ?city wdt:P31 wd:Q515; wdt:P1082 ?population; wdt:P6 [ wdt:P31 wd:Q5; wdt:P21 wd:Q6581072 ]. } ORDER BY DESC(?population) LIMIT 10

Lucas Werkmeister https://tinyurl.com/36c3-wdqs 19/20

slide-41
SLIDE 41

Closing stuff

Fun/interesting queries: @WikidataFacts or @WikidataFacts@mastodon.social Wikidata Query Service help portal: wikidata:Help:SPARQL (w.wiki/EV2) Many many example queries: wikidata:Wikidata:SPARQL query service/queries/examples (w.wiki/EXA) These slides: github.com/lucaswerkmeister/36c3-wdqs Other queries promised in the talk description:

Which films starred more than one future head of government? (w.wiki/EV$) When did women finally outnumber Johns in the House of Commons? (w.wiki/EVz)

Lucas Werkmeister https://tinyurl.com/36c3-wdqs 20/20