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
----
.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
----

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 group Or subscribe to the Channel Telegram channel

2019 - 2021 | Mixed with Bootstrap | Baked with JBake v2.6.7