Download as pdf or txt
Download as pdf or txt
You are on page 1of 69

The SPARQL Query Language

CapGemini Tutorial

Martin Giese

24 April 2020

Martin Giese SPARQL, CapGemini 24 April 2020 1 / 17


SPARQL

▶ SPARQL Protocol And RDF Query Language

Martin Giese SPARQL, CapGemini 24 April 2020 2 / 17


SPARQL

▶ SPARQL Protocol And RDF Query Language


▶ Documentation:https://www.w3.org/TR/sparql11-overview/

Martin Giese SPARQL, CapGemini 24 April 2020 2 / 17


SPARQL

▶ SPARQL Protocol And RDF Query Language


▶ Documentation:https://www.w3.org/TR/sparql11-overview/
▶ Query Language

Martin Giese SPARQL, CapGemini 24 April 2020 2 / 17


SPARQL

▶ SPARQL Protocol And RDF Query Language


▶ Documentation:https://www.w3.org/TR/sparql11-overview/
▶ Query Language
▶ Update Language

Martin Giese SPARQL, CapGemini 24 April 2020 2 / 17


SPARQL

▶ SPARQL Protocol And RDF Query Language


▶ Documentation:https://www.w3.org/TR/sparql11-overview/
▶ Query Language
▶ Update Language
▶ Protocol to submit queries to a server (“endpoint”)

Martin Giese SPARQL, CapGemini 24 April 2020 2 / 17


SPARQL

▶ SPARQL Protocol And RDF Query Language


▶ Documentation:https://www.w3.org/TR/sparql11-overview/
▶ Query Language
▶ Update Language
▶ Protocol to submit queries to a server (“endpoint”)
▶ Formatting of query results

Martin Giese SPARQL, CapGemini 24 April 2020 2 / 17


SPARQL

▶ SPARQL Protocol And RDF Query Language


▶ Documentation:https://www.w3.org/TR/sparql11-overview/
▶ Query Language
▶ Update Language
▶ Protocol to submit queries to a server (“endpoint”)
▶ Formatting of query results
▶ …

Martin Giese SPARQL, CapGemini 24 April 2020 2 / 17


SPARQL

▶ SPARQL Protocol And RDF Query Language


▶ Documentation:https://www.w3.org/TR/sparql11-overview/
▶ Query Language
▶ Update Language
▶ Protocol to submit queries to a server (“endpoint”)
▶ Formatting of query results
▶ …
▶ Try it out:

Martin Giese SPARQL, CapGemini 24 April 2020 2 / 17


SPARQL

▶ SPARQL Protocol And RDF Query Language


▶ Documentation:https://www.w3.org/TR/sparql11-overview/
▶ Query Language
▶ Update Language
▶ Protocol to submit queries to a server (“endpoint”)
▶ Formatting of query results
▶ …
▶ Try it out:
https://www.w3.org/wiki/SparqlEndpoints

Martin Giese SPARQL, CapGemini 24 April 2020 2 / 17


SPARQL

▶ SPARQL Protocol And RDF Query Language


▶ Documentation:https://www.w3.org/TR/sparql11-overview/
▶ Query Language
▶ Update Language
▶ Protocol to submit queries to a server (“endpoint”)
▶ Formatting of query results
▶ …
▶ Try it out:
https://www.w3.org/wiki/SparqlEndpoints
DBpedia http://dbpedia.org/sparql

Martin Giese SPARQL, CapGemini 24 April 2020 2 / 17


SPARQL

▶ SPARQL Protocol And RDF Query Language


▶ Documentation:https://www.w3.org/TR/sparql11-overview/
▶ Query Language
▶ Update Language
▶ Protocol to submit queries to a server (“endpoint”)
▶ Formatting of query results
▶ …
▶ Try it out:
https://www.w3.org/wiki/SparqlEndpoints
DBpedia http://dbpedia.org/sparql
Wikidata https://query.wikidata.org/

Martin Giese SPARQL, CapGemini 24 April 2020 2 / 17


SPARQL

▶ SPARQL Protocol And RDF Query Language


▶ Documentation:https://www.w3.org/TR/sparql11-overview/
▶ Query Language
▶ Update Language
▶ Protocol to submit queries to a server (“endpoint”)
▶ Formatting of query results
▶ …
▶ Try it out:
https://www.w3.org/wiki/SparqlEndpoints
DBpedia http://dbpedia.org/sparql
Wikidata https://query.wikidata.org/
Musicbrainz http://dbtune.org/musicbrainz/snorql/

Martin Giese SPARQL, CapGemini 24 April 2020 2 / 17


SPARQL

▶ SPARQL Protocol And RDF Query Language


▶ Documentation:https://www.w3.org/TR/sparql11-overview/
▶ Query Language
▶ Update Language
▶ Protocol to submit queries to a server (“endpoint”)
▶ Formatting of query results
▶ …
▶ Try it out:
https://www.w3.org/wiki/SparqlEndpoints
DBpedia http://dbpedia.org/sparql
Wikidata https://query.wikidata.org/
Musicbrainz http://dbtune.org/musicbrainz/snorql/
World DB http://sws.ifi.uio.no/d2rq/snorql/

Martin Giese SPARQL, CapGemini 24 April 2020 2 / 17


Simple Examples

▶ DBpedia has information about actors, movies, etc. https://dbpedia.org/


▶ Web interface for SPARQL writing: http://dbpedia.org/sparql

Martin Giese SPARQL, CapGemini 24 April 2020 3 / 17


Simple Examples

▶ DBpedia has information about actors, movies, etc. https://dbpedia.org/


▶ Web interface for SPARQL writing: http://dbpedia.org/sparql

People called “Johnny Depp”


PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?jd WHERE {
?jd foaf:name "Johnny Depp"@en .
}

Martin Giese SPARQL, CapGemini 24 April 2020 3 / 17


Simple Examples

▶ DBpedia has information about actors, movies, etc. https://dbpedia.org/


▶ Web interface for SPARQL writing: http://dbpedia.org/sparql

People called “Johnny Depp”


PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?jd WHERE {
?jd foaf:name "Johnny Depp"@en .
}
Answer:
?jd
<http://dbpedia.org/resource/Johnny_Depp>

Martin Giese SPARQL, CapGemini 24 April 2020 3 / 17


Simple Examples (cont.)

Films starring people called “Johnny Depp”


PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT ?m WHERE {
?jd foaf:name "Johnny Depp"@en .
?m dbo:starring ?jd .
}

Martin Giese SPARQL, CapGemini 24 April 2020 4 / 17


Simple Examples (cont.)

Films starring people called “Johnny Depp”


PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dbo: <http://dbpedia.org/ontology/>
SELECT ?m WHERE {
?jd foaf:name "Johnny Depp"@en .
?m dbo:starring ?jd .
}

Answer:
?m
<http://dbpedia.org/resource/Dead_Man>
<http://dbpedia.org/resource/Edward_Scissorhands>
<http://dbpedia.org/resource/Arizona_Dream>

Martin Giese SPARQL, CapGemini 24 April 2020 4 / 17


Simple Examples (cont.)

Titles of films by people called “Johnny Depp”


SELECT ?title WHERE {
?jd foaf:name "Johnny Depp"@en .
?m dbo:starring ?jd .
?m rdfs:label ?title .
}

Martin Giese SPARQL, CapGemini 24 April 2020 5 / 17


Simple Examples (cont.)

Titles of films by people called “Johnny Depp”


SELECT ?title WHERE {
?jd foaf:name "Johnny Depp"@en .
?m dbo:starring ?jd .
?m rdfs:label ?title .
}
Answer:
?title
"Truposz"@pl
"Dead Man"@en
"El sueño de Arizona"@es
"Arizona Dream"@en

Martin Giese SPARQL, CapGemini 24 April 2020 5 / 17
Simple Examples (cont.)
Names of people who co-starred with “Johnny Depp”
SELECT DISTINCT ?collab WHERE {
?jd foaf:name "Johnny Depp"@en .
?m dbo:starring ?jd .
?m dbo:starring ?other .
?other foaf:name ?collab .
}

Martin Giese SPARQL, CapGemini 24 April 2020 6 / 17


Simple Examples (cont.)
Names of people who co-starred with “Johnny Depp”
SELECT DISTINCT ?collab WHERE {
?jd foaf:name "Johnny Depp"@en .
?m dbo:starring ?jd .
?m dbo:starring ?other .
?other foaf:name ?collab .
}
Answer:
?collab
"Al Pacino"@en
"Antonio Banderas"@en
"Johnny Depp"@en
"Marlon Brando"@en

Martin Giese SPARQL, CapGemini 24 April 2020 6 / 17
Graph Patterns

The previous SPARQL query as a graph:

foaf:name
?jd "Johnny Depp"@en
ng
ta rri
dbo:s

?m dbo
:st
arr
ing

foaf:name
?other ?collab

Martin Giese SPARQL, CapGemini 24 April 2020 7 / 17


Graph Patterns

The previous SPARQL query as a graph:

foaf:name
?jd "Johnny Depp"@en
ng
ta rri
dbo:s

?m dbo
:st
arr
ing

foaf:name
?other ?collab

Pattern matching: assign values to variables to make this a sub-graph of the RDF graph!

Martin Giese SPARQL, CapGemini 24 April 2020 7 / 17


Graph with blank nodes

Variables not SELECTed can equivalently be blank:

foaf:name
"Johnny Depp"@en
ring
star
dbo:

dbo:
s tarr
i ng
foaf:name
?collab

Martin Giese SPARQL, CapGemini 24 April 2020 8 / 17


Graph with blank nodes

Variables not SELECTed can equivalently be blank:

foaf:name
"Johnny Depp"@en
ring
star
dbo:

dbo:
s tarr
i ng
foaf:name
?collab

Pattern matching: assign values to variables and blank nodes to make this a sub-graph of the
RDF graph!

Martin Giese SPARQL, CapGemini 24 April 2020 8 / 17


SPARQL Query with blank nodes
Names of people who co-starred with “Johnny Depp”
SELECT DISTINCT ?collab WHERE {
_:jd foaf:name "Johnny Depp"@en .
_:m dbo:starring _:jd .
_:m dbo:starring _:other .
_:other foaf:name ?collab .
}

Martin Giese SPARQL, CapGemini 24 April 2020 9 / 17


SPARQL Query with blank nodes
Names of people who co-starred with “Johnny Depp”
SELECT DISTINCT ?collab WHERE {
_:jd foaf:name "Johnny Depp"@en .
_:m dbo:starring _:jd .
_:m dbo:starring _:other .
_:other foaf:name ?collab .
}

The same with blank node syntax


SELECT DISTINCT ?collab WHERE {
_:m dbo:starring [foaf:name "Johnny Depp"@en] .
_:m dbo:starring _:other .
_:other foaf:name ?collab.
}
Martin Giese SPARQL, CapGemini 24 April 2020 9 / 17
SPARQL Query with blank nodes
Names of people who co-starred with “Johnny Depp”
SELECT DISTINCT ?collab WHERE {
_:jd foaf:name "Johnny Depp"@en .
_:m dbo:starring _:jd .
_:m dbo:starring _:other .
_:other foaf:name ?collab .
}

The same with blank node syntax


SELECT DISTINCT ?collab WHERE {
_:m dbo:starring [foaf:name "Johnny Depp"@en] .
_:m dbo:starring [foaf:name ?collab] .
}

Martin Giese SPARQL, CapGemini 24 April 2020 9 / 17


SPARQL Query with blank nodes
Names of people who co-starred with “Johnny Depp”
SELECT DISTINCT ?collab WHERE {
_:jd foaf:name "Johnny Depp"@en .
_:m dbo:starring _:jd .
_:m dbo:starring _:other .
_:other foaf:name ?collab .
}

The same with blank node syntax


SELECT DISTINCT ?collab WHERE {
[ dbo:starring [foaf:name "Johnny Depp"@en] ;
dbo:starring [foaf:name ?collab]
]
}
Martin Giese SPARQL, CapGemini 24 April 2020 9 / 17
SPARQL Query with blank nodes
Names of people who co-starred with “Johnny Depp”
SELECT DISTINCT ?collab WHERE {
_:jd foaf:name "Johnny Depp"@en .
_:m dbo:starring _:jd .
_:m dbo:starring _:other .
_:other foaf:name ?collab .
}

The same with blank node syntax


SELECT DISTINCT ?collab WHERE {
[ dbo:starring [foaf:name "Johnny Depp"@en] ,
[foaf:name ?collab]
]
}
Martin Giese SPARQL, CapGemini 24 April 2020 9 / 17
Filters

▶ Groups may include constraints or filters


▶ Reduces matches of surrounding group where filter applies
▶ E.g.
{
?x a dbo:Place ;
dbp:population ?pop .
FILTER (?pop > 1000000)
}

Martin Giese SPARQL, CapGemini 24 April 2020 10 / 17


Filters

▶ Groups may include constraints or filters


▶ Reduces matches of surrounding group where filter applies
▶ E.g.
{
?x a dbo:Place ;
dbp:population ?pop .
FILTER (?pop > 1000000)
}
▶ E.g.
{
?x a dbo:Document ;
dbp:abstract ?abs .
FILTER (lang(?abs) = no")
}

Martin Giese SPARQL, CapGemini 24 April 2020 10 / 17


Optional Patterns
▶ Allows a match to leave some variables unbound (e.g. no data was available)
▶ A match is a partial function from variables to RDF terms

Martin Giese SPARQL, CapGemini 24 April 2020 11 / 17


Optional Patterns
▶ Allows a match to leave some variables unbound (e.g. no data was available)
▶ A match is a partial function from variables to RDF terms
▶ Groups may include optional parts
▶ E.g.
{
?x a dbo:Document ;
dbp:date ?date .
OPTIONAL {
?x dbp:abstract ?abs .
FILTER (lang(?abs) = no")
}
}

Martin Giese SPARQL, CapGemini 24 April 2020 11 / 17


Optional Patterns
▶ Allows a match to leave some variables unbound (e.g. no data was available)
▶ A match is a partial function from variables to RDF terms
▶ Groups may include optional parts
▶ E.g.
{
?x a dbo:Document ;
dbp:date ?date .
OPTIONAL {
?x dbp:abstract ?abs .
FILTER (lang(?abs) = no")
}
}
▶ ?x and ?date bound in every match, ?abs bound if there is a Norwegian abstract
▶ Groups can contain several optional parts, evaluated separately
Martin Giese SPARQL, CapGemini 24 April 2020 11 / 17
Matching Alternatives

▶ A UNION pattern matches if any of some alternatives matches

Martin Giese SPARQL, CapGemini 24 April 2020 12 / 17


Matching Alternatives

▶ A UNION pattern matches if any of some alternatives matches


▶ E.g.
{
{ ?book dc:creator ?author ;
dc:created ?date . }
UNION
{ ?book foaf:maker ?author . }
UNION
{ ?author foaf:made ?book . }
}

Martin Giese SPARQL, CapGemini 24 April 2020 12 / 17


Matching Alternatives

▶ A UNION pattern matches if any of some alternatives matches


▶ E.g.
{
{ ?book dc:creator ?author ;
dc:created ?date . }
UNION
{ ?book foaf:maker ?author . }
UNION
{ ?author foaf:made ?book . }
}
▶ Variables in matches union of variables in sub-patterns

Martin Giese SPARQL, CapGemini 24 April 2020 12 / 17


Matching Alternatives

▶ A UNION pattern matches if any of some alternatives matches


▶ E.g.
{
{ ?book dc:creator ?author ;
dc:created ?date . }
UNION
{ ?book foaf:maker ?author . }
UNION
{ ?author foaf:made ?book . }
}
▶ Variables in matches union of variables in sub-patterns
▶ Match of one pattern leaves rest of variables unbound

Martin Giese SPARQL, CapGemini 24 April 2020 12 / 17


Four Types of Queries

SELECT Compute table of bindings for variables


SELECT ?a ?b WHERE {
[ dc:creator ?a ;
dc:creator ?b ]
}

Martin Giese SPARQL, CapGemini 24 April 2020 13 / 17


Four Types of Queries

SELECT Compute table of bindings for variables


SELECT ?a ?b WHERE {
[ dc:creator ?a ;
dc:creator ?b ]
}
CONSTRUCT Use bindings to construct a new RDF graph
CONSTRUCT {
?a foaf:knows ?b .
} WHERE {
[ dc:creator ?a ;
dc:creator ?b ]
}

Martin Giese SPARQL, CapGemini 24 April 2020 13 / 17


Four Types of Queries

SELECT Compute table of bindings for variables


SELECT ?a ?b WHERE {
[ dc:creator ?a ;
dc:creator ?b ]
}
CONSTRUCT Use bindings to construct a new RDF graph
CONSTRUCT {
?a foaf:knows ?b .
} WHERE {
[ dc:creator ?a ;
dc:creator ?b ]
}
ASK Answer (yes/no) whether there is ≥ 1 match

Martin Giese SPARQL, CapGemini 24 April 2020 13 / 17


Four Types of Queries

SELECT Compute table of bindings for variables


SELECT ?a ?b WHERE {
[ dc:creator ?a ;
dc:creator ?b ]
}
CONSTRUCT Use bindings to construct a new RDF graph
CONSTRUCT {
?a foaf:knows ?b .
} WHERE {
[ dc:creator ?a ;
dc:creator ?b ]
}
ASK Answer (yes/no) whether there is ≥ 1 match
DESCRIBE Answer available information about matching resources

Martin Giese SPARQL, CapGemini 24 April 2020 13 / 17


Solution Modifiers

▶ Patterns generate an unordered collection of solutions

Martin Giese SPARQL, CapGemini 24 April 2020 14 / 17


Solution Modifiers

▶ Patterns generate an unordered collection of solutions


▶ Each solution is a partial function from variables to RDF terms

Martin Giese SPARQL, CapGemini 24 April 2020 14 / 17


Solution Modifiers

▶ Patterns generate an unordered collection of solutions


▶ Each solution is a partial function from variables to RDF terms
▶ SELECT treats solutions as a sequence (solution sequence)

Martin Giese SPARQL, CapGemini 24 April 2020 14 / 17


Solution Modifiers

▶ Patterns generate an unordered collection of solutions


▶ Each solution is a partial function from variables to RDF terms
▶ SELECT treats solutions as a sequence (solution sequence)
▶ Sequence modifiers can modify the solution sequence:

Martin Giese SPARQL, CapGemini 24 April 2020 14 / 17


Solution Modifiers

▶ Patterns generate an unordered collection of solutions


▶ Each solution is a partial function from variables to RDF terms
▶ SELECT treats solutions as a sequence (solution sequence)
▶ Sequence modifiers can modify the solution sequence:
▶ Order: …ORDER BY ?country DESC(?pop)

Martin Giese SPARQL, CapGemini 24 April 2020 14 / 17


Solution Modifiers

▶ Patterns generate an unordered collection of solutions


▶ Each solution is a partial function from variables to RDF terms
▶ SELECT treats solutions as a sequence (solution sequence)
▶ Sequence modifiers can modify the solution sequence:
▶ Order: …ORDER BY ?country DESC(?pop)
▶ Projection: SELECT ?x ?y WHERE…

Martin Giese SPARQL, CapGemini 24 April 2020 14 / 17


Solution Modifiers

▶ Patterns generate an unordered collection of solutions


▶ Each solution is a partial function from variables to RDF terms
▶ SELECT treats solutions as a sequence (solution sequence)
▶ Sequence modifiers can modify the solution sequence:
▶ Order: …ORDER BY ?country DESC(?pop)
▶ Projection: SELECT ?x ?y WHERE…
▶ Distinct: SELECT DISTINCT ?x WHERE…

Martin Giese SPARQL, CapGemini 24 April 2020 14 / 17


Solution Modifiers

▶ Patterns generate an unordered collection of solutions


▶ Each solution is a partial function from variables to RDF terms
▶ SELECT treats solutions as a sequence (solution sequence)
▶ Sequence modifiers can modify the solution sequence:
▶ Order: …ORDER BY ?country DESC(?pop)
▶ Projection: SELECT ?x ?y WHERE…
▶ Distinct: SELECT DISTINCT ?x WHERE…
▶ Reduce: SELECT REDUCE ?x WHERE…

Martin Giese SPARQL, CapGemini 24 April 2020 14 / 17


Solution Modifiers

▶ Patterns generate an unordered collection of solutions


▶ Each solution is a partial function from variables to RDF terms
▶ SELECT treats solutions as a sequence (solution sequence)
▶ Sequence modifiers can modify the solution sequence:
▶ Order: …ORDER BY ?country DESC(?pop)
▶ Projection: SELECT ?x ?y WHERE…
▶ Distinct: SELECT DISTINCT ?x WHERE…
▶ Reduce: SELECT REDUCE ?x WHERE…
▶ Sub-sequence: …LIMIT 10 OFFSET 50

Martin Giese SPARQL, CapGemini 24 April 2020 14 / 17


Solution Modifiers

▶ Patterns generate an unordered collection of solutions


▶ Each solution is a partial function from variables to RDF terms
▶ SELECT treats solutions as a sequence (solution sequence)
▶ Sequence modifiers can modify the solution sequence:
▶ Order: …ORDER BY ?country DESC(?pop)
▶ Projection: SELECT ?x ?y WHERE…
▶ Distinct: SELECT DISTINCT ?x WHERE…
▶ Reduce: SELECT REDUCE ?x WHERE…
▶ Sub-sequence: …LIMIT 10 OFFSET 50
▶ Applied in this order.

Martin Giese SPARQL, CapGemini 24 April 2020 14 / 17


Some other features in SPARQL

Not discussed today:


▶ aggregate functions (count, sum, average,…)

Martin Giese SPARQL, CapGemini 24 April 2020 15 / 17


Some other features in SPARQL

Not discussed today:


▶ aggregate functions (count, sum, average,…)
▶ negation, set difference

Martin Giese SPARQL, CapGemini 24 April 2020 15 / 17


Some other features in SPARQL

Not discussed today:


▶ aggregate functions (count, sum, average,…)
▶ negation, set difference
▶ nested sub-queries

Martin Giese SPARQL, CapGemini 24 April 2020 15 / 17


Some other features in SPARQL

Not discussed today:


▶ aggregate functions (count, sum, average,…)
▶ negation, set difference
▶ nested sub-queries
▶ federation: execute parts of queries on remote endpoints

Martin Giese SPARQL, CapGemini 24 April 2020 15 / 17


Some other features in SPARQL

Not discussed today:


▶ aggregate functions (count, sum, average,…)
▶ negation, set difference
▶ nested sub-queries
▶ federation: execute parts of queries on remote endpoints
▶ updates (add delete triples)

Martin Giese SPARQL, CapGemini 24 April 2020 15 / 17


Some other features in SPARQL

Not discussed today:


▶ aggregate functions (count, sum, average,…)
▶ negation, set difference
▶ nested sub-queries
▶ federation: execute parts of queries on remote endpoints
▶ updates (add delete triples)

Have a look at the SPARQL 1.1 docs…

https://www.w3.org/TR/sparql11-query/

Martin Giese SPARQL, CapGemini 24 April 2020 15 / 17


SPARQL on the 'Net

▶ Many sites (dbpedia, wikidata, dbtunes,…) publish SPARQL endpoints

Martin Giese SPARQL, CapGemini 24 April 2020 16 / 17


SPARQL on the 'Net

▶ Many sites (dbpedia, wikidata, dbtunes,…) publish SPARQL endpoints


▶ I.e. SPARQL queries can be submitted to a database server that sends back the results

Martin Giese SPARQL, CapGemini 24 April 2020 16 / 17


SPARQL on the 'Net

▶ Many sites (dbpedia, wikidata, dbtunes,…) publish SPARQL endpoints


▶ I.e. SPARQL queries can be submitted to a database server that sends back the results
▶ RESTful HTTP requests to submit URL-encoded queries to server
GET /sparql/?query=... HTTP/1.1

Martin Giese SPARQL, CapGemini 24 April 2020 16 / 17


SPARQL on the 'Net

▶ Many sites (dbpedia, wikidata, dbtunes,…) publish SPARQL endpoints


▶ I.e. SPARQL queries can be submitted to a database server that sends back the results
▶ RESTful HTTP requests to submit URL-encoded queries to server
GET /sparql/?query=... HTTP/1.1
▶ Server responds with an encoding of the result set, see
http://www.w3.org/TR/rdf-sparql-XMLres/

Martin Giese SPARQL, CapGemini 24 April 2020 16 / 17


SPARQL on the 'Net

▶ Many sites (dbpedia, wikidata, dbtunes,…) publish SPARQL endpoints


▶ I.e. SPARQL queries can be submitted to a database server that sends back the results
▶ RESTful HTTP requests to submit URL-encoded queries to server
GET /sparql/?query=... HTTP/1.1
▶ Server responds with an encoding of the result set, see
http://www.w3.org/TR/rdf-sparql-XMLres/
▶ Nothing you would want to do manually!

Martin Giese SPARQL, CapGemini 24 April 2020 16 / 17


SPARQL on the 'Net

▶ Many sites (dbpedia, wikidata, dbtunes,…) publish SPARQL endpoints


▶ I.e. SPARQL queries can be submitted to a database server that sends back the results
▶ RESTful HTTP requests to submit URL-encoded queries to server
GET /sparql/?query=... HTTP/1.1
▶ Server responds with an encoding of the result set, see
http://www.w3.org/TR/rdf-sparql-XMLres/
▶ Nothing you would want to do manually!
▶ Mostly, there is a web page for manual entry of queries

Martin Giese SPARQL, CapGemini 24 April 2020 16 / 17


SPARQL on the 'Net

▶ Many sites (dbpedia, wikidata, dbtunes,…) publish SPARQL endpoints


▶ I.e. SPARQL queries can be submitted to a database server that sends back the results
▶ RESTful HTTP requests to submit URL-encoded queries to server
GET /sparql/?query=... HTTP/1.1
▶ Server responds with an encoding of the result set, see
http://www.w3.org/TR/rdf-sparql-XMLres/
▶ Nothing you would want to do manually!
▶ Mostly, there is a web page for manual entry of queries
▶ RDF APIs like Jena or RDF4J can send queries to endpoints

Martin Giese SPARQL, CapGemini 24 April 2020 16 / 17


Exercise: SPARQL

▶ Write SPARQL queries.


▶ Two possibilities:
▶ Run queries on SPARQL endpoint at http://sws.ifi.uio.no/d2rq/snorql/.
▶ Host your own triples with Fuseki
▶ Many queries, choose according to your skills.

Martin Giese SPARQL, CapGemini 24 April 2020 17 / 17

You might also like