SlideShare a Scribd company logo
+

SPARQL 1.0

Mariano Rodriguez-Muro,
Free University of Bozen-Bolzano
+

Disclaimer


Most of the content of these slides is from:




An introduction to SPARQL and Queries over Linked Data.
Chapter 2 SPARQL. By Olaf Harting (CC Attribution Share Alike
3.0 License)

License


This work is licensed under a
Creative Commons Attribution-Share Alike 3.0 License
(http://creativecommons.org/licenses/by-sa/3.0/)
+

Reading material


Semantic Web Programming Part II, Chapter 6



Foundations of Semantic Web Technologies - Sections 7.1 to
7.1.8
+

SPARQL in General


A family of W3C recommendations



SPARQL Query




SPARQL Update




Declarative update language for RDF data

SPARQL Protocol




Declarative query language for RDF data

Communication between SPARQL processing services (a.k.a.
SPARQL endpoints) and clients

SPARQL Query Results XML Format


XML Format for serializing query results
+

Main idea of SPARQL queries


Pattern matching


Describe subgraphs of the queried RDF graph



Subgraphs that match your description contribute an answer



Mean: graph patterns (i.e. RDF graphs with variables)
+

Main idea of SPARQL queries

?v
dbpedia:Mount_Baker

dbpedia:Mount_Etna
+

Components of SPARQL Queries
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX umbel-sc: <http://umbel.org/umbel/sc/>
SELECT ?v
FROM <http://example.org/myGeoData>
WHERE {
?v rdf:type umbel-sc:Volcano .
}
ORDER BY ?name
+

Components of SPARQL Queries
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX umbel-sc: <http://umbel.org/umbel/sc/>
SELECT ?v
FROM <http://example.org/myGeoData>
WHERE {
?v rdf:type umbel-sc:Volcano .
}
ORDER BY ?name



Prologue


Prefix definitions for compact URIs (CURIEs)



Attention (difference w.r.t. Turtle): No period (“.”) character as
separator
+

Components of SPARQL Queries
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX umbel-sc: <http://umbel.org/umbel/sc/>
SELECT ?v
FROM <http://example.org/myGeoData>
WHERE {
?v rdf:type umbel-sc:Volcano .
}
ORDER BY ?name



Result form specification


SELECT, DESCRIBE, CONSTRUCT or ASK
(more later)
+

Components of SPARQL Queries
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX umbel-sc: <http://umbel.org/umbel/sc/>
SELECT ?v
FROM <http://example.org/myGeoData>
WHERE {
?v rdf:type umbel-sc:Volcano .
}
ORDER BY ?name



Dataset specification


Specify the RDF dataset to be queries
(more on that later)
+

Components of SPARQL Queries
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX umbel-sc: <http://umbel.org/umbel/sc/>
SELECT ?v
FROM <http://example.org/myGeoData>
WHERE {
?v rdf:type umbel-sc:Volcano .
}
ORDER BY ?name



Query pattern


WHERE clause specifies the graph pattern to be matched
+

Components of SPARQL Queries
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX umbel-sc: <http://umbel.org/umbel/sc/>
SELECT ?v
FROM <http://example.org/myGeoData>
WHERE {
?v rdf:type umbel-sc:Volcano .
}
ORDER BY ?name



Solution modifiers


ORDER BY, LIMIT, OFFSET
(more about that later)



Only available in some of the result forms
+

Graph patterns


Different types of graph patterns for the query pattern (WHERE
clause):


Basic graph pattern (BGP)



Group graph pattern



Optional graph pattern



Union graph pattern



Graph graph pattern



(Constraints)
+

Basic Graph Patterns


Set of triple patterns in Turtle syntax (i.e., RDF triples with
variables)



Variable names prefixed with “?” or “$”

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX umbel-sc: <http://umbel.org/umbel/sc/>
SELECT ?name
WHERE {
?v rdf:type umbel-sc:Volcano .
?v rdfs:label ?name
}
+

Basic Graph Patterns


Set of triple patterns in Turtle syntax (i.e., RDF triples with
variables)



Variable names prefixed with “?” or “$”

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX umbel-sc: <http://umbel.org/umbel/sc/>
SELECT ?name
WHERE {
?v rdf:type umbel-sc:Volcano ;
rdfs:label ?name
}
+

Example
dbpedia:Mount_Etna
dbpedia:Mount_Baker
dbpedia:Beerenberg



rdf:type umbel-sc:Volcano ;
rdfs:label "Etna" .
rdf:type umbel-sc:Volcano.
rdf:type umbel-sc:Volcano,
umbel-sc:NaturalElevation ;
rdfs:label "Beerenberg"@en ;
rdfs:label "Беренберг"@ru .

What are the names of all (known) volcanos?
SELECT ?name WHERE {
?v rdf:type umbel-sc:Volcano ;
rdfs:label ?name
}

?name
“Etna”
"Беренберг"@ru
"Beerenberg"@en
+

Example
dbpedia:Mount_Etna
dbpedia:Mount_Baker
dbpedia:Beerenberg



rdf:type umbel-sc:Volcano ;
rdfs:label "Etna" .
rdf:type umbel-sc:Volcano.
rdf:type umbel-sc:Volcano,
umbel-sc:NaturalElevation ;
rdfs:label "Beerenberg"@en ;
rdfs:label "Беренберг"@ru .

List all types of the volcano called “Beerenberg”
SELECT ?type WHERE {
?v rdf:type ?type ;
rdfs:label “Beerenberg”
}

?type
+

Example
dbpedia:Mount_Etna
dbpedia:Mount_Baker
dbpedia:Beerenberg



rdf:type umbel-sc:Volcano ;
rdfs:label "Etna" .
rdf:type umbel-sc:Volcano.
rdf:type umbel-sc:Volcano,
umbel-sc:NaturalElevation ;
rdfs:label "Beerenberg"@en ;
rdfs:label "Беренберг"@ru .

List all types of the volcano called “Beerenberg”
SELECT ?type WHERE {
?v rdf:type ?type ;
rdfs:label “Beerenberg”@en
}

?type
umbel-sc:Volcano
umbel-sc:NaturalElevation
+

Example
dbpedia:Mount_Baker
dbpedia:United_States

rdf:type
p:location
rdfs:label

umbel-sc:Volcano;
dbpedia:United_States.
“United States”



Where are all (known) volcanos located? (List the names of
these locations)



Blank nodes in SPARQL queries


As subject or object of triple patterns



Non-selectable variables

SELECT ?name WHERE {
_:x
rdf:type umbel-sc:Volcano ;
p:location [ rdfs:label ?name ] .
}

?name

“United States”
+

Example
dbpedia:Mount_ Baker rdf:type umbel-sc:Volcano ;
p:location [ rdfs:label
"United States"@en ,
" tats-Unis"@fr ] .
dbpedia:Mount_ Etna rdf:type umbel-sc:Volcano ;
p:location [ rdfs:label "Italy" ] .

"Italy"


Blank nodes in the queried data


Blank node identifiers may appear in the results

SELECT ?l ?name WHERE {
?v rdf:type umbel-sc:Volcano ;
p:location ?l .
?l rdfs:label ?name .
}

?l

?name

_:n0

“United States”@en

_:n0

" tats-Unis"@fr

_:n1

"Italy"
+

Optional Graph Patterns
dbpedia:Mount_Etna
dbpedia:Mount_Baker
dbpedia:Beerenberg



rdf:type umbel-sc:Volcano ;
rdfs:label "Etna" .
rdf:type umbel-sc:Volcano.
rdf:type umbel-sc:Volcano,
umbel-sc:NaturalElevation ;
rdfs:label "Beerenberg"@en .

What are all volcanos and their names?

SELECT ?v ?name WHERE {
?v rdf:type umbel-sc:Volcano ;
rdfs:label ?name
}


?v

?name

dbpedia:Mount_Etna

“Etna”

dbpedia:Beerenber

"Beerenberg"@en

Problem: Missing Mount Baker (it has no name)
+

Optional Graph Patterns

SELECT ?v ?name WHERE {
?v rdf:type umbel-sc:Volcano .
OPTIONAL { ?v rdfs:label ?name }
}
?v

?name

dbpedia:Mount_Etna

“Etna”

dbpedia:Mount_Baker
dbpedia:Beerenber



Optional patterns may result in unbound variables

"Beerenberg"@en
+

Union Graph Patterns
dbpedia:Mount_Etna

dbpedia:Mount_Baker
dbpedia:Beerenberg



rdf:type umbel-sc:Volcano ;
rdfs:label "Etna” ;
p:location dbpedia:Italy .
rdf:type umbel-sc:Volcano ;
p:location dbpedia:United_States.
rdf:type umbel-sc:Volcano,
rdfs:label "Beerenberg"@en ;
p:location dbpedia:Norway .

List all volcanos located in Italy or Norway
SELECT ?v WHERE {
?v rdf:type umbel-sc:Volcano;
p:location ???????
}
+

Union Graph Patterns
SELECT ?v WHERE {
?v rdf:type umbel-sc:Volcano.
{ ?v p:location dbpedia:Italy }
UNION
{ ?v p:location dbpedia:Norway }
}

semantically
equivalent

SELECT ?v WHERE {
{ ?v rdf:type umbel-sc:Volcano; p:location dbpedia:Italy }
UNION
{?v rdf:type umbel-sc:Volcano; p:location dbpedia:Norway. }
}
+

Union Graph Patterns
SELECT ?v WHERE {
?v rdf:type umbel-sc:Volcano.
{ ?v p:location dbpedia:Italy }
UNION
{ ?v p:location dbpedia:Norway }
}

SELECT ?v WHERE {
{ ?v rdf:type umbel-sc:Volcano. } {
{ ?v p:location dbpedia:Italy }
UNION
{ ?v p:location dbpedia:Norway }
}
}

semantically
equivalent
+

Constraints on Solutions


Syntax: Keyword FILTER followed by a filter expression
SELECT ?v WHERE {
?v
rdf:type umbel-sc:Volcano ;
p:lastEruption ?le
FILTER ( ?le > 1900 )
}



Filter expressions are formed by operators and functions



Operators and functions operate on RDF terms
+

Constraints (Truth Table)


Filter expressions evaluate to true, false or error



Truth table:

A

B

A || B

A && B

T

T

T

T

T

F

T

F

F

T

T

F

F

F

F

F

T

E

T

E

E

T

T

E

F

E

E

F

E

F

E

F

E

E

E

E
+

Unary Operators in Constraints
Operator

Type(A)

Result type

!A

xsd:boolean

xsd:boolean

+A

numeric

numeric

-A

numeric

numeric

BOUND(A)

variable

xsd:boolean

isURI(A)

RDF term

xsd:boolean

isBLANK(A)

RDF term

xsd:boolean

isLITERAL(A)

RDF term

xsd:boolean

STR(A)

literal / URI

simple literal

LANG(A)

literal

simple literal

DATATYPE(A)

literal

simple literal
+

Example
dbpedia:Mount_Etna
dbpedia:Mount_Baker
dbpedia:Beerenberg



rdf:type umbel-sc:Volcano ;
rdfs:label "Etna" .
rdf:type umbel-sc:Volcano.
rdf:type umbel-sc:Volcano,
umbel-sc:NaturalElevation ;
rdfs:label "Beerenberg"@en ;
rdfs:label "Беренберг"@ru .

List all types of the volcano called “Beerenberg”
SELECT ?type WHERE {
?v rdf:type ?type ;
rdfs:label “Beerenberg”
}

?type
+

Example
dbpedia:Mount_Etna
dbpedia:Mount_Baker
dbpedia:Beerenberg



rdf:type umbel-sc:Volcano ;
rdfs:label "Etna" .
rdf:type umbel-sc:Volcano.
rdf:type umbel-sc:Volcano,
umbel-sc:NaturalElevation ;
rdfs:label "Beerenberg"@en ;
rdfs:label "Беренберг"@ru .

List all types of the volcano called “Beerenberg”
SELECT ?type WHERE {
?v rdf:type ?type ;
rdfs:label ?name .
FILTER( STR(?name) = “Beerenberg)
}

?type
umbel-sc:Volcano
umbel-sc:NaturalElevation
+

Constraints (Further operators)


Binary operators:



Comparison operators =, !=, <, >, <=, and >= for numeric datatypes,
xsd:dateTime, xsd:string, and xsd:boolean



Comparison operators = and != for other datatypes





Logical connectives && and || for xsd:boolean

Arithmetic operators +, -, *, and / for numeric datatypes

Furthermore:


REGEX(String,Pattern) or REGEX(String,Pattern,Flags)



sameTERM(A,B)



langMATCHES(A,B)
+

Example
dbpedia:Mount_Etna
dbpedia:Mount_Baker
dbpedia:Beerenberg



rdf:type umbel-sc:Volcano ;
rdfs:label "Etna" .
rdf:type umbel-sc:Volcano.
rdf:type umbel-sc:Volcano,
umbel-sc:NaturalElevation ;
rdfs:label "Beerenberg"@en ;
rdfs:label "Беренберг"@ru .

List all types of the volcano with “e” in their name
SELECT ?v WHERE {
?v rdf:type umbel-sc:Volcano ;
rdfs:label ?name .
FILTER( REGEX(STR(?name), „e”) )
}

?v
dbpedia:Beerenberg
dbpedia:Beerenberg
+

Example
dbpedia:Mount_Etna
dbpedia:Mount_Baker
dbpedia:Beerenberg



rdf:type umbel-sc:Volcano ;
rdfs:label "Etna" .
rdf:type umbel-sc:Volcano.
rdf:type umbel-sc:Volcano,
umbel-sc:NaturalElevation ;
rdfs:label "Beerenberg"@en ;
rdfs:label "Беренберг"@ru .

List all types of the volcano with “e” in their name (case
insensitive)
SELECT ?v WHERE {
?v rdf:type umbel-sc:Volcano ;
rdfs:label ?name .
FILTER( REGEX(STR(?name), “e”,”i”) )
}

?v
dbpedia:Mount_Etna
dbpedia:Beerenberg
dbpedia:Beerenberg
+

Graph Graph Patterns
Default graph
dbpedia:Mount_Etna
dbpedia:Mount_Baker

rdfs:seeAlso <http://example.org/d1>
rdfs:seeAlso <http://example.org/d2>
http://example.org/d1

dbpedia:Mount_Etna

rdf:type umbel-sc:Volcano ;
rdfs:label "Etna" .
http://example.org/d2

dbpedia:Mount_Baker

rdf:type umbel-sc:Volcano.
http://example.org/d3

dbpedia:Beerenberg


rdf:type umbel-sc:Volcano ;
rdfs:label "Beerenberg"@en ;

SPARQL queries are executed over an RDF dataset:


One default graph and



Zero or more named graphs (identified by an URI)
+

Graphs in RDF


Currently no official specification of named graphs in RDF



However, most RDF triple stores support them


Loading data into graphs in Jena, use “ng4j”
+

Named graphs in Jena, Example
// Create a new graphset
NamedGraphSet graphset = new NamedGraphSetImpl();
NamedGraph graph = graphset.createGraph("http://example.org/persons/123");
// Add information to the NamedGraph
graph.add(new
Triple(Node.createURI("http://richard.cyganiak.de/foaf.rdf#RichardCyganiak"),
Node.createURI("http://xmlns.com/foaf/0.1/name") ,
Node.createLiteral("Richard Cyganiak", null, null)));
// Create a quad
Quad quad = new Quad(Node.createURI("http://www.bizer.de/InformationAboutRichard"),
Node.createURI("http://richard.cyganiak.de/foaf.rdf#RichardCyganiak"),
Node.createURI("http://xmlns.com/foaf/0.1/mbox") ,
Node.createURI("mailto:richard@cyganiak.de"));
// Add the quad to the graphset. This will create a new NamedGraph in the
// graphset.
graphset.addQuad(quad);
+

Components of SPARQL Queries
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX umbel-sc: <http://umbel.org/umbel/sc/>
SELECT ?v
FROM <http://example.org/myGeoData>
WHERE {
?v rdf:type umbel-sc:Volcano .
}
ORDER BY ?name



Dataset specification




Specify the RDF dataset to be queries
(more on that later)

Specification using FROM and FROM NAMED
+

Graph Graph Patterns
Default graph
dbpedia:Mount_Etna
dbpedia:Mount_Baker

rdfs:seeAlso <http://example.org/d1>
rdfs:seeAlso <http://example.org/d2>
http://example.org/d1

dbpedia:Mount_Etna

rdf:type umbel-sc:Volcano ;
rdfs:label "Etna" .
http://example.org/d2

dbpedia:Mount_Baker

rdf:type umbel-sc:Volcano.
http://example.org/d3

dbpedia:Beerenberg

rdf:type umbel-sc:Volcano ;
rdfs:label "Beerenberg"@en ;



Evaluation of patterns w.r.t. the active graph



GRAPH clause for making a named graph the active graph
+

Graph Graph Patterns
Default graph
dbpedia:Mount_Etna
dbpedia:Mount_Baker

rdfs:seeAlso <http://example.org/d1>
rdfs:seeAlso <http://example.org/d2>
http://example.org/d1

dbpedia:Mount_Etna

rdf:type umbel-sc:Volcano ;
rdfs:label "Etna" .
http://example.org/d2

dbpedia:Mount_Baker

rdf:type umbel-sc:Volcano.
http://example.org/d3

dbpedia:Beerenberg

rdf:type umbel-sc:Volcano ;
rdfs:label "Beerenberg"@en ;

SELECT ?v WHERE {
GRAPH ?g {
?v rdf:type umbel-sc:Volcano }
}

?v
dbpedia:Mount_Etna
dbpedia:Mount_Baker
dbpedia:Beerenberg
+

Graph Graph Patterns
Default graph
dbpedia:Mount_Etna
dbpedia:Mount_Baker

rdfs:seeAlso <http://example.org/d1>
rdfs:seeAlso <http://example.org/d2>
http://example.org/d1

dbpedia:Mount_Etna

rdf:type umbel-sc:Volcano ;
rdfs:label "Etna" .
http://example.org/d2

dbpedia:Mount_Baker

rdf:type umbel-sc:Volcano.
http://example.org/d3

dbpedia:Beerenberg

rdf:type umbel-sc:Volcano ;
rdfs:label "Beerenberg"@en ;

?v
SELECT ?v ?g WHERE {
dbpedia:Mount_Etna
GRAPH ?g {
?v rdf:type umbel-sc:Volcano }
dbpedia:Mount_Baker
}
dbpedia:Beerenberg

?g
<http://example.org/d1>
<http://example.org/d2>
<http://example.org/d3>
+

Graph Graph Patterns
Default graph
dbpedia:Mount_Etna
dbpedia:Mount_Baker

rdfs:seeAlso <http://example.org/d1>
rdfs:seeAlso <http://example.org/d2>
http://example.org/d1

dbpedia:Mount_Etna

rdf:type umbel-sc:Volcano ;
rdfs:label "Etna" .
http://example.org/d2

dbpedia:Mount_Baker

rdf:type umbel-sc:Volcano.
http://example.org/d3

dbpedia:Beerenberg

rdf:type umbel-sc:Volcano ;
rdfs:label "Beerenberg"@en ;

SELECT ?v WHERE {
_:x rdfs:seeAlso ?g GRAPH ?g {
?v rdf:type umbel-sc:Volcano }
}

?v
dbpedia:Mount_Etna
dbpedia:Mount_Baker
+

Negation
dbpedia:Mount_Etna
dbpedia:Mount_Baker
dbpedia:Beerenberg



rdf:type umbel-sc:Volcano ;
rdfs:label "Etna" .
rdf:type umbel-sc:Volcano.
rdf:type umbel-sc:Volcano,
umbel-sc:NaturalElevation ;
rdfs:label "Beerenberg"@en ;
rdfs:label "Беренберг"@ru .

What volcanos do not have a name in our data?
SELECT ?v WHERE {
?v rdf:type umbel-sc:Volcano .
OPTIONAL { ?v rdfs:label ?name }
FILTER ( ! BOUND(?name) )
}

?v
dbpedia:Mount_Baker
Negation as failure
+

Negation
dbpedia:Mount_Etna
dbpedia:Mount_Baker
dbpedia:Beerenberg



rdf:type umbel-sc:Volcano ;
rdfs:label "Etna" .
rdf:type umbel-sc:Volcano.
rdf:type umbel-sc:Volcano,
umbel-sc:NaturalElevation ;
rdfs:label "Beerenberg"@en ;
rdfs:label "Беренберг"@ru .

What volcanos are not called “Beerenberg”?
SELECT ?v WHERE {
?v rdf:type
umbel-sc:Volcano ;
rdfs:label ?name .
FILTER ( STR(?name) != “Beerenberg” ) }
}

?name
dbpedia:Mount_Etna
dbpedia:Mount_Baker
dbpedia:Beerenberg
+

Negation
dbpedia:Mount_Etna
dbpedia:Mount_Baker
dbpedia:Beerenberg



rdf:type umbel-sc:Volcano ;
rdfs:label "Etna" .
rdf:type umbel-sc:Volcano.
rdf:type umbel-sc:Volcano,
umbel-sc:NaturalElevation ;
rdfs:label "Beerenberg"@en ;
rdfs:label "Беренберг"@ru .

What volcanos are not called “Beerenberg”?

SELECT ?v WHERE {
?v rdf:type umbel-sc:Volcano ;
OPTIONAL {
?v rdfs:label ?name .
FILTER ( STR(?name) = “Beerenberg” )
}
FILTER ( ! BOUND (?name) )
}

?name
dbpedia:Mount_Etna
dbpedia:Mount_Baker
Negation as failure
+

Graph Graph Patterns
Default graph
dbpedia:Mount_Etna
dbpedia:Mount_Baker

rdfs:seeAlso <http://example.org/d1>
rdfs:seeAlso <http://example.org/d2>
http://example.org/d1

dbpedia:Mount_Etna

rdf:type umbel-sc:Volcano ;
rdfs:label "Etna" .
http://example.org/d2

dbpedia:Mount_Baker

rdf:type umbel-sc:Volcano.

http://example.org/d3
SELECT ?g WHERE {
GRAPH ?g {
dbpedia:Beerenberg
rdf:type umbel-sc:Volcano ;
?v rdf:type umble-sc:Volcano ; "Beerenberg"@en ;
rdfs:label
rdfs:label ?name .
 Which named graphs contain the name of a volcano that is not
}
references rdfs:seeAlso graph
OPTIONAL { ?vin the default?r }
FILTER ( ! BOUND(?r) )
}
+

Summary – Graph Patterns


Different types of graph patterns for the query pattern
(WHERE clause):


Basic graph pattern (BGP)



Group graph pattern



Optional graph pattern – keyword OPTIONAL



Union graph pattern – keyword UNION



Graph graph pattern – keyword GRAPH



Constraints – keyword FILTER
+

Components of SPARQL Queries
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX umbel-sc: <http://umbel.org/umbel/sc/>
SELECT ?v
FROM <http://example.org/myGeoData>
WHERE {
?v rdf:type umbel-sc:Volcano .
}
ORDER BY ?name



Result form specification


SELECT, DESCRIBE, CONSTRUCT or ASK
(more later)
+

Result Forms


SELECT



Selected variables separated by space (not by comma!)





Result: sequence of solutions (i.e. sets of variable bindings)
Asterisk character (“*”) selects all variables in the pattern

ASK


Check whether there is at least one result



Result: true or false



Example: Do we have data about volcanos?
ASK WHERE {
?v rdf:type umble-sc:Volcano
}
+

Result Forms


DESCRIBE


Result: an RDF graph with data about resources



Non-deterministic (i.e. query processor defines the actual structure
of the resulting RDF graph)



Example: just name the resource

DESCRIBE <http://dbpedia.org/resource/Beerenberg>


Possible to specify the resource by query pattern
DESCRIBE ?v WHERE {
?v rdf:type umbel-sc:Volcano .
}
+

Result Forms


CONSTRUCT


Result: an RDF graph constructed from a template



Template: graph pattern with variables from the query pattern

CONSTRUCT {
?v
rdfs:label ?name ;
rdf:type myTypes:VolcanosOutsideTheUS
} WHERE {
?v rdf:type umbel-sc:Volcano ;
rdfs:label ?name .
OPTIONAL { ?v p:location ?l
FILTER ( ?l = dbpedia:United_States ) }
FILTER ( ! BOUND(?l) )
}
+

Result Forms
Data
dbpedia:Mount_Etna

dbpedia:Mount_Baker

dbpedia:Beerenberg

dbpedia:Mount_Etna

dbpedia:Beerenberg

rdf:type umbel-sc:Volcano ;
rdfs:label "Etna” ;
p:location dbpedia:Italy .
rdf:type umbel-sc:Volcano ;
rdfs:label ”Mount Baker” ;
p:location dbpedia:United_States.
rdf:type umbel-sc:Volcano,
rdfs:label "Beerenberg"@en ;
p:location dbpedia:Norway .
rdfs:label "Etna” ;
rdf:type myTypes:VolcanosOutsideTheUS
rdfs:label "Beerenberg"@en ;
rdf:type myTypes:VolcanosOutsideTheUS
Result
+

Solution Modifiers
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX umbel-sc: <http://umbel.org/umbel/sc/>
SELECT ?v
FROM <http://example.org/myGeoData>
WHERE {
?v rdf:type umbel-sc:Volcano .
}
ORDER BY ?name



Solution modifiers


Only for SELECT queries



Modify the result set as a whole (not single solutions)



Keywords: DISTINCT, ORDER BY, LIMIT, OFFSET
+

Solution Modifiers
dbpedia:Mount_Etna
dbpedia:Mount_Baker
dbpedia:Beerenberg



rdf:type umbel-sc:Volcano ;
rdfs:label "Etna" .
rdf:type umbel-sc:Volcano.
rdf:type umbel-sc:Volcano,
umbel-sc:NaturalElevation ;
rdfs:label "Beerenberg"@en ;
rdfs:label "Беренберг"@ru .

DISTINCT removes duplicates from the result set
?name
SELECT ?type
WHERE {
_:x rdf:type ?type
}

umbel-sc:Volcano
umbel-sc:Volcano
umbel-sc:NaturalElevation
umbel-sc:Volcano
+

Solution Modifiers
dbpedia:Mount_Etna
dbpedia:Mount_Baker
dbpedia:Beerenberg



rdf:type umbel-sc:Volcano ;
rdfs:label "Etna" .
rdf:type umbel-sc:Volcano.
rdf:type umbel-sc:Volcano,
umbel-sc:NaturalElevation ;
rdfs:label "Beerenberg"@en ;
rdfs:label "Беренберг"@ru .

DISTINCT removes duplicates from the result set
?name
SELECT DISTINCT ?type
WHERE {
_:x rdf:type ?type
}

umbel-sc:Volcano
umbel-sc:NaturalElevation
+

Solution Modifiers


ORDER BY orders the results
SELECT ?v WHERE { ?v rdf:type umbel-sc:Volcano ;
rdfs:label ?name }
ORDER BY ?name



How do you order different kinds of elements?


unbound < blank node < URI < literal



ASC for ascending (default) and DESC for descending



Hierarchical order criteria
SELECT ?name WHERE { ?v rdf:type umbel-sc:Volcano ;
p:lastEruption ?le ;
rdfs:label ?name }
ORDER BY DESC(?le), ?name
+

Solution Modifiers


LIMIT – limits the number of result
SELECT ?v WHERE { ?v rdf:type umbel-sc:Volcano ;
rdfs:label ?name }
ORDER BY ?name LIMIT 5



OFFSET – position/index of the first reported results
SELECT ?v WHERE { ?v rdf:type umbel-sc:Volcano ;
rdfs:label ?name }
ORDER BY ?name LIMIT 5 OFFSET 10



Order of the result should be predictable (combine with
ORDER BY)
SWT Lecture Session 3 - SPARQL

More Related Content

What's hot

RDF briefing
RDF briefingRDF briefing
RDF briefing
Frank van Harmelen
 
Ist16-04 An introduction to RDF
Ist16-04 An introduction to RDF Ist16-04 An introduction to RDF
Ist16-04 An introduction to RDF
Emanuele Della Valle
 
RDF data model
RDF data modelRDF data model
RDF data model
Jose Emilio Labra Gayo
 
Ontologies in RDF-S/OWL
Ontologies in RDF-S/OWLOntologies in RDF-S/OWL
Ontologies in RDF-S/OWL
Emanuele Della Valle
 
RDF Data Model
RDF Data ModelRDF Data Model
RDF Data Model
Jose Emilio Labra Gayo
 
Two graph data models : RDF and Property Graphs
Two graph data models : RDF and Property GraphsTwo graph data models : RDF and Property Graphs
Two graph data models : RDF and Property Graphs
andyseaborne
 
Introduction To RDF and RDFS
Introduction To RDF and RDFSIntroduction To RDF and RDFS
Introduction To RDF and RDFS
Nilesh Wagmare
 
RDF, SPARQL and Semantic Repositories
RDF, SPARQL and Semantic RepositoriesRDF, SPARQL and Semantic Repositories
RDF, SPARQL and Semantic Repositories
Marin Dimitrov
 
Data in RDF
Data in RDFData in RDF
Another RDF Encoding Form
Another RDF Encoding FormAnother RDF Encoding Form
Another RDF Encoding Form
Jakob .
 
Semantic web
Semantic webSemantic web
Semantic web
tariq1352
 
Introduction to RDF Data Model
Introduction to RDF Data ModelIntroduction to RDF Data Model
Introduction to RDF Data Model
Cesar Augusto Nogueira
 
Efficient Query Answering against Dynamic RDF Databases
Efficient Query Answering against Dynamic RDF DatabasesEfficient Query Answering against Dynamic RDF Databases
Efficient Query Answering against Dynamic RDF Databases
Alexandra Roatiș
 
RDF Tutorial - SPARQL 20091031
RDF Tutorial - SPARQL 20091031RDF Tutorial - SPARQL 20091031
RDF Tutorial - SPARQL 20091031
kwangsub kim
 
Querying the Semantic Web with SPARQL
Querying the Semantic Web with SPARQLQuerying the Semantic Web with SPARQL
Querying the Semantic Web with SPARQL
Emanuele Della Valle
 
Triple Stores
Triple StoresTriple Stores
Triple Stores
Stephan Volmer
 
An Introduction to RDF and the Web of Data
An Introduction to RDF and the Web of DataAn Introduction to RDF and the Web of Data
An Introduction to RDF and the Web of Data
Olaf Hartig
 
Challenges and applications of RDF shapes
Challenges and applications of RDF shapesChallenges and applications of RDF shapes
Challenges and applications of RDF shapes
Jose Emilio Labra Gayo
 
Rdf Overview Presentation
Rdf Overview PresentationRdf Overview Presentation
Rdf Overview Presentation
Ken Varnum
 
Introduction to RDF
Introduction to RDFIntroduction to RDF
Introduction to RDF
Narni Rajesh
 

What's hot (20)

RDF briefing
RDF briefingRDF briefing
RDF briefing
 
Ist16-04 An introduction to RDF
Ist16-04 An introduction to RDF Ist16-04 An introduction to RDF
Ist16-04 An introduction to RDF
 
RDF data model
RDF data modelRDF data model
RDF data model
 
Ontologies in RDF-S/OWL
Ontologies in RDF-S/OWLOntologies in RDF-S/OWL
Ontologies in RDF-S/OWL
 
RDF Data Model
RDF Data ModelRDF Data Model
RDF Data Model
 
Two graph data models : RDF and Property Graphs
Two graph data models : RDF and Property GraphsTwo graph data models : RDF and Property Graphs
Two graph data models : RDF and Property Graphs
 
Introduction To RDF and RDFS
Introduction To RDF and RDFSIntroduction To RDF and RDFS
Introduction To RDF and RDFS
 
RDF, SPARQL and Semantic Repositories
RDF, SPARQL and Semantic RepositoriesRDF, SPARQL and Semantic Repositories
RDF, SPARQL and Semantic Repositories
 
Data in RDF
Data in RDFData in RDF
Data in RDF
 
Another RDF Encoding Form
Another RDF Encoding FormAnother RDF Encoding Form
Another RDF Encoding Form
 
Semantic web
Semantic webSemantic web
Semantic web
 
Introduction to RDF Data Model
Introduction to RDF Data ModelIntroduction to RDF Data Model
Introduction to RDF Data Model
 
Efficient Query Answering against Dynamic RDF Databases
Efficient Query Answering against Dynamic RDF DatabasesEfficient Query Answering against Dynamic RDF Databases
Efficient Query Answering against Dynamic RDF Databases
 
RDF Tutorial - SPARQL 20091031
RDF Tutorial - SPARQL 20091031RDF Tutorial - SPARQL 20091031
RDF Tutorial - SPARQL 20091031
 
Querying the Semantic Web with SPARQL
Querying the Semantic Web with SPARQLQuerying the Semantic Web with SPARQL
Querying the Semantic Web with SPARQL
 
Triple Stores
Triple StoresTriple Stores
Triple Stores
 
An Introduction to RDF and the Web of Data
An Introduction to RDF and the Web of DataAn Introduction to RDF and the Web of Data
An Introduction to RDF and the Web of Data
 
Challenges and applications of RDF shapes
Challenges and applications of RDF shapesChallenges and applications of RDF shapes
Challenges and applications of RDF shapes
 
Rdf Overview Presentation
Rdf Overview PresentationRdf Overview Presentation
Rdf Overview Presentation
 
Introduction to RDF
Introduction to RDFIntroduction to RDF
Introduction to RDF
 

Similar to SWT Lecture Session 3 - SPARQL

(An Overview on) Linked Data Management and SPARQL Querying (ISSLOD2011)
(An Overview on) Linked Data Management and SPARQL Querying (ISSLOD2011)(An Overview on) Linked Data Management and SPARQL Querying (ISSLOD2011)
(An Overview on) Linked Data Management and SPARQL Querying (ISSLOD2011)
Olaf Hartig
 
An Introduction to SPARQL
An Introduction to SPARQLAn Introduction to SPARQL
An Introduction to SPARQL
Olaf Hartig
 
A hands on overview of the semantic web
A hands on overview of the semantic webA hands on overview of the semantic web
A hands on overview of the semantic web
Marakana Inc.
 
Data translation with SPARQL 1.1
Data translation with SPARQL 1.1Data translation with SPARQL 1.1
Data translation with SPARQL 1.1
andreas_schultz
 
The Semantics of SPARQL
The Semantics of SPARQLThe Semantics of SPARQL
The Semantics of SPARQL
Olaf Hartig
 
A Hands On Overview Of The Semantic Web
A Hands On Overview Of The Semantic WebA Hands On Overview Of The Semantic Web
A Hands On Overview Of The Semantic Web
Shamod Lacoul
 
Federation and Navigation in SPARQL 1.1
Federation and Navigation in SPARQL 1.1Federation and Navigation in SPARQL 1.1
Federation and Navigation in SPARQL 1.1
net2-project
 
Triplestore and SPARQL
Triplestore and SPARQLTriplestore and SPARQL
Triplestore and SPARQL
Lino Valdivia
 
Semantic web meetup – sparql tutorial
Semantic web meetup – sparql tutorialSemantic web meetup – sparql tutorial
Semantic web meetup – sparql tutorial
AdonisDamian
 
Sparql
SparqlSparql
SPARQL Cheat Sheet
SPARQL Cheat SheetSPARQL Cheat Sheet
SPARQL Cheat Sheet
LeeFeigenbaum
 
LarKC Tutorial at ISWC 2009 - Data Model
LarKC Tutorial at ISWC 2009 - Data ModelLarKC Tutorial at ISWC 2009 - Data Model
LarKC Tutorial at ISWC 2009 - Data Model
LarKC
 
Semantic Variation Graphs the case for RDF & SPARQL
Semantic Variation Graphs the case for RDF & SPARQLSemantic Variation Graphs the case for RDF & SPARQL
Semantic Variation Graphs the case for RDF & SPARQL
Jerven Bolleman
 
Tutorial "An Introduction to SPARQL and Queries over Linked Data" Chapter 2 (...
Tutorial "An Introduction to SPARQL and Queries over Linked Data" Chapter 2 (...Tutorial "An Introduction to SPARQL and Queries over Linked Data" Chapter 2 (...
Tutorial "An Introduction to SPARQL and Queries over Linked Data" Chapter 2 (...
Olaf Hartig
 
The Semantic Web #10 - SPARQL
The Semantic Web #10 - SPARQLThe Semantic Web #10 - SPARQL
The Semantic Web #10 - SPARQL
Myungjin Lee
 
Facet: Building Web Pages with SPARQL
Facet: Building Web Pages with SPARQLFacet: Building Web Pages with SPARQL
Facet: Building Web Pages with SPARQL
Leigh Dodds
 
SPARQL
SPARQLSPARQL
SPARQL
Raji Ghawi
 
SWT Lecture Session 4 - SW architectures and SPARQL
SWT Lecture Session 4 - SW architectures and SPARQLSWT Lecture Session 4 - SW architectures and SPARQL
SWT Lecture Session 4 - SW architectures and SPARQL
Mariano Rodriguez-Muro
 
Functional manipulations of large data graphs 20160601
Functional manipulations of large data graphs 20160601Functional manipulations of large data graphs 20160601
Functional manipulations of large data graphs 20160601
David Wood
 
SPARQL introduction and training (130+ slides with exercices)
SPARQL introduction and training (130+ slides with exercices)SPARQL introduction and training (130+ slides with exercices)
SPARQL introduction and training (130+ slides with exercices)
Thomas Francart
 

Similar to SWT Lecture Session 3 - SPARQL (20)

(An Overview on) Linked Data Management and SPARQL Querying (ISSLOD2011)
(An Overview on) Linked Data Management and SPARQL Querying (ISSLOD2011)(An Overview on) Linked Data Management and SPARQL Querying (ISSLOD2011)
(An Overview on) Linked Data Management and SPARQL Querying (ISSLOD2011)
 
An Introduction to SPARQL
An Introduction to SPARQLAn Introduction to SPARQL
An Introduction to SPARQL
 
A hands on overview of the semantic web
A hands on overview of the semantic webA hands on overview of the semantic web
A hands on overview of the semantic web
 
Data translation with SPARQL 1.1
Data translation with SPARQL 1.1Data translation with SPARQL 1.1
Data translation with SPARQL 1.1
 
The Semantics of SPARQL
The Semantics of SPARQLThe Semantics of SPARQL
The Semantics of SPARQL
 
A Hands On Overview Of The Semantic Web
A Hands On Overview Of The Semantic WebA Hands On Overview Of The Semantic Web
A Hands On Overview Of The Semantic Web
 
Federation and Navigation in SPARQL 1.1
Federation and Navigation in SPARQL 1.1Federation and Navigation in SPARQL 1.1
Federation and Navigation in SPARQL 1.1
 
Triplestore and SPARQL
Triplestore and SPARQLTriplestore and SPARQL
Triplestore and SPARQL
 
Semantic web meetup – sparql tutorial
Semantic web meetup – sparql tutorialSemantic web meetup – sparql tutorial
Semantic web meetup – sparql tutorial
 
Sparql
SparqlSparql
Sparql
 
SPARQL Cheat Sheet
SPARQL Cheat SheetSPARQL Cheat Sheet
SPARQL Cheat Sheet
 
LarKC Tutorial at ISWC 2009 - Data Model
LarKC Tutorial at ISWC 2009 - Data ModelLarKC Tutorial at ISWC 2009 - Data Model
LarKC Tutorial at ISWC 2009 - Data Model
 
Semantic Variation Graphs the case for RDF & SPARQL
Semantic Variation Graphs the case for RDF & SPARQLSemantic Variation Graphs the case for RDF & SPARQL
Semantic Variation Graphs the case for RDF & SPARQL
 
Tutorial "An Introduction to SPARQL and Queries over Linked Data" Chapter 2 (...
Tutorial "An Introduction to SPARQL and Queries over Linked Data" Chapter 2 (...Tutorial "An Introduction to SPARQL and Queries over Linked Data" Chapter 2 (...
Tutorial "An Introduction to SPARQL and Queries over Linked Data" Chapter 2 (...
 
The Semantic Web #10 - SPARQL
The Semantic Web #10 - SPARQLThe Semantic Web #10 - SPARQL
The Semantic Web #10 - SPARQL
 
Facet: Building Web Pages with SPARQL
Facet: Building Web Pages with SPARQLFacet: Building Web Pages with SPARQL
Facet: Building Web Pages with SPARQL
 
SPARQL
SPARQLSPARQL
SPARQL
 
SWT Lecture Session 4 - SW architectures and SPARQL
SWT Lecture Session 4 - SW architectures and SPARQLSWT Lecture Session 4 - SW architectures and SPARQL
SWT Lecture Session 4 - SW architectures and SPARQL
 
Functional manipulations of large data graphs 20160601
Functional manipulations of large data graphs 20160601Functional manipulations of large data graphs 20160601
Functional manipulations of large data graphs 20160601
 
SPARQL introduction and training (130+ slides with exercices)
SPARQL introduction and training (130+ slides with exercices)SPARQL introduction and training (130+ slides with exercices)
SPARQL introduction and training (130+ slides with exercices)
 

More from Mariano Rodriguez-Muro

SWT Lab 3
SWT Lab 3SWT Lab 3
SWT Lab 5
SWT Lab 5SWT Lab 5
SWT Lab 2
SWT Lab 2SWT Lab 2
SWT Lab 1
SWT Lab 1SWT Lab 1
SWT Lecture Session 8 - Inference in jena
SWT Lecture Session 8 - Inference in jenaSWT Lecture Session 8 - Inference in jena
SWT Lecture Session 8 - Inference in jena
Mariano Rodriguez-Muro
 
SWT Lecture Session 7 - Advanced uses of RDFS
SWT Lecture Session 7 - Advanced uses of RDFSSWT Lecture Session 7 - Advanced uses of RDFS
SWT Lecture Session 7 - Advanced uses of RDFS
Mariano Rodriguez-Muro
 
SWT Lecture Session 5 - RDFS
SWT Lecture Session 5 - RDFSSWT Lecture Session 5 - RDFS
SWT Lecture Session 5 - RDFS
Mariano Rodriguez-Muro
 
SWT Lecture Session 4 - Sesame
SWT Lecture Session 4 - SesameSWT Lecture Session 4 - Sesame
SWT Lecture Session 4 - Sesame
Mariano Rodriguez-Muro
 
7 advanced uses of rdfs
7 advanced uses of rdfs7 advanced uses of rdfs
7 advanced uses of rdfs
Mariano Rodriguez-Muro
 
4 sesame
4 sesame4 sesame
SWT Lecture Session 1 - Introduction
SWT Lecture Session 1 - IntroductionSWT Lecture Session 1 - Introduction
SWT Lecture Session 1 - Introduction
Mariano Rodriguez-Muro
 
ontop: A tutorial
ontop: A tutorialontop: A tutorial
ontop: A tutorial
Mariano Rodriguez-Muro
 
Stanford'12 Intro to Ontology Based Data Access for RDBMS through query rewri...
Stanford'12 Intro to Ontology Based Data Access for RDBMS through query rewri...Stanford'12 Intro to Ontology Based Data Access for RDBMS through query rewri...
Stanford'12 Intro to Ontology Based Data Access for RDBMS through query rewri...
Mariano Rodriguez-Muro
 
Introduction to query rewriting optimisation with dependencies
Introduction to query rewriting optimisation with dependenciesIntroduction to query rewriting optimisation with dependencies
Introduction to query rewriting optimisation with dependencies
Mariano Rodriguez-Muro
 
OXFORD'13 Optimising OWL 2 QL query rewriring
OXFORD'13 Optimising OWL 2 QL query rewriringOXFORD'13 Optimising OWL 2 QL query rewriring
OXFORD'13 Optimising OWL 2 QL query rewriring
Mariano Rodriguez-Muro
 
OWLED'12 Quest
OWLED'12 QuestOWLED'12 Quest
OWLED'12 Quest
Mariano Rodriguez-Muro
 
ODBASE'08 dl-lite explanations
ODBASE'08 dl-lite explanationsODBASE'08 dl-lite explanations
ODBASE'08 dl-lite explanations
Mariano Rodriguez-Muro
 
IMAS'08 obda plugin
IMAS'08 obda pluginIMAS'08 obda plugin
IMAS'08 obda plugin
Mariano Rodriguez-Muro
 
DL'12 dl-lite explanations
DL'12 dl-lite explanationsDL'12 dl-lite explanations
DL'12 dl-lite explanations
Mariano Rodriguez-Muro
 
DL'12 mastro at work
DL'12 mastro at workDL'12 mastro at work
DL'12 mastro at work
Mariano Rodriguez-Muro
 

More from Mariano Rodriguez-Muro (20)

SWT Lab 3
SWT Lab 3SWT Lab 3
SWT Lab 3
 
SWT Lab 5
SWT Lab 5SWT Lab 5
SWT Lab 5
 
SWT Lab 2
SWT Lab 2SWT Lab 2
SWT Lab 2
 
SWT Lab 1
SWT Lab 1SWT Lab 1
SWT Lab 1
 
SWT Lecture Session 8 - Inference in jena
SWT Lecture Session 8 - Inference in jenaSWT Lecture Session 8 - Inference in jena
SWT Lecture Session 8 - Inference in jena
 
SWT Lecture Session 7 - Advanced uses of RDFS
SWT Lecture Session 7 - Advanced uses of RDFSSWT Lecture Session 7 - Advanced uses of RDFS
SWT Lecture Session 7 - Advanced uses of RDFS
 
SWT Lecture Session 5 - RDFS
SWT Lecture Session 5 - RDFSSWT Lecture Session 5 - RDFS
SWT Lecture Session 5 - RDFS
 
SWT Lecture Session 4 - Sesame
SWT Lecture Session 4 - SesameSWT Lecture Session 4 - Sesame
SWT Lecture Session 4 - Sesame
 
7 advanced uses of rdfs
7 advanced uses of rdfs7 advanced uses of rdfs
7 advanced uses of rdfs
 
4 sesame
4 sesame4 sesame
4 sesame
 
SWT Lecture Session 1 - Introduction
SWT Lecture Session 1 - IntroductionSWT Lecture Session 1 - Introduction
SWT Lecture Session 1 - Introduction
 
ontop: A tutorial
ontop: A tutorialontop: A tutorial
ontop: A tutorial
 
Stanford'12 Intro to Ontology Based Data Access for RDBMS through query rewri...
Stanford'12 Intro to Ontology Based Data Access for RDBMS through query rewri...Stanford'12 Intro to Ontology Based Data Access for RDBMS through query rewri...
Stanford'12 Intro to Ontology Based Data Access for RDBMS through query rewri...
 
Introduction to query rewriting optimisation with dependencies
Introduction to query rewriting optimisation with dependenciesIntroduction to query rewriting optimisation with dependencies
Introduction to query rewriting optimisation with dependencies
 
OXFORD'13 Optimising OWL 2 QL query rewriring
OXFORD'13 Optimising OWL 2 QL query rewriringOXFORD'13 Optimising OWL 2 QL query rewriring
OXFORD'13 Optimising OWL 2 QL query rewriring
 
OWLED'12 Quest
OWLED'12 QuestOWLED'12 Quest
OWLED'12 Quest
 
ODBASE'08 dl-lite explanations
ODBASE'08 dl-lite explanationsODBASE'08 dl-lite explanations
ODBASE'08 dl-lite explanations
 
IMAS'08 obda plugin
IMAS'08 obda pluginIMAS'08 obda plugin
IMAS'08 obda plugin
 
DL'12 dl-lite explanations
DL'12 dl-lite explanationsDL'12 dl-lite explanations
DL'12 dl-lite explanations
 
DL'12 mastro at work
DL'12 mastro at workDL'12 mastro at work
DL'12 mastro at work
 

Recently uploaded

ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptxRESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
zuzanka
 
Nutrition Inc FY 2024, 4 - Hour Training
Nutrition Inc FY 2024, 4 - Hour TrainingNutrition Inc FY 2024, 4 - Hour Training
Nutrition Inc FY 2024, 4 - Hour Training
melliereed
 
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...
TechSoup
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Denish Jangid
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
PsychoTech Services
 
Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"
National Information Standards Organization (NISO)
 
Pharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brubPharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brub
danielkiash986
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
Himanshu Rai
 
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdfREASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
giancarloi8888
 
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
EduSkills OECD
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
Nguyen Thanh Tu Collection
 
Electric Fetus - Record Store Scavenger Hunt
Electric Fetus - Record Store Scavenger HuntElectric Fetus - Record Store Scavenger Hunt
Electric Fetus - Record Store Scavenger Hunt
RamseyBerglund
 
The basics of sentences session 7pptx.pptx
The basics of sentences session 7pptx.pptxThe basics of sentences session 7pptx.pptx
The basics of sentences session 7pptx.pptx
heathfieldcps1
 
Haunted Houses by H W Longfellow for class 10
Haunted Houses by H W Longfellow for class 10Haunted Houses by H W Longfellow for class 10
Haunted Houses by H W Longfellow for class 10
nitinpv4ai
 
A Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two HeartsA Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two Hearts
Steve Thomason
 
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
imrankhan141184
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
Katrina Pritchard
 
Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47
MysoreMuleSoftMeetup
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
GeorgeMilliken2
 

Recently uploaded (20)

ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptxRESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
 
Nutrition Inc FY 2024, 4 - Hour Training
Nutrition Inc FY 2024, 4 - Hour TrainingNutrition Inc FY 2024, 4 - Hour Training
Nutrition Inc FY 2024, 4 - Hour Training
 
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
 
Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"
 
Pharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brubPharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brub
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
 
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdfREASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
REASIGNACION 2024 UGEL CHUPACA 2024 UGEL CHUPACA.pdf
 
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 9 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2024-2025 - ...
 
Electric Fetus - Record Store Scavenger Hunt
Electric Fetus - Record Store Scavenger HuntElectric Fetus - Record Store Scavenger Hunt
Electric Fetus - Record Store Scavenger Hunt
 
The basics of sentences session 7pptx.pptx
The basics of sentences session 7pptx.pptxThe basics of sentences session 7pptx.pptx
The basics of sentences session 7pptx.pptx
 
Haunted Houses by H W Longfellow for class 10
Haunted Houses by H W Longfellow for class 10Haunted Houses by H W Longfellow for class 10
Haunted Houses by H W Longfellow for class 10
 
A Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two HeartsA Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two Hearts
 
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
 
Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
 

SWT Lecture Session 3 - SPARQL

  • 1. + SPARQL 1.0 Mariano Rodriguez-Muro, Free University of Bozen-Bolzano
  • 2. + Disclaimer  Most of the content of these slides is from:   An introduction to SPARQL and Queries over Linked Data. Chapter 2 SPARQL. By Olaf Harting (CC Attribution Share Alike 3.0 License) License  This work is licensed under a Creative Commons Attribution-Share Alike 3.0 License (http://creativecommons.org/licenses/by-sa/3.0/)
  • 3. + Reading material  Semantic Web Programming Part II, Chapter 6  Foundations of Semantic Web Technologies - Sections 7.1 to 7.1.8
  • 4. + SPARQL in General  A family of W3C recommendations  SPARQL Query   SPARQL Update   Declarative update language for RDF data SPARQL Protocol   Declarative query language for RDF data Communication between SPARQL processing services (a.k.a. SPARQL endpoints) and clients SPARQL Query Results XML Format  XML Format for serializing query results
  • 5. + Main idea of SPARQL queries  Pattern matching  Describe subgraphs of the queried RDF graph  Subgraphs that match your description contribute an answer  Mean: graph patterns (i.e. RDF graphs with variables)
  • 6. + Main idea of SPARQL queries ?v dbpedia:Mount_Baker dbpedia:Mount_Etna
  • 7. + Components of SPARQL Queries PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX umbel-sc: <http://umbel.org/umbel/sc/> SELECT ?v FROM <http://example.org/myGeoData> WHERE { ?v rdf:type umbel-sc:Volcano . } ORDER BY ?name
  • 8. + Components of SPARQL Queries PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX umbel-sc: <http://umbel.org/umbel/sc/> SELECT ?v FROM <http://example.org/myGeoData> WHERE { ?v rdf:type umbel-sc:Volcano . } ORDER BY ?name  Prologue  Prefix definitions for compact URIs (CURIEs)  Attention (difference w.r.t. Turtle): No period (“.”) character as separator
  • 9. + Components of SPARQL Queries PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX umbel-sc: <http://umbel.org/umbel/sc/> SELECT ?v FROM <http://example.org/myGeoData> WHERE { ?v rdf:type umbel-sc:Volcano . } ORDER BY ?name  Result form specification  SELECT, DESCRIBE, CONSTRUCT or ASK (more later)
  • 10. + Components of SPARQL Queries PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX umbel-sc: <http://umbel.org/umbel/sc/> SELECT ?v FROM <http://example.org/myGeoData> WHERE { ?v rdf:type umbel-sc:Volcano . } ORDER BY ?name  Dataset specification  Specify the RDF dataset to be queries (more on that later)
  • 11. + Components of SPARQL Queries PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX umbel-sc: <http://umbel.org/umbel/sc/> SELECT ?v FROM <http://example.org/myGeoData> WHERE { ?v rdf:type umbel-sc:Volcano . } ORDER BY ?name  Query pattern  WHERE clause specifies the graph pattern to be matched
  • 12. + Components of SPARQL Queries PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX umbel-sc: <http://umbel.org/umbel/sc/> SELECT ?v FROM <http://example.org/myGeoData> WHERE { ?v rdf:type umbel-sc:Volcano . } ORDER BY ?name  Solution modifiers  ORDER BY, LIMIT, OFFSET (more about that later)  Only available in some of the result forms
  • 13. + Graph patterns  Different types of graph patterns for the query pattern (WHERE clause):  Basic graph pattern (BGP)  Group graph pattern  Optional graph pattern  Union graph pattern  Graph graph pattern  (Constraints)
  • 14. + Basic Graph Patterns  Set of triple patterns in Turtle syntax (i.e., RDF triples with variables)  Variable names prefixed with “?” or “$” PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX umbel-sc: <http://umbel.org/umbel/sc/> SELECT ?name WHERE { ?v rdf:type umbel-sc:Volcano . ?v rdfs:label ?name }
  • 15. + Basic Graph Patterns  Set of triple patterns in Turtle syntax (i.e., RDF triples with variables)  Variable names prefixed with “?” or “$” PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX umbel-sc: <http://umbel.org/umbel/sc/> SELECT ?name WHERE { ?v rdf:type umbel-sc:Volcano ; rdfs:label ?name }
  • 16. + Example dbpedia:Mount_Etna dbpedia:Mount_Baker dbpedia:Beerenberg  rdf:type umbel-sc:Volcano ; rdfs:label "Etna" . rdf:type umbel-sc:Volcano. rdf:type umbel-sc:Volcano, umbel-sc:NaturalElevation ; rdfs:label "Beerenberg"@en ; rdfs:label "Беренберг"@ru . What are the names of all (known) volcanos? SELECT ?name WHERE { ?v rdf:type umbel-sc:Volcano ; rdfs:label ?name } ?name “Etna” "Беренберг"@ru "Beerenberg"@en
  • 17. + Example dbpedia:Mount_Etna dbpedia:Mount_Baker dbpedia:Beerenberg  rdf:type umbel-sc:Volcano ; rdfs:label "Etna" . rdf:type umbel-sc:Volcano. rdf:type umbel-sc:Volcano, umbel-sc:NaturalElevation ; rdfs:label "Beerenberg"@en ; rdfs:label "Беренберг"@ru . List all types of the volcano called “Beerenberg” SELECT ?type WHERE { ?v rdf:type ?type ; rdfs:label “Beerenberg” } ?type
  • 18. + Example dbpedia:Mount_Etna dbpedia:Mount_Baker dbpedia:Beerenberg  rdf:type umbel-sc:Volcano ; rdfs:label "Etna" . rdf:type umbel-sc:Volcano. rdf:type umbel-sc:Volcano, umbel-sc:NaturalElevation ; rdfs:label "Beerenberg"@en ; rdfs:label "Беренберг"@ru . List all types of the volcano called “Beerenberg” SELECT ?type WHERE { ?v rdf:type ?type ; rdfs:label “Beerenberg”@en } ?type umbel-sc:Volcano umbel-sc:NaturalElevation
  • 19. + Example dbpedia:Mount_Baker dbpedia:United_States rdf:type p:location rdfs:label umbel-sc:Volcano; dbpedia:United_States. “United States”  Where are all (known) volcanos located? (List the names of these locations)  Blank nodes in SPARQL queries  As subject or object of triple patterns  Non-selectable variables SELECT ?name WHERE { _:x rdf:type umbel-sc:Volcano ; p:location [ rdfs:label ?name ] . } ?name “United States”
  • 20. + Example dbpedia:Mount_ Baker rdf:type umbel-sc:Volcano ; p:location [ rdfs:label "United States"@en , " tats-Unis"@fr ] . dbpedia:Mount_ Etna rdf:type umbel-sc:Volcano ; p:location [ rdfs:label "Italy" ] . "Italy"  Blank nodes in the queried data  Blank node identifiers may appear in the results SELECT ?l ?name WHERE { ?v rdf:type umbel-sc:Volcano ; p:location ?l . ?l rdfs:label ?name . } ?l ?name _:n0 “United States”@en _:n0 " tats-Unis"@fr _:n1 "Italy"
  • 21. + Optional Graph Patterns dbpedia:Mount_Etna dbpedia:Mount_Baker dbpedia:Beerenberg  rdf:type umbel-sc:Volcano ; rdfs:label "Etna" . rdf:type umbel-sc:Volcano. rdf:type umbel-sc:Volcano, umbel-sc:NaturalElevation ; rdfs:label "Beerenberg"@en . What are all volcanos and their names? SELECT ?v ?name WHERE { ?v rdf:type umbel-sc:Volcano ; rdfs:label ?name }  ?v ?name dbpedia:Mount_Etna “Etna” dbpedia:Beerenber "Beerenberg"@en Problem: Missing Mount Baker (it has no name)
  • 22. + Optional Graph Patterns SELECT ?v ?name WHERE { ?v rdf:type umbel-sc:Volcano . OPTIONAL { ?v rdfs:label ?name } } ?v ?name dbpedia:Mount_Etna “Etna” dbpedia:Mount_Baker dbpedia:Beerenber  Optional patterns may result in unbound variables "Beerenberg"@en
  • 23. + Union Graph Patterns dbpedia:Mount_Etna dbpedia:Mount_Baker dbpedia:Beerenberg  rdf:type umbel-sc:Volcano ; rdfs:label "Etna” ; p:location dbpedia:Italy . rdf:type umbel-sc:Volcano ; p:location dbpedia:United_States. rdf:type umbel-sc:Volcano, rdfs:label "Beerenberg"@en ; p:location dbpedia:Norway . List all volcanos located in Italy or Norway SELECT ?v WHERE { ?v rdf:type umbel-sc:Volcano; p:location ??????? }
  • 24. + Union Graph Patterns SELECT ?v WHERE { ?v rdf:type umbel-sc:Volcano. { ?v p:location dbpedia:Italy } UNION { ?v p:location dbpedia:Norway } } semantically equivalent SELECT ?v WHERE { { ?v rdf:type umbel-sc:Volcano; p:location dbpedia:Italy } UNION {?v rdf:type umbel-sc:Volcano; p:location dbpedia:Norway. } }
  • 25. + Union Graph Patterns SELECT ?v WHERE { ?v rdf:type umbel-sc:Volcano. { ?v p:location dbpedia:Italy } UNION { ?v p:location dbpedia:Norway } } SELECT ?v WHERE { { ?v rdf:type umbel-sc:Volcano. } { { ?v p:location dbpedia:Italy } UNION { ?v p:location dbpedia:Norway } } } semantically equivalent
  • 26. + Constraints on Solutions  Syntax: Keyword FILTER followed by a filter expression SELECT ?v WHERE { ?v rdf:type umbel-sc:Volcano ; p:lastEruption ?le FILTER ( ?le > 1900 ) }  Filter expressions are formed by operators and functions  Operators and functions operate on RDF terms
  • 27. + Constraints (Truth Table)  Filter expressions evaluate to true, false or error  Truth table: A B A || B A && B T T T T T F T F F T T F F F F F T E T E E T T E F E E F E F E F E E E E
  • 28. + Unary Operators in Constraints Operator Type(A) Result type !A xsd:boolean xsd:boolean +A numeric numeric -A numeric numeric BOUND(A) variable xsd:boolean isURI(A) RDF term xsd:boolean isBLANK(A) RDF term xsd:boolean isLITERAL(A) RDF term xsd:boolean STR(A) literal / URI simple literal LANG(A) literal simple literal DATATYPE(A) literal simple literal
  • 29. + Example dbpedia:Mount_Etna dbpedia:Mount_Baker dbpedia:Beerenberg  rdf:type umbel-sc:Volcano ; rdfs:label "Etna" . rdf:type umbel-sc:Volcano. rdf:type umbel-sc:Volcano, umbel-sc:NaturalElevation ; rdfs:label "Beerenberg"@en ; rdfs:label "Беренберг"@ru . List all types of the volcano called “Beerenberg” SELECT ?type WHERE { ?v rdf:type ?type ; rdfs:label “Beerenberg” } ?type
  • 30. + Example dbpedia:Mount_Etna dbpedia:Mount_Baker dbpedia:Beerenberg  rdf:type umbel-sc:Volcano ; rdfs:label "Etna" . rdf:type umbel-sc:Volcano. rdf:type umbel-sc:Volcano, umbel-sc:NaturalElevation ; rdfs:label "Beerenberg"@en ; rdfs:label "Беренберг"@ru . List all types of the volcano called “Beerenberg” SELECT ?type WHERE { ?v rdf:type ?type ; rdfs:label ?name . FILTER( STR(?name) = “Beerenberg) } ?type umbel-sc:Volcano umbel-sc:NaturalElevation
  • 31. + Constraints (Further operators)  Binary operators:   Comparison operators =, !=, <, >, <=, and >= for numeric datatypes, xsd:dateTime, xsd:string, and xsd:boolean  Comparison operators = and != for other datatypes   Logical connectives && and || for xsd:boolean Arithmetic operators +, -, *, and / for numeric datatypes Furthermore:  REGEX(String,Pattern) or REGEX(String,Pattern,Flags)  sameTERM(A,B)  langMATCHES(A,B)
  • 32. + Example dbpedia:Mount_Etna dbpedia:Mount_Baker dbpedia:Beerenberg  rdf:type umbel-sc:Volcano ; rdfs:label "Etna" . rdf:type umbel-sc:Volcano. rdf:type umbel-sc:Volcano, umbel-sc:NaturalElevation ; rdfs:label "Beerenberg"@en ; rdfs:label "Беренберг"@ru . List all types of the volcano with “e” in their name SELECT ?v WHERE { ?v rdf:type umbel-sc:Volcano ; rdfs:label ?name . FILTER( REGEX(STR(?name), „e”) ) } ?v dbpedia:Beerenberg dbpedia:Beerenberg
  • 33. + Example dbpedia:Mount_Etna dbpedia:Mount_Baker dbpedia:Beerenberg  rdf:type umbel-sc:Volcano ; rdfs:label "Etna" . rdf:type umbel-sc:Volcano. rdf:type umbel-sc:Volcano, umbel-sc:NaturalElevation ; rdfs:label "Beerenberg"@en ; rdfs:label "Беренберг"@ru . List all types of the volcano with “e” in their name (case insensitive) SELECT ?v WHERE { ?v rdf:type umbel-sc:Volcano ; rdfs:label ?name . FILTER( REGEX(STR(?name), “e”,”i”) ) } ?v dbpedia:Mount_Etna dbpedia:Beerenberg dbpedia:Beerenberg
  • 34. + Graph Graph Patterns Default graph dbpedia:Mount_Etna dbpedia:Mount_Baker rdfs:seeAlso <http://example.org/d1> rdfs:seeAlso <http://example.org/d2> http://example.org/d1 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; rdfs:label "Etna" . http://example.org/d2 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano. http://example.org/d3 dbpedia:Beerenberg  rdf:type umbel-sc:Volcano ; rdfs:label "Beerenberg"@en ; SPARQL queries are executed over an RDF dataset:  One default graph and  Zero or more named graphs (identified by an URI)
  • 35. + Graphs in RDF  Currently no official specification of named graphs in RDF  However, most RDF triple stores support them  Loading data into graphs in Jena, use “ng4j”
  • 36. + Named graphs in Jena, Example // Create a new graphset NamedGraphSet graphset = new NamedGraphSetImpl(); NamedGraph graph = graphset.createGraph("http://example.org/persons/123"); // Add information to the NamedGraph graph.add(new Triple(Node.createURI("http://richard.cyganiak.de/foaf.rdf#RichardCyganiak"), Node.createURI("http://xmlns.com/foaf/0.1/name") , Node.createLiteral("Richard Cyganiak", null, null))); // Create a quad Quad quad = new Quad(Node.createURI("http://www.bizer.de/InformationAboutRichard"), Node.createURI("http://richard.cyganiak.de/foaf.rdf#RichardCyganiak"), Node.createURI("http://xmlns.com/foaf/0.1/mbox") , Node.createURI("mailto:richard@cyganiak.de")); // Add the quad to the graphset. This will create a new NamedGraph in the // graphset. graphset.addQuad(quad);
  • 37. + Components of SPARQL Queries PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX umbel-sc: <http://umbel.org/umbel/sc/> SELECT ?v FROM <http://example.org/myGeoData> WHERE { ?v rdf:type umbel-sc:Volcano . } ORDER BY ?name  Dataset specification   Specify the RDF dataset to be queries (more on that later) Specification using FROM and FROM NAMED
  • 38. + Graph Graph Patterns Default graph dbpedia:Mount_Etna dbpedia:Mount_Baker rdfs:seeAlso <http://example.org/d1> rdfs:seeAlso <http://example.org/d2> http://example.org/d1 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; rdfs:label "Etna" . http://example.org/d2 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano. http://example.org/d3 dbpedia:Beerenberg rdf:type umbel-sc:Volcano ; rdfs:label "Beerenberg"@en ;  Evaluation of patterns w.r.t. the active graph  GRAPH clause for making a named graph the active graph
  • 39. + Graph Graph Patterns Default graph dbpedia:Mount_Etna dbpedia:Mount_Baker rdfs:seeAlso <http://example.org/d1> rdfs:seeAlso <http://example.org/d2> http://example.org/d1 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; rdfs:label "Etna" . http://example.org/d2 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano. http://example.org/d3 dbpedia:Beerenberg rdf:type umbel-sc:Volcano ; rdfs:label "Beerenberg"@en ; SELECT ?v WHERE { GRAPH ?g { ?v rdf:type umbel-sc:Volcano } } ?v dbpedia:Mount_Etna dbpedia:Mount_Baker dbpedia:Beerenberg
  • 40. + Graph Graph Patterns Default graph dbpedia:Mount_Etna dbpedia:Mount_Baker rdfs:seeAlso <http://example.org/d1> rdfs:seeAlso <http://example.org/d2> http://example.org/d1 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; rdfs:label "Etna" . http://example.org/d2 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano. http://example.org/d3 dbpedia:Beerenberg rdf:type umbel-sc:Volcano ; rdfs:label "Beerenberg"@en ; ?v SELECT ?v ?g WHERE { dbpedia:Mount_Etna GRAPH ?g { ?v rdf:type umbel-sc:Volcano } dbpedia:Mount_Baker } dbpedia:Beerenberg ?g <http://example.org/d1> <http://example.org/d2> <http://example.org/d3>
  • 41. + Graph Graph Patterns Default graph dbpedia:Mount_Etna dbpedia:Mount_Baker rdfs:seeAlso <http://example.org/d1> rdfs:seeAlso <http://example.org/d2> http://example.org/d1 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; rdfs:label "Etna" . http://example.org/d2 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano. http://example.org/d3 dbpedia:Beerenberg rdf:type umbel-sc:Volcano ; rdfs:label "Beerenberg"@en ; SELECT ?v WHERE { _:x rdfs:seeAlso ?g GRAPH ?g { ?v rdf:type umbel-sc:Volcano } } ?v dbpedia:Mount_Etna dbpedia:Mount_Baker
  • 42. + Negation dbpedia:Mount_Etna dbpedia:Mount_Baker dbpedia:Beerenberg  rdf:type umbel-sc:Volcano ; rdfs:label "Etna" . rdf:type umbel-sc:Volcano. rdf:type umbel-sc:Volcano, umbel-sc:NaturalElevation ; rdfs:label "Beerenberg"@en ; rdfs:label "Беренберг"@ru . What volcanos do not have a name in our data? SELECT ?v WHERE { ?v rdf:type umbel-sc:Volcano . OPTIONAL { ?v rdfs:label ?name } FILTER ( ! BOUND(?name) ) } ?v dbpedia:Mount_Baker Negation as failure
  • 43. + Negation dbpedia:Mount_Etna dbpedia:Mount_Baker dbpedia:Beerenberg  rdf:type umbel-sc:Volcano ; rdfs:label "Etna" . rdf:type umbel-sc:Volcano. rdf:type umbel-sc:Volcano, umbel-sc:NaturalElevation ; rdfs:label "Beerenberg"@en ; rdfs:label "Беренберг"@ru . What volcanos are not called “Beerenberg”? SELECT ?v WHERE { ?v rdf:type umbel-sc:Volcano ; rdfs:label ?name . FILTER ( STR(?name) != “Beerenberg” ) } } ?name dbpedia:Mount_Etna dbpedia:Mount_Baker dbpedia:Beerenberg
  • 44. + Negation dbpedia:Mount_Etna dbpedia:Mount_Baker dbpedia:Beerenberg  rdf:type umbel-sc:Volcano ; rdfs:label "Etna" . rdf:type umbel-sc:Volcano. rdf:type umbel-sc:Volcano, umbel-sc:NaturalElevation ; rdfs:label "Beerenberg"@en ; rdfs:label "Беренберг"@ru . What volcanos are not called “Beerenberg”? SELECT ?v WHERE { ?v rdf:type umbel-sc:Volcano ; OPTIONAL { ?v rdfs:label ?name . FILTER ( STR(?name) = “Beerenberg” ) } FILTER ( ! BOUND (?name) ) } ?name dbpedia:Mount_Etna dbpedia:Mount_Baker Negation as failure
  • 45. + Graph Graph Patterns Default graph dbpedia:Mount_Etna dbpedia:Mount_Baker rdfs:seeAlso <http://example.org/d1> rdfs:seeAlso <http://example.org/d2> http://example.org/d1 dbpedia:Mount_Etna rdf:type umbel-sc:Volcano ; rdfs:label "Etna" . http://example.org/d2 dbpedia:Mount_Baker rdf:type umbel-sc:Volcano. http://example.org/d3 SELECT ?g WHERE { GRAPH ?g { dbpedia:Beerenberg rdf:type umbel-sc:Volcano ; ?v rdf:type umble-sc:Volcano ; "Beerenberg"@en ; rdfs:label rdfs:label ?name .  Which named graphs contain the name of a volcano that is not } references rdfs:seeAlso graph OPTIONAL { ?vin the default?r } FILTER ( ! BOUND(?r) ) }
  • 46. + Summary – Graph Patterns  Different types of graph patterns for the query pattern (WHERE clause):  Basic graph pattern (BGP)  Group graph pattern  Optional graph pattern – keyword OPTIONAL  Union graph pattern – keyword UNION  Graph graph pattern – keyword GRAPH  Constraints – keyword FILTER
  • 47. + Components of SPARQL Queries PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX umbel-sc: <http://umbel.org/umbel/sc/> SELECT ?v FROM <http://example.org/myGeoData> WHERE { ?v rdf:type umbel-sc:Volcano . } ORDER BY ?name  Result form specification  SELECT, DESCRIBE, CONSTRUCT or ASK (more later)
  • 48. + Result Forms  SELECT   Selected variables separated by space (not by comma!)   Result: sequence of solutions (i.e. sets of variable bindings) Asterisk character (“*”) selects all variables in the pattern ASK  Check whether there is at least one result  Result: true or false  Example: Do we have data about volcanos? ASK WHERE { ?v rdf:type umble-sc:Volcano }
  • 49. + Result Forms  DESCRIBE  Result: an RDF graph with data about resources  Non-deterministic (i.e. query processor defines the actual structure of the resulting RDF graph)  Example: just name the resource DESCRIBE <http://dbpedia.org/resource/Beerenberg>  Possible to specify the resource by query pattern DESCRIBE ?v WHERE { ?v rdf:type umbel-sc:Volcano . }
  • 50. + Result Forms  CONSTRUCT  Result: an RDF graph constructed from a template  Template: graph pattern with variables from the query pattern CONSTRUCT { ?v rdfs:label ?name ; rdf:type myTypes:VolcanosOutsideTheUS } WHERE { ?v rdf:type umbel-sc:Volcano ; rdfs:label ?name . OPTIONAL { ?v p:location ?l FILTER ( ?l = dbpedia:United_States ) } FILTER ( ! BOUND(?l) ) }
  • 51. + Result Forms Data dbpedia:Mount_Etna dbpedia:Mount_Baker dbpedia:Beerenberg dbpedia:Mount_Etna dbpedia:Beerenberg rdf:type umbel-sc:Volcano ; rdfs:label "Etna” ; p:location dbpedia:Italy . rdf:type umbel-sc:Volcano ; rdfs:label ”Mount Baker” ; p:location dbpedia:United_States. rdf:type umbel-sc:Volcano, rdfs:label "Beerenberg"@en ; p:location dbpedia:Norway . rdfs:label "Etna” ; rdf:type myTypes:VolcanosOutsideTheUS rdfs:label "Beerenberg"@en ; rdf:type myTypes:VolcanosOutsideTheUS Result
  • 52. + Solution Modifiers PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX umbel-sc: <http://umbel.org/umbel/sc/> SELECT ?v FROM <http://example.org/myGeoData> WHERE { ?v rdf:type umbel-sc:Volcano . } ORDER BY ?name  Solution modifiers  Only for SELECT queries  Modify the result set as a whole (not single solutions)  Keywords: DISTINCT, ORDER BY, LIMIT, OFFSET
  • 53. + Solution Modifiers dbpedia:Mount_Etna dbpedia:Mount_Baker dbpedia:Beerenberg  rdf:type umbel-sc:Volcano ; rdfs:label "Etna" . rdf:type umbel-sc:Volcano. rdf:type umbel-sc:Volcano, umbel-sc:NaturalElevation ; rdfs:label "Beerenberg"@en ; rdfs:label "Беренберг"@ru . DISTINCT removes duplicates from the result set ?name SELECT ?type WHERE { _:x rdf:type ?type } umbel-sc:Volcano umbel-sc:Volcano umbel-sc:NaturalElevation umbel-sc:Volcano
  • 54. + Solution Modifiers dbpedia:Mount_Etna dbpedia:Mount_Baker dbpedia:Beerenberg  rdf:type umbel-sc:Volcano ; rdfs:label "Etna" . rdf:type umbel-sc:Volcano. rdf:type umbel-sc:Volcano, umbel-sc:NaturalElevation ; rdfs:label "Beerenberg"@en ; rdfs:label "Беренберг"@ru . DISTINCT removes duplicates from the result set ?name SELECT DISTINCT ?type WHERE { _:x rdf:type ?type } umbel-sc:Volcano umbel-sc:NaturalElevation
  • 55. + Solution Modifiers  ORDER BY orders the results SELECT ?v WHERE { ?v rdf:type umbel-sc:Volcano ; rdfs:label ?name } ORDER BY ?name  How do you order different kinds of elements?  unbound < blank node < URI < literal  ASC for ascending (default) and DESC for descending  Hierarchical order criteria SELECT ?name WHERE { ?v rdf:type umbel-sc:Volcano ; p:lastEruption ?le ; rdfs:label ?name } ORDER BY DESC(?le), ?name
  • 56. + Solution Modifiers  LIMIT – limits the number of result SELECT ?v WHERE { ?v rdf:type umbel-sc:Volcano ; rdfs:label ?name } ORDER BY ?name LIMIT 5  OFFSET – position/index of the first reported results SELECT ?v WHERE { ?v rdf:type umbel-sc:Volcano ; rdfs:label ?name } ORDER BY ?name LIMIT 5 OFFSET 10  Order of the result should be predictable (combine with ORDER BY)