Sparql examples

This documents shows by example how to translate informal data questions into formal knowledge base queries.

People who were born in Berlin before 1900

answer fields
  • name
  • birth
  • death
  • person
datasets 
  • http://dbpedia.org/sparql

SPARQL query:

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

Try it in dbpedia.

Soccer players, who are born in a country with more than 10 million inhabitants, who played as goalkeeper for a club that has a stadium with more than 30.000 seats and the club country is different from the birth country

answer fields
  • soccerplayer
  • countryOfBirth
  • team 
  • countryOfTeam
  • stadiumcapacity
datasets 
  • http://dbpedia.org/sparql

SPARQL query:

PREFIX dbo: <http://dbpedia.org/ontology/>

SELECT distinct ?soccerplayer ?countryOfBirth ?team ?countryOfTeam ?stadiumcapacity
?soccerplayer a dbo:SoccerPlayer ;
   dbo:position|dbp:position <http://dbpedia.org/resource/Goalkeeper_(association_football)> ;
   dbo:birthPlace/dbo:country* ?countryOfBirth ;
   #dbo:number 13 ;
   dbo:team ?team .
   ?team dbo:capacity ?stadiumcapacity ; dbo:ground ?countryOfTeam . 
   ?countryOfBirth a dbo:Country ; dbo:populationTotal ?population .
   ?countryOfTeam a dbo:Country .
FILTER (?countryOfTeam != ?countryOfBirth)
FILTER (?stadiumcapacity > 30000)
FILTER (?population > 10000000)
} order by ?soccerplayer

Try it in dbpedia

Localities in the Italian province of Prato with number of foreigners of Asian origin

answer fields
  • Locality
  • Asian_Foreigns_Number
datasets 
  • http://datiopen.istat.it/sparql/oracle
SPARQL query:
PREFIX ter: <http://datiopen.istat.it/odi/ontologia/territorio/> PREFIX cen: <http://datiopen.istat.it/odi/ontologia/censimento/> SELECT ?Localita ?Stranieri_orig_Asiatica WHERE { ?loc a ter:LOC . ?loc ter:haNome ?Localita . ?loc ter:provincia_di_LOC ?prov . ?loc ter:haIndicatoreCensimento ?o . ?o cen:provieneDa cen:Asia . ?o cen:haStranieriApolidiResidentiItalia ?Stranieri_orig_Asiatica. FILTER(?prov = <http://datiopen.istat.it/odi/risorsa/territorio/province/Prato>) }


Try it in istat endpoint