The document provides examples of SPARQL queries that can be executed on the DBpedia SPARQL endpoint. It includes queries to retrieve information about people born in London, actors still alive, capital cities in the CET time zone, and universities established in English-speaking countries before the 20th century. Each query is accompanied by its respective SPARQL syntax and filtering criteria.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
32 views9 pages
SPARQL Examples
The document provides examples of SPARQL queries that can be executed on the DBpedia SPARQL endpoint. It includes queries to retrieve information about people born in London, actors still alive, capital cities in the CET time zone, and universities established in English-speaking countries before the 20th century. Each query is accompanied by its respective SPARQL syntax and filtering criteria.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9
SPARQL QUERY LANGUAGE
Examples of SPARQL queries
QUERY EXAMPLES OVER DBPEDIA SPARQL endpoint: http://dbpedia.org/sparql SPARQL editors: § http://yasgui.laurensrietveld.nl/ § http://dbpedia.org/snorql/ Query 1: Display names and dates of birth and death of all people born in London between 1900-1950; sort the results based on the birth date.
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbr: <http://dbpedia.org/resource/> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> SELECT DISTINCT ?name ?birth ?death WHERE { ?person dbo:birthPlace dbr:London . ?person dbo:birthDate ?birth . ?person rdfs:label ?name FILTER (lang(?name) = "en"). OPTIONAL { ?person dbo:deathDate ?death . } FILTER ((?birth > "1900-01-01"^^xsd:date) && (?birth < "1950-01-01"^^xsd:date)) . } ORDER BY (?birth) Query 2: Display names and dates of birth of all actors born in London after year 1930. who are still alive
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dbo: <http://dbpedia.org/ontology/> PREFIX dbr: <http://dbpedia.org/resource/> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> SELECT DISTINCT ?name ?birth WHERE { ?person dbo:birthPlace dbr:London . ?person dbo:occupation dbr:Actor . ?person foaf:name ?name . ?person dbo:birthDate ?birth FILTER (?birth > "1930-01-01"^^xsd:date) . FILTER NOT EXISTS { ?person dbo:deathDate ?death. } } More comprehensive solution (takes into account cases where the occupation is given as a plain string): PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX dbo: <http://dbpedia.org/ontology/> PREFIX dbp: <http://dbpedia.org/property/> PREFIX dbr: <http://dbpedia.org/resource/> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT DISTINCT ?name ?birth
WHERE { ?person dbo:birthPlace dbr:London . { ?person dbo:occupation dbr:Actor . } UNION {?person dbp:occupation ?occupation FILTER (contains(str(?occupation), "Actor") || contains(str(?occupation), "Actress")) } ?person foaf:name ?name . ?person dbo:birthDate ?birth FILTER (?birth > "1930-01-01"^^xsd:date) . FILTER NOT EXISTS { ?person dbo:deathDate ?death. } } Query 3: Display names of all capital cities that are in the CET time zone. Sort the results based on the size of the population of the capitals from the result set. PREFIX dbo: <http://dbpedia.org/ontology/> PREFIX dbp: <http://dbpedia.org/property/> PREFIX dbr: <http://dbpedia.org/resource/> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> This filter is to eliminate PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> the former capitals, that is, SELECT DISTINCT ?name capitals of the countries that ceased to exist WHERE { ?country rdf:type dbo:Country ; FILTER NOT EXISTS {{ ?country dbo:dissolutionDate ?endDate } UNION { ?country dbo:dissolutionYear ?endDate }} ?country dbo:capital ?city . ?city rdfs:label ?name FILTER ( lang(?name) = "en" ) {?city dbo:timeZone dbr:Central_European_Time . } UNION {?city dbp:timezone ?timezone FILTER (str(?timezone) = "CET") } ?city dbo:populationTotal ?population . } ORDER BY DESC (?population) Tasks
Write a SPARQL query that returns names of the universities
that were established in English speaking countries before the beginning of the 20th century. For each university, return also the name of the country it is located in, and if available, the number of students. Sort the results based on the date of the universities’ founding dates. • Use DBpedia SPARQL Endpoint PREFIX dbo: <http://dbpedia.org/ontology/> PREFIX dbp: <http://dbpedia.org/property/> PREFIX dbr: <http://dbpedia.org/resource/> PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> SELECT ?uniName ?cName ?students WHERE { ?uni rdf:type dbo:University ; foaf:name ?uniName FILTER (lang(?uniName)="en"). ?uni dbp:established ?creationDate ; dbo:country ?country . ?country dbo:language dbr:English_language ; foaf:name ?cName FILTER (lang(?cName)="en") . OPTIONAL { ?uni dbo:numberOfUndergraduateStudents ?students . } FILTER ( ?creationDate < "1900-01-01"^^xsd:date ) . } ORDER BY (?creationDate)