Sparql

Playing with a new #asciidoctor extension for the blog querying Wikidata (or Dbpedia) using SPARQL

Wikidata

.List of Pokemons
[sparql, fields="pokemon,pokemonLabel,pokedexNumber"]
----
SELECT DISTINCT ?pokemon ?pokemonLabel ?pokedexNumber
WHERE
{
    ?pokemon wdt:P31/wdt:P279* wd:Q3966183 .
    ?pokemon p:P1685 ?statement.
    ?statement ps:P1685 ?pokedexNumber;
            pq:P972 wd:Q20005020.
    FILTER (! wikibase:isSomeValue(?pokedexNumber) )
    SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
}
ORDER BY (?pokedexNumber)
LIMIT 30
----
Table 1. List of Pokemons
pokemon pokemonLabel pokedexNumber

http://www.wikidata.org/entity/Q847571

Bulbasaur

001

http://www.wikidata.org/entity/Q1636903

Ivysaur

002

http://www.wikidata.org/entity/Q2283930

Venusaur

003

http://www.wikidata.org/entity/Q3178753

Charmander

004

http://www.wikidata.org/entity/Q1637365

Charmeleon

005

http://www.wikidata.org/entity/Q844940

Charizard

006

http://www.wikidata.org/entity/Q845294

Squirtle

007

http://www.wikidata.org/entity/Q1752151

Wartortle

008

http://www.wikidata.org/entity/Q1752154

Blastoise

009

http://www.wikidata.org/entity/Q1651039

Caterpie

010

http://www.wikidata.org/entity/Q1646079

Metapod

011

http://www.wikidata.org/entity/Q1252891

Butterfree

012

http://www.wikidata.org/entity/Q1778712

Weedle

013

http://www.wikidata.org/entity/Q1778696

Kakuna

014

http://www.wikidata.org/entity/Q2014761

Beedrill

015

http://www.wikidata.org/entity/Q1769892

Pidgey

016

http://www.wikidata.org/entity/Q2090182

Pidgeotto

017

http://www.wikidata.org/entity/Q2337000

Pidgeot

018

http://www.wikidata.org/entity/Q2252880

Rattata

019

http://www.wikidata.org/entity/Q2265115

Raticate

020

http://www.wikidata.org/entity/Q2021999

Spearow

021

http://www.wikidata.org/entity/Q2087817

Fearow

022

http://www.wikidata.org/entity/Q1266064

Ekans

023

http://www.wikidata.org/entity/Q1289969

Arbok

024

http://www.wikidata.org/entity/Q9351

Pikachu

025

http://www.wikidata.org/entity/Q1647331

Raichu

026

http://www.wikidata.org/entity/Q2002398

Sandshrew

027

http://www.wikidata.org/entity/Q2345521

Sandslash

028

http://www.wikidata.org/entity/Q2725378

Nidoran♀

029

http://www.wikidata.org/entity/Q1998207

Nidorina

030

.Cats
[sparql, provider="wikidata", fields="item,itemLabel,pic"]
----
SELECT ?item ?itemLabel ?pic
WHERE
{
?item wdt:P31 wd:Q146 .
?item wdt:P18 ?pic
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
}
LIMIT 10
----

Dbpedia

.People who were born in Berlin before 1900
[sparql, provider="dbpedia", fields="name,birth,death,person"]
----
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX : <http://dbpedia.org/resource/>
SELECT ?name ?birth ?death ?person WHERE {
    ?person dbo:birthPlace :Berlin .
    ?person dbo:birthDate ?birth .
    ?person foaf:name ?name .
    ?person dbo:deathDate ?death .
    FILTER (?birth < "1900-01-01"^^xsd:date) .
} ORDER BY ?name
LIMIT 30
----
Table 3. People who were born in Berlin before 1900
name birth death person

"Annot" (Annot Jacobi)

1894-12-27

1981-10-20

http://dbpedia.org/resource/Annot_(artist)

()

1811-10-29

1873-06-06

http://dbpedia.org/resource/Prince_Adalbert_of_Prussia_(1811–1873)

()

1811-10-29

1873-6-6

http://dbpedia.org/resource/Prince_Adalbert_of_Prussia_(1811–1873)

(Henry William Adalbert)

1811-10-29

1873-06-06

http://dbpedia.org/resource/Prince_Adalbert_of_Prussia_(1811–1873)

(Henry William Adalbert)

1811-10-29

1873-6-6

http://dbpedia.org/resource/Prince_Adalbert_of_Prussia_(1811–1873)

Abraham Mendelssohn Bartholdy

1776-12-10

1835-11-19

http://dbpedia.org/resource/Abraham_Mendelssohn_Bartholdy

Achim von Arnim

1781-01-26

1831-1-21

http://dbpedia.org/resource/Ludwig_Achim_von_Arnim

Adalbert of Prussia

1811-10-29

1873-06-06

http://dbpedia.org/resource/Prince_Adalbert_of_Prussia_(1811–1873)

Adalbert of Prussia

1811-10-29

1873-6-6

http://dbpedia.org/resource/Prince_Adalbert_of_Prussia_(1811–1873)

Adam Müller

1779-06-30

1829-01-17

http://dbpedia.org/resource/Adam_Müller

Adam Müller

1779-06-30

1829-1-17

http://dbpedia.org/resource/Adam_Müller

Adolf Brand

1874-11-14

1945-2-2

http://dbpedia.org/resource/Adolf_Brand

Adolf Christen

1811-08-07

1883-07-13

http://dbpedia.org/resource/Adolf_Christen

Adolf Christen

1811-08-07

1883-7-13

http://dbpedia.org/resource/Adolf_Christen

Adolf Damaschke

1865-11-24

1935-7-30

http://dbpedia.org/resource/Adolf_Damaschke

Adolf Erman

1854-10-31

1937-6-26

http://dbpedia.org/resource/Adolf_Erman

Adolf Gärtner

1879-03-24

1958-01-09

http://dbpedia.org/resource/Adolf_Gärtner

Adolf Gärtner

1879-03-24

1958-1-9

http://dbpedia.org/resource/Adolf_Gärtner

Adolf Heinrich von Arnim-Boitzenburg

1803-04-10

1868-01-08

http://dbpedia.org/resource/Adolf_Heinrich_von_Arnim-Boitzenburg

Adolf Heinrich von Arnim-Boitzenburg

1803-04-10

1868-1-8

http://dbpedia.org/resource/Adolf_Heinrich_von_Arnim-Boitzenburg

Adolf Huschke

1891-10-14

1923-08-29

http://dbpedia.org/resource/Adolf_Huschke

Adolf Huschke

1891-10-14

1923-8-29

http://dbpedia.org/resource/Adolf_Huschke

Adolf Kirchhoff

1826-01-06

1908-02-26

http://dbpedia.org/resource/Adolf_Kirchhoff

Adolf Kirchhoff

1826-01-06

1908-2-26

http://dbpedia.org/resource/Adolf_Kirchhoff

Adolf Otto Reinhold Windaus

1876-12-25

1959-06-09

http://dbpedia.org/resource/Adolf_Windaus

Adolf Otto Reinhold Windaus

1876-12-25

1959-6-9

http://dbpedia.org/resource/Adolf_Windaus

Adolf von Baeyer

1835-10-31

1917-08-20

http://dbpedia.org/resource/Adolf_von_Baeyer

Adolf von Baeyer

1835-10-31

1917-8-20

http://dbpedia.org/resource/Adolf_von_Baeyer

Agnes of Brandenburg

1584-07-17

1629-03-26

http://dbpedia.org/resource/Agnes_of_Brandenburg,_Duchess_of_Pomerania

Agnes of Brandenburg

1584-07-17

1629-3-26

http://dbpedia.org/resource/Agnes_of_Brandenburg,_Duchess_of_Pomerania

.Jugadores de Futbol nacidos en Madrid
[sparql, provider="dbpedia", fields='athlete,number']
----
SELECT *
WHERE
{
?athlete a dbo:SoccerPlayer;
dbo:birthPlace [rdfs:label "Madrid"@en];
dbo:number ?number.
}
LIMIT 30
----
Table 4. Jugadores de Futbol nacidos en Madrid
athlete number

http://dbpedia.org/resource/Álvaro_Morata

21

http://dbpedia.org/resource/Álvaro_Negredo

10

http://dbpedia.org/resource/Álvaro_Tejero

3

http://dbpedia.org/resource/Roberto_Román_Triguero

2

http://dbpedia.org/resource/David_de_Gea

1

http://dbpedia.org/resource/Borja_González

10

http://dbpedia.org/resource/Ernesto_Galán

2

http://dbpedia.org/resource/Rubén_Belima

7

http://dbpedia.org/resource/Mario_Hermoso

TBA

http://dbpedia.org/resource/Borja_García_Freire

24

http://dbpedia.org/resource/Nagore_(footballer)

24

http://dbpedia.org/resource/Raúl_Llorente

23

http://dbpedia.org/resource/Samuel_Sáiz

14

http://dbpedia.org/resource/Amanda_Sampedro

10

http://dbpedia.org/resource/Natalia_Pablos

17

http://dbpedia.org/resource/Sonia_Prim

4

http://dbpedia.org/resource/Juan_Carlos_(footballer,_born_1990)

7

http://dbpedia.org/resource/Juanfran_(footballer,_born_1988)

2

http://dbpedia.org/resource/Koke_(footballer,_born_1992)

6

http://dbpedia.org/resource/Álvaro_Domínguez_Soto

18

http://dbpedia.org/resource/Carlos_Calvo_Sobrado

12

http://dbpedia.org/resource/Jesús_Fernández_Collado

13

http://dbpedia.org/resource/Alberto_Bueno

23

http://dbpedia.org/resource/Álex_Fernández

9

http://dbpedia.org/resource/David_Mateos

44

http://dbpedia.org/resource/Esteban_Granero

8

http://dbpedia.org/resource/Tomás_Mejías

13

http://dbpedia.org/resource/Derik_Osede

15

http://dbpedia.org/resource/Jennifer_Hermoso

10

http://dbpedia.org/resource/Aitor_Monroy_Rueda

62

Custom endpoint

You can specify the endpoint using the provider attribute:

[sparql, provider="https://es.dbpedia.org/sparql", fields="torero,cantante"]
----
PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
PREFIX dcterms: <http://purl.org/dc/terms/>
SELECT ?torero ?cantante WHERE{
?torero rdf:type dbpedia-owl:BullFighter .
?torero dbpedia-owl:spouse ?cantante .
?cantante dcterms:subject <http://es.dbpedia.org/resource/Categoría:Cantantes_de_coplas>
}
----
Follow comments at Telegram groupOr subscribe to the Channel Telegram channel

2019 - 2020 | Mixed with Bootstrap | Baked with JBake v2.6.5