SPARQL: introduction Semantic Web and Linked Data Module 3 Lesson 1 Dr. Idafen Santana Pérez
[email protected] Ontology Engineering Group
Querying over RDF. The Basics Application
Application
SQL queries
SPARQL queries RDF(S) OWL
Relational database
SPARQL
2
Querying over RDF. The Basics Application
Application
SQL queries
SPARQL queries RDF(S) OWL
Relational database
• Supported by the most relevant APIs and triple stores – Jena, Sesame, etc. – Virtuoso, Stardog, 4store, Fuseki, etc.
SPARQL
3
Querying over RDF. Examples (I) • Sample RDF graph person:hasColleague
person:hasColleague data:Asun
data:Oscar
person:hasHomePage
person:hasName “Óscar Corcho García”
data:Raul
http://www.oeg-upm .net/
• Query: “Tell me the persons that have Raúl as a colleague”
– Result: data:Asun
SPARQL
4
Querying over RDF. Examples (I) • Sample RDF graph person:hasColleague
person:hasColleague data:Asun
data:Oscar
person:hasHomePage
person:hasName “Óscar Corcho García”
data:Raul
http://www.oeg-upm .net/
• Query: “Tell me the persons that have Raúl as a colleague” person:hasColleague ?
data:Raul
– Result: data:Asun
SPARQL
5
Querying over RDF. Examples • Sample RDF graph person:hasColleague
person:hasColleague data:Asun
data:Oscar
person:hasHomePage
person:hasName “Óscar Corcho García”
data:Raul
http://www.oeg-upm .net/
• Query: “Tell me which relationships exist between Oscar and Asun” ?
data:Oscar
– Result: person:hasColleague
SPARQL
6
data:Asun
Querying over RDF. Examples • Sample RDF graph person:hasColleague
person:hasColleague data:Asun
data:Oscar
person:hasHomePage
person:hasName “Óscar Corcho García”
data:Raul
http://www.oeg-upm .net/
• Query: “Tell me the Web page of Oscar’s colleagues” data:Oscar
person:hasColleague person:hasHomePage
– Result: “http://www.oeg-upm.net/” SPARQL
7
?
Querying over RDF. SPARQL examples
• Find names and websites of PlanetRDF collaborators: PREFIX foaf:
SELECT ?name ?website FROM
WHERE { ?person foaf:weblog ?website . ?person foaf:name ?name . ?website a foaf:Document }
SPARQL
8
Querying over RDF. SPARQL examples
• Find names and websites of PlanetRDF collaborators: PREFIX foaf: SELECT ?name ?website FROM WHERE { ?person foaf:weblog ?website . ?person foaf:name ?name . ?website a foaf:Document }
SPARQL
9
Querying over RDF. SPARQL examples
• Find names and websites of PlanetRDF collaborators: PREFIX foaf: SELECT ?name ?website FROM WHERE { ?person foaf:weblog ?website . ?person foaf:name ?name . ?website a foaf:Document }
SPARQL
10
Querying over RDF. SPARQL examples
• Find names and websites of PlanetRDF collaborators: PREFIX foaf: SELECT ?name ?website FROM WHERE { ?person foaf:weblog ?website . ?person foaf:name ?name . ?website a foaf:Document }
SPARQL
11
Querying over RDF. SPARQL examples
• Find names and websites of PlanetRDF collaborators: PREFIX foaf: SELECT ?name ?website FROM WHERE { ?person foaf:weblog ?website . ?person foaf:name ?name . ?website a foaf:Document }
SPARQL
12
Querying over RDF. SPARQL examples
• Find names and websites of PlanetRDF collaborators: PREFIX foaf: SELECT ?name ?website FROM WHERE { ?person foaf:weblog ?website . ?person foaf:name ?name . ?website a foaf:Document }
SPARQL
13
SPARQL is also a protocol • SPARQL is also a protocol
http://.../qps?query-lang=http://www.w3.org/TR/rdfsparql-query/ &graphid=http://planetrdf.com/bloggers.rdf&query=PREFIXfoaf :
• This comprises – – – –
SPARQL
Services evaluating SPARQL queries over an RDF dataset (a set of graphs) + a transport protocol to invoke the services + service description using Web services + several output formats
14
SPARQL endpoints • SPARQL protocol service – Implements the SPARQL Protocol for RDF (SPROT) specification
• Some SPARQL endpoint listings – http://esw.w3.org/topic/SparqlEndpoints – http://sparqles.okfn.org/
SPARQL
15
SPARQL endpoints • SPARQL protocol service – Implements the SPARQL Protocol for RDF (SPROT) specification
• Some SPARQL endpoint listings – http://esw.w3.org/topic/SparqlEndpoints – http://sparqles.okfn.org/
• Examples: Project
Endpoint
DBpedia
http://dbpedia.org/sparql
AragoDBpedia
http://opendata.aragon.es/sparql
Biblioteca Nacional
http://datos.bne.es/sparql
Bathing Water Quality UK
http://environment.data.gov.uk/lab/sparql.html
European Data Portal
http://www.europeandataportal.eu/sparql
SPARQL
16
SPARQL: introduction Idafen Santana Pérez Acknowledgements: Oscar Corcho and Raúl García
Querying over RDF. SPARQL examples (II) • ¿Which bullfighters have been married to “copla” singers? PREFIX dcterms: SELECT ?torero ?cantante WHERE{ ?torero rdf:type dbpedia-owl:BullFighter . ?torero dbpedia-owl:spouse ?cantante . ?cantante dcterms:subject }
http://es.dbpedia.org/sparql?default-graphuri=&query=PREFIX+dcterms:+%3Chttp://purl.org/dc/terms/%3ESELECT+?torero+?cantante+WHERE%7 B++?torero+rdf:type+dbpedia-owl:BullFighter+.++?torero+dbpediaowl:spouse+?cantante+.++?cantante+dcterms:subject+%3Chttp://es.dbpedia.org/resource/Categor%C3% ADa:Cantantes_de_coplas%3E%7D&should-sponge=&format=text/html&timeout=0&debug=on
SPARQL
18