0% found this document useful (0 votes)
54 views43 pages

Slide Semweb 7 Sparql

The document discusses SPARQL, the standard query language for retrieving and manipulating data stored in RDF format. It covers SPARQL basics like query types, triple patterns, filters, optional patterns, and unions. Specifically: 1) SPARQL allows querying RDF databases using patterns to match triples, with support for optional and union graph patterns. 2) Common query types in SPARQL include SELECT, CONSTRUCT, DESCRIBE and ASK. 3) Filters can be used to constrain pattern matching based on values, regular expressions or other conditions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views43 pages

Slide Semweb 7 Sparql

The document discusses SPARQL, the standard query language for retrieving and manipulating data stored in RDF format. It covers SPARQL basics like query types, triple patterns, filters, optional patterns, and unions. Specifically: 1) SPARQL allows querying RDF databases using patterns to match triples, with support for optional and union graph patterns. 2) Common query types in SPARQL include SELECT, CONSTRUCT, DESCRIBE and ASK. 3) Filters can be used to constrain pattern matching based on values, regular expressions or other conditions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 43

Web Science & Technologies

University of Koblenz Landau, Germany

SPARQL

Sergej Sizov

Semantic Web
Semantic Web Language Layer Cake

Existing standards
WeST Sergej Sizov Semantic Web
[email protected] 2
SPARQL

SPARQL Protocol and RDF Query Language

W3C Recommendation 15 January 2008


http://www.w3.org/TR/rdf-sparql-query/

Standard query language for RDF


Native RDF knowledge bases
Knowledge bases viewed as RDF via middleware
Language for querying for graph patterns
Includes unions, conjunctions and optional patterns
No support for inserts or updates
Supports extensible testing for values and constraints
WeST Sergej Sizov Semantic Web
[email protected] 3
SPARQL Query

Schemas used in query

PREFIX
SELECT Values to be returned

FROM
WHERE { }

Identify source data to query

Triple patterns and other


conditions to match the graph
WeST Sergej Sizov Semantic Web
[email protected] 4
SPARQL Query types

SELECT
returns the set of variables bound in a query pattern match

CONSTRUCT
returns an RDF graph constructed by substituting variables
in a set of triple templates

DESCRIBE
returns an RDF graph that describes the resources found

ASK
returns whether a query pattern matches any triples or not
True / False query

WeST Sergej Sizov Semantic Web


[email protected] 5
Basic SPARQL patterns

Triple Pattern
Similar to an RDF Triple
subject, predicate, object
Any component can be a query variable
Any combination of variables in the query is allowed

Matching patterns in the WHERE clause


Matching conjunction of Triple Patterns
Matching a triple pattern to a graph
Finding bindings between variables and RDF Terms
Underneath use of reasoners
Infering triples originally not present in the knowledge base

WeST Sergej Sizov Semantic Web


[email protected] 6
Simple SPQRQL Query

PREFIX foaf: <http://xmlns.com/foaf/0.1/>


SELECT ?name ?page
WHERE {
?person foaf:page ?page .
?person foaf:name ?name
}

foaf:page ?page

?person

foaf:name
?name

WeST Sergej Sizov Semantic Web


[email protected] 7
Query example
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
_:a foaf:name Steffen Staab" .
Data _:a foaf:homepage <http://www.uni-koblenz.de/~staab> .
_:b foaf:name Maciej Janik" .
_:b foaf:homepage <http://www.uni-koblenz.de/~janik> .

PREFIX foaf: <http://xmlns.com/foaf/0.1/>


SELECT ?name ?page
WHERE {
?person foaf:homepage ?page . Query
?person foaf:name ?name
}

name page

Query Result Steffen Staab" <http://www.uni-koblenz.de/~staab>

Maciej Janik" <http://www.uni-koblenz.de/~janik>

WeST Sergej Sizov Semantic Web


[email protected] 8
Querying for blank nodes
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
_:a foaf:name Steffen Staab" .
Data _:a foaf:homepage <http://www.uni-koblenz.de/~staab> .
_:b foaf:name Maciej Janik" .
_:b foaf:homepage <http://www.uni-koblenz.de/~janik> .

PREFIX foaf: <http://xmlns.com/foaf/0.1/>


SELECT ?person ?name ?page
WHERE {
?person foaf:homepage ?page . Query
?person foaf:name ?name
}

person name homepage


_:c Steffen Staab" <http://www.uni-koblenz.de/~staab>
Query Result
_:d Maciej Janik" <http://www.uni-koblenz.de/~janik>

WeST Sergej Sizov Semantic Web


[email protected] 9
Filters
FILTER
Further constrain graph patterns
Applies to the whole group of triple patterns

FILTER clause
Support for AND and OR logic operators
Extensive applications for testing literals
Support for numerical operations
Support for math equality operators for literals
Less than equal greater than
Use of regular expressions
Support for datatypes defined in XSL
e.g. comparison of dates, time
Possible comparison of resources
Equal or not equal
Even possible user extensions

WeST Sergej Sizov Semantic Web


[email protected] 10
Filter Value Constraints
@prefix dc: <http://purl.org/dc/elements/1.1/> .
@prefix ex: <http://example.org/book/> .
@prefix ns: <http://example.org/ns#> .
ex:book1 dc:title "SPARQL Tutorial" .
Data
ex:book1 ns:price 42 .
ex:book2 dc:title "The Semantic Web" .
ex:book2 ns:price 23 .

PREFIX dc: <http://purl.org/dc/elements/1.1/>


PREFIX ns: <http://example.org/ns#>
SELECT ?title ?price
Query
WHERE { ?x ns:price ?price .
FILTER ?price < 30 .
?x dc:title ?title }

title price
Query Result
"The Semantic Web" 23

WeST Sergej Sizov Semantic Web


[email protected] 11
Scope of filters

Filters are applied to the whole group of patterns where it


appears

{ ?x foaf:name ?name .
?x foaf:homepage ?page .
FILTER regex(?name, Steffen") }

{ ?x foaf:name ?name .
FILTER regex(?name, Steffen") .
?x foaf:homepage ?page }

{ FILTER regex(?name, Steffen") .


?x foaf:name ?name .
?x foaf:homepage ?page }

These patterns are equivalent have the same solution.

WeST Sergej Sizov Semantic Web


[email protected] 12
Filter regular expression
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
_:a foaf:name Steffen Staab" .
Data _:a foaf:homepage <http://www.uni-koblenz.de/~staab> .
_:b foaf:name Maciej Janik" .
_:b foaf:homepage <http://www.uni-koblenz.de/~janik> .

PREFIX foaf: <http://xmlns.com/foaf/0.1/>


SELECT ?name ?page
WHERE {
?person foaf:homepage ?page . Query
?person foaf:name ?name .
FILTER regex(?name, Steffen")
}

Query Result name page


Steffen Staab" <http://www.uni-koblenz.de/~staab>

WeST Sergej Sizov Semantic Web


[email protected] 13
Filter regular expression
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
_:a foaf:name Steffen Staab" .
Data _:a foaf:homepage <http://www.uni-koblenz.de/~staab> .
_:b foaf:name Maciej Janik" .
_:b foaf:homepage <http://www.uni-koblenz.de/~janik> .

PREFIX foaf: <http://xmlns.com/foaf/0.1/>


SELECT ?name ?page
WHERE {
?person foaf:homepage ?page . Query
?person foaf:name ?name .
FILTER regex(?name, i, janik")
} Case insensitive

Query Result name page


Maciej Janik" <http://www.uni-koblenz.de/~janik>

WeST Sergej Sizov Semantic Web


[email protected] 14
Optional patterns

OPTIONAL
Include optional triple patterns to the match
Optional is a pattern itself can include further constraints

SELECT
WHERE {

OPTIONAL { }
}

OPTIONAL is left-associative
pattern OPTIONAL { pattern } OPTIONAL { pattern }
is the same as
{ pattern OPTIONAL { pattern } } OPTIONAL { pattern }

WeST Sergej Sizov Semantic Web


[email protected] 15
Query example
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
_:a foaf:name Steffen Staab" .
Data _:a foaf:homepage <http://www.uni-koblenz.de/~staab> .
_:b foaf:name Maciej Janik" .
_:b foaf:mbox <[email protected]> .

PREFIX foaf: <http://xmlns.com/foaf/0.1/>


SELECT ?name ?page
WHERE {
?person foaf:name ?name . Query
?person foaf:homepage ?page
}

name page

Query Result Steffen Staab" <http://www.uni-koblenz.de/~staab>

WeST Sergej Sizov Semantic Web


[email protected] 16
Query example - OPTIONAL
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
_:a foaf:name Steffen Staab" .
Data _:a foaf:homepage <http://www.uni-koblenz.de/~staab> .
_:b foaf:name Maciej Janik" .
_:b foaf:mbox <[email protected]> .

PREFIX foaf: <http://xmlns.com/foaf/0.1/>


SELECT ?name ?page
WHERE {
?person foaf:name ?name . Query
OPTIONAL (?person foaf:homepage ?page)
}

name page

Query Result Steffen Staab" <http://www.uni-koblenz.de/~staab>

Maciej Janik"

WeST Sergej Sizov Semantic Web


[email protected] 17
Union of graph patterns

UNION
Combining alternative graph patterns
If more than one of the alternatives matches, all the
possible pattern solutions are included in result

SELECT
WHERE {
{ pattern }
UNION
{ pattern }
}

WeST Sergej Sizov Semantic Web


[email protected] 18
Union of graph patterns
@prefix dc10: <http://purl.org/dc/elements/1.0/> .
@prefix dc11: <http://purl.org/dc/elements/1.1/> .
:book1 dc10:title "SPARQL Tutorial" .
:book1 dc10:creator Alice .
Data :book2 dc11:title "The Semantic Web" .
:book2 dc11:creator Robert .

PREFIX dc10: <http://purl.org/dc/elements/1.0/>


PREFIX dc11: <http://purl.org/dc/elements/1.1/>
SELECT ?title Query
WHERE { { ?x dc10:title ?title }
UNION
{ ?x dc11:title ?title } }

title

Query Result SPARQL Tutorial


"The Semantic Web"
WeST Sergej Sizov Semantic Web
[email protected] 19
Modification to the result set

Result of SPARQL query can be further modified

ORDER BY
Sort results alphabetically / numerically by specific variable

LIMIT
Limit number of returned results (only top n results)

OFFSET
Skip n top results, and return the rest

These expressions can be combined in one query


WeST Sergej Sizov Semantic Web
[email protected] 20
Sequencing and limiting results

Results 11 to 30 sorted by name

PREFIX foaf: <http://xmlns.com/foaf/0.1/>


SELECT ?name ?page
WHERE {
?person foaf:homepage ?page .
?person foaf:name ?name
}
ORDERBY ?name
LIMIT 20
OFFSET 10

WeST Sergej Sizov Semantic Web


[email protected] 21
Bound variables

One of the FILTER expressions


Supports testing if a variable in a query can be bound to an
instance in the knowledge base
Mostly used for negation as failure

PREFIX foaf: < http://xmlns.com/foaf/0.1/>


SELECT ?name
WHERE {
?person foaf:name ?name .
OPTIONAL { ?person foaf:knows ?x . }
FILTER ( ! bound(?x))
}
WeST Sergej Sizov Semantic Web
[email protected] 22
Tricky negation

Find people who do not know Steffen


PREFIX foaf: < http://xmlns.com/foaf/0.1/>
SELECT ?name
WHERE {
?person foaf:name ?name .
?person foaf:knows ?x .
FILTER ( ?x != Steffen )
}
we know that
Maciej foaf:knows Steffen
Maciej foaf:knows Sergej
so Maciej is still a valid answer, and we do not want it.

WeST Sergej Sizov Semantic Web


[email protected] 23
Negation with bound

Find people who do not know Steffen


now the correct way using bound expression and optional
graph pattern

PREFIX foaf: < http://xmlns.com/foaf/0.1/>


SELECT ?name
WHERE {
?person foaf:name ?name .
OPTIONAL { ?person foaf:knows ?x .
FILTER ( ?x = Steffen ) }
FILTER ( ! bound(?x) ) }
}

WeST Sergej Sizov Semantic Web


[email protected] 24
Other SPARQL filter expressions

isBlank
Testing if bounded variable is a blank node
SELECT ?given ?family
annotation
WHERE { ?annot dc:creator ?c .
OPTIONAL { dc:creator
?c foaf:given ?given .
:_
?c foaf:family ?family }. foaf:given
foaf:family
FILTER isBlank(?c) }
Alan Smith
lang
Accessing the language of a literal
SELECT ?name ?mbox
WHERE { ?x foaf:name ?name .
?x foaf:mbox ?mbox .
FILTER ( lang(?name) = DE ) }

WeST Sergej Sizov Semantic Web


[email protected] 25
Other SPARQL filter expressions

isLiteral
Testing if bounded variable is a literal (not a resource)
SELECT ?name ?mbox
foaf:name Maciej
WHERE { ?x foaf:name ?name .
?x foaf:mbox ?mbox . :_
FILTER isLiteral(?mbox) }
foaf:mbox janik@

str
Converting resource URI to string for regular expression matching
SELECT ?name ?mbox
WHERE { ?x foaf:name ?name .
?x foaf:mbox ?mbox .
FILTER regex(str(?mbox), "@uni-koblenz.de") }

WeST Sergej Sizov Semantic Web


[email protected] 26
Equal terms and same terms
Check if two terms are equal or if they describe the same
entity
Same entity can have even different URIs, but conneced
with owl:sameAs

term1 = term2
or
sameTerm(term1, term2)

Returns true, if
terms are of the same type (URI, literal, blank node)
two terms represent URIs are equivalent
two terms represent literals are equivalent
two terms are bound by the same blank node
WeST Sergej Sizov Semantic Web
[email protected] 27
Equal terms

Find people who have the same email address, but use
different names
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
_:a foaf:name "Alice".
_:a foaf:mbox <mailto:[email protected]> .
_:b foaf:name "Ms A. .
_:b foaf:mbox <mailto:[email protected]> .

PREFIX foaf: <http://xmlns.com/foaf/0.1/>


SELECT ?name1 ?name2
WHERE {
?x foaf:name ?name1 .
?x foaf:mbox ?mbox1 .
?y foaf:name ?name2 .
?y foaf:mbox ?mbox2 .
FILTER ( sameTerm(mbox1, ?mbox2) && ?name1 != ?name2) }

WeST Sergej Sizov Semantic Web


[email protected] 28
User-defined functions
FILTER enables using user-defined expressions

PREFIX aGeo: <http://example.org/geo#>


SELECT ?neighbor WHERE {
?a aGeo:placeName Koblenz" .
?a aGeo:location ?axLoc .
?a aGeo:location ?ayLoc .
?b aGeo:placeName ?neighbor .
?b aGeo:location ?bxLoc .
?b aGeo:location ?byLoc .
FILTER
( aGeo:distance(?axLoc, ?ayLoc, ?bxLoc, ?byLoc) < 5 )
}

Definition of user function


Geometric distance between two points described by (x, y) coordinates
xsd:double aGeo:distance (numeric x1, numeric y1,
numeric x2, numeric y2)

WeST Sergej Sizov Semantic Web


[email protected] 29
Querying for inferred knowledge

SPARQL do not have specific constructs for accessing


inferred knowledge
Underlying knowledge base is responsible for supporting
inference, e.g.
Class hierarchy
Property hierarchy
Transitive or symmetric properties
OWL restrictions
Defining classes by unions and/or intersections
Different knowledge bases can offer different level of
support
Same knowledge in different knowledge bases may return
different results for the same query, depending on
supported entailment

WeST Sergej Sizov Semantic Web


[email protected] 30
Query example

ancestorOf ancestorOf

daugherOf sonOf
Alice Bob Clare

ancestorOf

ancestorOf = owl:transitiveProperty + union ( inverse(daugherOf), inverse(sonOf) )

Find ancestors of Alice

Query Result
SELECT ?x Clare
WHERE ?x ancestorOf Alice Bob

WeST Sergej Sizov Semantic Web


[email protected] 31
CONSTRUCT queries

Special type of query to construct a new RDF graph from


the existing knowledge base

PREFIX
CONSTRUCT
{
graph pattern
definition of triples
}
WHERE
{
constraint triple patterns, filters, etc
}
WeST Sergej Sizov Semantic Web
[email protected] 32
Constructing graphs
Data: Query:
@prefix foaf: PREFIX foaf:
<http://xmlns.com/foaf/0.1/> . <http://xmlns.com/foaf/0.1/>
_:a foaf:givenname "Alice" . PREFIX vcard:
_:a foaf:family_name "Hacker" . <http://www.w3.org/2001/vcard-
_:b foaf:firstname "Bob" . rdf/3.0#>
_:b foaf:surname "Hacker" . CONSTRUCT
{
?x vcard:N _:v .
_:v vcard:givenName ?gname .
_:v vcard:familyName ?fname
}
Result: WHERE
@prefix vcard: {
<http://www.w3.org/2001/vcard-rdf/3.0#> { UNION
?x foaf:firstname ?gname }
_:v1 vcard:N _:x . { ?x foaf:givenname ?gname } .
_:x vcard:givenName "Alice" . { ?x foaf:surname ?fname }
_:x vcard:familyName "Hacker" . UNION
_:v2 vcard:N _:z . { ?x foaf:family_name ?fname }
_:z vcard:givenName "Bob" . }
_:z vcard:familyName "Hacker" .

WeST Sergej Sizov Semantic Web


[email protected] 33
ASK queries

True / false queries checks if given set of triple patterns


have at least one match in knowledge base
Does not include ORDER BY, LIMIT or OFFSET
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
_:a foaf:name "Alice" .
_:a foaf:homepage <http://work.example.org/alice/> .
_:b foaf:name "Bob" .
_:b foaf:mbox <mailto:[email protected]>

PREFIX foaf: <http://xmlns.com/foaf/0.1/>


}
ASK { ?x foaf:name "Alice" .
?x foaf:mbox ?y }

YES
Answer: NO
WeST Sergej Sizov Semantic Web
[email protected] 34
DESCRIBE queries

Returns a graph that includes description of specific


resources

Results of DESCRIBE query reveal metainformation not


returned by standard SELECT query
Type of bounded resources
Types of relationships used in query pattern

Exact description of resources is determined by the query


service
No common standard of description
Can even include information about related resources

WeST Sergej Sizov Semantic Web


[email protected] 35
DESCRIBE query example

PREFIX ent: <http://org.example.com/employees#>


DESCRIBE ?x
WHERE { ?x ent:employeeId "1234" }

@prefix foaf: <http://xmlns.com/foaf/0.1/> .


@prefix vcard: <http://www.w3.org/2001/vcard-rdf/3.0> .
@prefix exOrg: <http://org.example.com/employees#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix owl: <http://www.w3.org/2002/07/owl#>

_:a exOrg:employeeId "1234" ;


foaf:mbox_sha1sum "ABCD1234" ;
vcard:N
[ vcard:Family "Smith" ;
vcard:Given "John" ] .

foaf:mbox_sha1sum rdf:type owl:InverseFunctionalProperty

WeST Sergej Sizov Semantic Web


[email protected] 36
Named Graphs

RDF data stores may hold multiple RDF graphs:


record information about each graph
queries that involve information from more than one graph
default graph (does not have a name)
multiple named graphs (identified by URI reference)
direct implementation for reification

Accessing named graphs


FROM
access knowledge in default graph
FROM NAMED
access information from specific named graph

WeST Sergej Sizov Semantic Web


[email protected] 37
Ad hoc-Reification (direct)

Kant examined Jonas in Introduction to CS and gave him


grade 1.0
s:jonas/#me

s:examinee

s:examiner s:in
s:kant/#me s:exam1 s:introCS

s:grade

1.0

WeST Sergej Sizov Semantic Web


[email protected] 38
Named Graph as reification

Kant examined Jonas in Introduction to CS and gave him


grade 1.0

s:JonasGraph

s:jonas/#me

s:examinedIn

s:Stud2Graph
s:kant/#me s:introCS
s:examinedBy

s:grade

1.0

WeST Sergej Sizov Semantic Web


[email protected] 39
Named graph examples
# Default graph (http://example.org/friends)
@prefix dc: <http://purl.org/dc/elements/1.1/> .
<http://example.org/bob> dc:publisher "Bob" .
<http://example.org/alice> dc:publisher "Alice" .
# Graph: http://example.org/bob
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
_:a foaf:name "Bob" .
_:a foaf:mbox <mailto:[email protected]> .
# Graph: http://example.org/alice
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
_:a foaf:name "Alice" .
_:a foaf:mbox <mailto:[email protected]> .

SELECT ...
FROM NAMED <http://example.org/alice>
FROM NAMED <http://example.org/bob>
...
WeST Sergej Sizov Semantic Web
[email protected] 40
Relationships between named graphs

# Default graph
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
_:y foaf:name "Alice" .
_:y foaf:mbox <mailto:[email protected]> .
_:y foaf:mbox <mailto:[email protected]> .

# Graph: http://example.org/alice
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
_:a foaf:name Alice" .
_:a foaf:mbox <mailto:[email protected]> .

# Graph: http://example.org/alice_prev
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
_:a foaf:name "Alice" .
_:a foaf:mbox <mailto:[email protected]> .

WeST Sergej Sizov Semantic Web


[email protected] 41
Accessing named graphs
# Graph: http://example.org/alice
_:a foaf:name Alice" .
_:a foaf:mbox <mailto:[email protected]> .
# Graph: http://example.org/alice_prev
_:a foaf:name "Alice" .
_:a foaf:mbox <mailto:[email protected]> .

SELECT ?src ?mbox


WHERE {
GRAPH ?src
{ ?x foaf:name Alice .
?x foaf:mbox ?mbox
Result:
}
} src mbox
http://example.org/alice mailto:[email protected]
http://example.org/alice_prev mailto:[email protected]
WeST Sergej Sizov Semantic Web
[email protected] 42
Restricting access by graph name
# Graph: http://example.org/alice
_:a foaf:name Alice" .
_:a foaf:mbox <mailto:[email protected]> .
# Graph: http://example.org/alice_prev
_:a foaf:name "Alice" .
_:a foaf:mbox <mailto:[email protected]> .

PREFIX ex: <http://example.org/>


SELECT ?mbox
WHERE {
GRAPH ex:alice
{ ?x foaf:mbox ?mbox }
} Result:

mbox
mailto:[email protected]

WeST Sergej Sizov Semantic Web


[email protected] 43

You might also like