Page 1
SPARQL Formalization
Marcelo Arenas, Claudio Gutierrez, Jorge Perez
Department of Computer SciencePontificia Universidad Catolica de Chile
Universidad de Chile
Center for Web Researchhttp://www.cwr.cl
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 1 / 34
Page 2
SPARQL: A simple RDF query language
SELECT ?Name ?Email
WHERE
{
?X :name ?Name
?X :email ?Email
}
◮ The semantics of simple SPARQL queries is easy tounderstand, at least intuitively.
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 2 / 34
Page 3
SPARQL: A simple RDF query language
SELECT ?Name ?Email
WHERE
{
?X :name ?Name
?X :email ?Email
}
◮ The semantics of simple SPARQL queries is easy tounderstand, at least intuitively.
“Give me the name and email of the
resources in the datasource”
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 2 / 34
Page 4
But things can become more complex...
Interesting features of patternmatching on graphs
◮ Grouping
◮ Optional parts
◮ Nesting
◮ Union of patterns
◮ Filtering
◮ .....
{ P1
P2 }
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 3 / 34
Page 5
But things can become more complex...
Interesting features of patternmatching on graphs
◮ Grouping
◮ Optional parts
◮ Nesting
◮ Union of patterns
◮ Filtering
◮ .....
{ { P1
P2 }
{ P3
P4 }
}
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 3 / 34
Page 6
But things can become more complex...
Interesting features of patternmatching on graphs
◮ Grouping
◮ Optional parts
◮ Nesting
◮ Union of patterns
◮ Filtering
◮ .....
{ { P1
P2
OPTIONAL { P5 } }
{ P3
P4
OPTIONAL { P7 } }
}
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 3 / 34
Page 7
But things can become more complex...
Interesting features of patternmatching on graphs
◮ Grouping
◮ Optional parts
◮ Nesting
◮ Union of patterns
◮ Filtering
◮ .....
{ { P1
P2
OPTIONAL { P5 } }
{ P3
P4
OPTIONAL { P7
OPTIONAL { P8 } } }
}
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 3 / 34
Page 8
But things can become more complex...
Interesting features of patternmatching on graphs
◮ Grouping
◮ Optional parts
◮ Nesting
◮ Union of patterns
◮ Filtering
◮ .....
{ { P1
P2
OPTIONAL { P5 } }
{ P3
P4
OPTIONAL { P7
OPTIONAL { P8 } } }
}
UNION
{ P9 }
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 3 / 34
Page 9
But things can become more complex...
Interesting features of patternmatching on graphs
◮ Grouping
◮ Optional parts
◮ Nesting
◮ Union of patterns
◮ Filtering
◮ .....
{ { P1
P2
OPTIONAL { P5 } }
{ P3
P4
OPTIONAL { P7
OPTIONAL { P8 } } }
}
UNION
{ P9
FILTER ( R ) }
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 3 / 34
Page 10
But things can become more complex...
Interesting features of patternmatching on graphs
◮ Grouping
◮ Optional parts
◮ Nesting
◮ Union of patterns
◮ Filtering
◮ .....
{ { P1
P2
OPTIONAL { P5 } }
{ P3
P4
OPTIONAL { P7
OPTIONAL { P8 } } }
}
UNION
{ P9
FILTER ( R ) }
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 3 / 34
Page 11
A formal semantics for SPARQL is needed.
A formal approach would be beneficial
◮ Clarifying corner cases
◮ Helping in the implementation process
◮ Providing sound foundations
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 4 / 34
Page 12
A formal semantics for SPARQL is needed.
A formal approach would be beneficial
◮ Clarifying corner cases
◮ Helping in the implementation process
◮ Providing sound foundations
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 4 / 34
Page 13
A formal semantics for SPARQL is needed.
A formal approach would be beneficial
◮ Clarifying corner cases
◮ Helping in the implementation process
◮ Providing sound foundations
We will see:
◮ A formal compositional semantics based on[PAG06: Semantics and Complexity of SPARQL]
◮ This formalization is the starting point of the officialsemantics of the SPARQL language by the W3C.
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 4 / 34
Page 14
Outline
Motivation
Basic Syntax
Semantics
Datasets
Query result forms
Dealing with bnodes
Dealing with duplicates
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 5 / 34
Page 15
First of all, a simplified algebraic syntax
◮ Triple patterns: RDF triple + variables (no bnodes for now)
(?X , name, ?Name)
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 6 / 34
Page 16
First of all, a simplified algebraic syntax
◮ Triple patterns: RDF triple + variables (no bnodes for now)
(?X , name, ?Name)
◮ The base case for the algebra is a set of triple patterns
{t1, t2, . . . , tk}.
This is called basic graph pattern (BGP).
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 6 / 34
Page 17
First of all, a simplified algebraic syntax
◮ Triple patterns: RDF triple + variables (no bnodes for now)
(?X , name, ?Name)
◮ The base case for the algebra is a set of triple patterns
{t1, t2, . . . , tk}.
This is called basic graph pattern (BGP).
Example
{ (?X , name, ?Name), (?X , email, ?Email) }
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 6 / 34
Page 18
First of all, a simplified algebraic syntax (cont.)
◮ We consider initially three basic operators:
AND, UNION, OPT.
◮ We will use them to construct graph pattern expressions frombasic graph patterns.
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 7 / 34
Page 19
First of all, a simplified algebraic syntax (cont.)
◮ We consider initially three basic operators:
AND, UNION, OPT.
◮ We will use them to construct graph pattern expressions frombasic graph patterns.
◮ A SPARQL graph pattern:
((({t1, t2} AND t3) OPT {t4, t5}) AND (t6 UNION {t7, t8}))
it is a full parenthesized expression
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 7 / 34
Page 20
First of all, a simplified algebraic syntax (cont.)
◮ We consider initially three basic operators:
AND, UNION, OPT.
◮ We will use them to construct graph pattern expressions frombasic graph patterns.
◮ A SPARQL graph pattern:
((({t1, t2} AND t3) OPT {t4, t5}) AND (t6 UNION {t7, t8}))
it is a full parenthesized expression
◮ Full parenthesized expressions give us explicitprecedence/association.
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 7 / 34
Page 21
Mappings: building block for the semantics
Definition
A mapping is a partial function from variables to RDF terms.
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 8 / 34
Page 22
Mappings: building block for the semantics
Definition
A mapping is a partial function from variables to RDF terms.
Given a mapping µ and a basic graph pattern P :
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 8 / 34
Page 23
Mappings: building block for the semantics
Definition
A mapping is a partial function from variables to RDF terms.
Given a mapping µ and a basic graph pattern P :
◮ dom(µ): the domain of µ.
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 8 / 34
Page 24
Mappings: building block for the semantics
Definition
A mapping is a partial function from variables to RDF terms.
Given a mapping µ and a basic graph pattern P :
◮ dom(µ): the domain of µ.
◮ µ(P): the set obtained from P replacing the variablesaccording to µ
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 8 / 34
Page 25
Mappings: building block for the semantics
Definition
A mapping is a partial function from variables to RDF terms.
Given a mapping µ and a basic graph pattern P :
◮ dom(µ): the domain of µ.
◮ µ(P): the set obtained from P replacing the variablesaccording to µ
Example
µ = {?X → R1, ?Y → R2, ?Name → john, ?Email → [email protected] }
P = {(?X , name, ?Name), (?X , email, ?Email)}
µ(P) = {(R1, name, john), (R1, email, [email protected] )}
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 8 / 34
Page 26
Mappings: building block for the semantics
Definition
A mapping is a partial function from variables to RDF terms.
Given a mapping µ and a basic graph pattern P :
◮ dom(µ): the domain of µ.
◮ µ(P): the set obtained from P replacing the variablesaccording to µ
Example
µ = {?X → R1, ?Y → R2, ?Name → john, ?Email → [email protected] }
P = {(?X , name, ?Name), (?X , email, ?Email)}
µ(P) = {(R1, name, john), (R1, email, [email protected] )}
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 8 / 34
Page 27
Mappings: building block for the semantics
Definition
A mapping is a partial function from variables to RDF terms.
Given a mapping µ and a basic graph pattern P :
◮ dom(µ): the domain of µ.
◮ µ(P): the set obtained from P replacing the variablesaccording to µ
Example
µ = {?X → R1, ?Y → R2, ?Name → john, ?Email → [email protected] }
P = {(?X , name, ?Name), (?X , email, ?Email)}
µ(P) = {(R1, name, john), (R1, email, [email protected] )}
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 8 / 34
Page 28
Mappings: building block for the semantics
Definition
A mapping is a partial function from variables to RDF terms.
Given a mapping µ and a basic graph pattern P :
◮ dom(µ): the domain of µ.
◮ µ(P): the set obtained from P replacing the variablesaccording to µ
Example
µ = {?X → R1, ?Y → R2, ?Name → john, ?Email → [email protected] }
P = {(?X , name, ?Name), (?X , email, ?Email)}
µ(P) = {(R1, name, john), (R1, email, [email protected] )}
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 8 / 34
Page 29
The semantics of basic graph pattern
Definition
The evaluation of the BGP P over a graph G , denoted by [[P ]]G , isthe set of all mappings µ such that:
◮ dom(µ) is exactly the set of variables occurring in P
◮ µ(P) ⊆ G
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 9 / 34
Page 30
The semantics of basic graph pattern
Definition
The evaluation of the BGP P over a graph G , denoted by [[P ]]G , isthe set of all mappings µ such that:
◮ dom(µ) is exactly the set of variables occurring in P
◮ µ(P) ⊆ G
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 9 / 34
Page 31
The semantics of basic graph pattern
Definition
The evaluation of the BGP P over a graph G , denoted by [[P ]]G , isthe set of all mappings µ such that:
◮ dom(µ) is exactly the set of variables occurring in P
◮ µ(P) ⊆ G
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 9 / 34
Page 32
Example
G(R1, name, john)
(R1, email, [email protected] )(R2, name, paul)
[[{(?X , name, ?Y )}]]G
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 10 / 34
Page 33
Example
G(R1, name, john)
(R1, email, [email protected] )(R2, name, paul)
[[{(?X , name, ?Y )}]]G{
µ1 = {?X → R1, ?Y → john}µ2 = {?X → R2, ?Y → paul}
}
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 10 / 34
Page 34
Example
G(R1, name, john)
(R1, email, [email protected] )(R2, name, paul)
[[{(?X , name, ?Y )}]]G{
µ1 = {?X → R1, ?Y → john}µ2 = {?X → R2, ?Y → paul}
}
[[{(?X , name, ?Y ), (?X , email, ?E )}]]G
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 10 / 34
Page 35
Example
G(R1, name, john)
(R1, email, [email protected] )(R2, name, paul)
[[{(?X , name, ?Y )}]]G{
µ1 = {?X → R1, ?Y → john}µ2 = {?X → R2, ?Y → paul}
}
[[{(?X , name, ?Y ), (?X , email, ?E )}]]G{
µ = {?X → R1, ?Y → john, ?E → [email protected] }}
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 10 / 34
Page 36
Example
G(R1, name, john)
(R1, email, [email protected] )(R2, name, paul)
[[{(?X , name, ?Y )}]]G
?X ?Yµ1 R1 johnµ2 R2 paul
[[{(?X , name, ?Y ), (?X , email, ?E )}]]G
?X ?Y ?Eµ R1 john [email protected]
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 10 / 34
Page 37
Example
G(R1, name, john)
(R1, email, [email protected] )(R2, name, paul)
[[{(R1, webPage, ?W )}]]G
[[{(R2, name, paul)}]]G
[[{(R3, name, ringo)}]]G
[[{ }]]G
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 11 / 34
Page 38
Example
G(R1, name, john)
(R1, email, [email protected] )(R2, name, paul)
[[{(R1, webPage, ?W )}]]G{ }
[[{(R2, name, paul)}]]G
[[{(R3, name, ringo)}]]G
[[{ }]]G
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 11 / 34
Page 39
Example
G(R1, name, john)
(R1, email, [email protected] )(R2, name, paul)
[[{(R1, webPage, ?W )}]]G{ }
[[{(R2, name, paul)}]]G
[[{(R3, name, ringo)}]]G{ }
[[{ }]]G
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 11 / 34
Page 40
Example
G(R1, name, john)
(R1, email, [email protected] )(R2, name, paul)
[[{(R1, webPage, ?W )}]]G{ }
[[{(R2, name, paul)}]]G{
µ∅ = { }}
[[{(R3, name, ringo)}]]G{ }
[[{ }]]G
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 11 / 34
Page 41
Example
G(R1, name, john)
(R1, email, [email protected] )(R2, name, paul)
[[{(R1, webPage, ?W )}]]G{ }
[[{(R2, name, paul)}]]G{
µ∅ = { }}
[[{(R3, name, ringo)}]]G{ }
[[{ }]]G{
µ∅ = { }}
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 11 / 34
Page 42
Compatible mappings: mappings that can be merged.
Definition
The mappings µ1, µ2 are compatibles iff they agreein their shared variables:
◮ µ1(?X ) = µ2(?X ) for every ?X ∈ dom(µ1) ∩ dom(µ2).
µ1 ∪ µ2 is also a mapping.
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 12 / 34
Page 43
Compatible mappings: mappings that can be merged.
Definition
The mappings µ1, µ2 are compatibles iff they agreein their shared variables:
◮ µ1(?X ) = µ2(?X ) for every ?X ∈ dom(µ1) ∩ dom(µ2).
µ1 ∪ µ2 is also a mapping.
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 12 / 34
Page 44
Compatible mappings: mappings that can be merged.
Definition
The mappings µ1, µ2 are compatibles iff they agreein their shared variables:
◮ µ1(?X ) = µ2(?X ) for every ?X ∈ dom(µ1) ∩ dom(µ2).
µ1 ∪ µ2 is also a mapping.
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 12 / 34
Page 45
Compatible mappings: mappings that can be merged.
Definition
The mappings µ1, µ2 are compatibles iff they agreein their shared variables:
◮ µ1(?X ) = µ2(?X ) for every ?X ∈ dom(µ1) ∩ dom(µ2).
µ1 ∪ µ2 is also a mapping.
Example
?X ?Y ?U ?Vµ1 R1 johnµ2 R1 [email protected] µ3 [email protected] R2
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 12 / 34
Page 46
Compatible mappings: mappings that can be merged.
Definition
The mappings µ1, µ2 are compatibles iff they agreein their shared variables:
◮ µ1(?X ) = µ2(?X ) for every ?X ∈ dom(µ1) ∩ dom(µ2).
µ1 ∪ µ2 is also a mapping.
Example
?X ?Y ?U ?Vµ1 R1 johnµ2 R1 [email protected] µ3 [email protected] R2
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 12 / 34
Page 47
Compatible mappings: mappings that can be merged.
Definition
The mappings µ1, µ2 are compatibles iff they agreein their shared variables:
◮ µ1(?X ) = µ2(?X ) for every ?X ∈ dom(µ1) ∩ dom(µ2).
µ1 ∪ µ2 is also a mapping.
Example
?X ?Y ?U ?Vµ1 R1 johnµ2 R1 [email protected] µ3 [email protected] R2
µ1 ∪ µ2 R1 john [email protected]
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 12 / 34
Page 48
Compatible mappings: mappings that can be merged.
Definition
The mappings µ1, µ2 are compatibles iff they agreein their shared variables:
◮ µ1(?X ) = µ2(?X ) for every ?X ∈ dom(µ1) ∩ dom(µ2).
µ1 ∪ µ2 is also a mapping.
Example
?X ?Y ?U ?Vµ1 R1 johnµ2 R1 [email protected] µ3 [email protected] R2
µ1 ∪ µ2 R1 john [email protected]
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 12 / 34
Page 49
Compatible mappings: mappings that can be merged.
Definition
The mappings µ1, µ2 are compatibles iff they agreein their shared variables:
◮ µ1(?X ) = µ2(?X ) for every ?X ∈ dom(µ1) ∩ dom(µ2).
µ1 ∪ µ2 is also a mapping.
Example
?X ?Y ?U ?Vµ1 R1 johnµ2 R1 [email protected] µ3 [email protected] R2
µ1 ∪ µ2 R1 john [email protected] µ1 ∪ µ3 R1 john [email protected] R2
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 12 / 34
Page 50
Compatible mappings: mappings that can be merged.
Definition
The mappings µ1, µ2 are compatibles iff they agreein their shared variables:
◮ µ1(?X ) = µ2(?X ) for every ?X ∈ dom(µ1) ∩ dom(µ2).
µ1 ∪ µ2 is also a mapping.
Example
?X ?Y ?U ?Vµ1 R1 johnµ2 R1 [email protected] µ3 [email protected] R2
µ1 ∪ µ2 R1 john [email protected] µ1 ∪ µ3 R1 john [email protected] R2
µ∅ = { } is compatible with every mapping.
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 12 / 34
Page 51
Sets of mappings and operations
Let M1 and M2 be sets of mappings:
Definition
Join: M1 M2
◮ {µ1 ∪ µ2 | µ1 ∈ M1, µ2 ∈ M2, and µ1, µ2 are compatibles}
◮ extending mappings in M1 with compatible mappings in M2
will be used to define AND
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 13 / 34
Page 52
Sets of mappings and operations
Let M1 and M2 be sets of mappings:
Definition
Join: M1 M2
◮ {µ1 ∪ µ2 | µ1 ∈ M1, µ2 ∈ M2, and µ1, µ2 are compatibles}
◮ extending mappings in M1 with compatible mappings in M2
will be used to define AND
Definition
Union: M1 ∪ M2
◮ {µ | µ ∈ M1 or µ ∈ M2}
◮ mappings in M1 plus mappings in M2 (the usual set union)
will be used to define UNION
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 13 / 34
Page 53
Sets of mappings and operations
Definition
Difference: M1 r M2
◮ {µ ∈ M1 | for all µ′ ∈ M2, µ and µ′ are not compatibles}
◮ mappings in M1 that cannot be extended with mappings in M2
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 14 / 34
Page 54
Sets of mappings and operations
Definition
Difference: M1 r M2
◮ {µ ∈ M1 | for all µ′ ∈ M2, µ and µ′ are not compatibles}
◮ mappings in M1 that cannot be extended with mappings in M2
Definition
Left outer join: M1 M2 = (M1 M2) ∪ (M1 r M2)
◮ extension of mappings in M1 with compatible mappings in M2
◮ plus the mappings in M1 that cannot be extended.
will be used to define OPT
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 14 / 34
Page 55
Semantics of general graph patterns
Definition
Given a graph G the evaluation of a pattern is recursively defined
the base case is the evaluation of a BGP.
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 15 / 34
Page 56
Semantics of general graph patterns
Definition
Given a graph G the evaluation of a pattern is recursively defined
◮ [[(P1 AND P2)]]G = [[P1]]G [[P2]]G
the base case is the evaluation of a BGP.
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 15 / 34
Page 57
Semantics of general graph patterns
Definition
Given a graph G the evaluation of a pattern is recursively defined
◮ [[(P1 AND P2)]]G = [[P1]]G [[P2]]G
◮ [[(P1 UNION P2)]]G = [[P1]]G ∪ [[P2]]G
the base case is the evaluation of a BGP.
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 15 / 34
Page 58
Semantics of general graph patterns
Definition
Given a graph G the evaluation of a pattern is recursively defined
◮ [[(P1 AND P2)]]G = [[P1]]G [[P2]]G
◮ [[(P1 UNION P2)]]G = [[P1]]G ∪ [[P2]]G
◮ [[(P1 OPT P2)]]G = [[P1]]G [[P2]]G
the base case is the evaluation of a BGP.
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 15 / 34
Page 59
Example (AND)
G :(R1, name, john) (R2, name, paul) (R3, name, ringo)(R1, email, [email protected] ) (R3, email, [email protected] )
(R3, webPage, www.ringo.com)
[[{(?X , name, ?N)} AND {(?X , email, ?E )}]]G
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 16 / 34
Page 60
Example (AND)
G :(R1, name, john) (R2, name, paul) (R3, name, ringo)(R1, email, [email protected] ) (R3, email, [email protected] )
(R3, webPage, www.ringo.com)
[[{(?X , name, ?N)} AND {(?X , email, ?E )}]]G
[[{(?X , name, ?N)}]]G [[{(?X , email, ?E )}]]G
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 16 / 34
Page 61
Example (AND)
G :(R1, name, john) (R2, name, paul) (R3, name, ringo)(R1, email, [email protected] ) (R3, email, [email protected] )
(R3, webPage, www.ringo.com)
[[{(?X , name, ?N)} AND {(?X , email, ?E )}]]G
[[{(?X , name, ?N)}]]G [[{(?X , email, ?E )}]]G
?X ?Nµ1 R1 johnµ2 R2 paulµ3 R3 ringo
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 16 / 34
Page 62
Example (AND)
G :(R1, name, john) (R2, name, paul) (R3, name, ringo)(R1, email, [email protected] ) (R3, email, [email protected] )
(R3, webPage, www.ringo.com)
[[{(?X , name, ?N)} AND {(?X , email, ?E )}]]G
[[{(?X , name, ?N)}]]G [[{(?X , email, ?E )}]]G
?X ?Nµ1 R1 johnµ2 R2 paulµ3 R3 ringo
?X ?Eµ4 R1 [email protected] µ5 R3 [email protected]
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 16 / 34
Page 63
Example (AND)
G :(R1, name, john) (R2, name, paul) (R3, name, ringo)(R1, email, [email protected] ) (R3, email, [email protected] )
(R3, webPage, www.ringo.com)
[[{(?X , name, ?N)} AND {(?X , email, ?E )}]]G
[[{(?X , name, ?N)}]]G [[{(?X , email, ?E )}]]G
?X ?Nµ1 R1 johnµ2 R2 paulµ3 R3 ringo
?X ?Eµ4 R1 [email protected] µ5 R3 [email protected]
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 16 / 34
Page 64
Example (AND)
G :(R1, name, john) (R2, name, paul) (R3, name, ringo)(R1, email, [email protected] ) (R3, email, [email protected] )
(R3, webPage, www.ringo.com)
[[{(?X , name, ?N)} AND {(?X , email, ?E )}]]G
[[{(?X , name, ?N)}]]G [[{(?X , email, ?E )}]]G
?X ?Nµ1 R1 johnµ2 R2 paulµ3 R3 ringo
?X ?Eµ4 R1 [email protected] µ5 R3 [email protected]
?X ?N ?Eµ1 ∪ µ4 R1 john [email protected] µ3 ∪ µ5 R3 ringo [email protected]
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 16 / 34
Page 65
Example (OPT)
G :(R1, name, john) (R2, name, paul) (R3, name, ringo)(R1, email, [email protected] ) (R3, email, [email protected] )
(R3, webPage, www.ringo.com)
[[{(?X , name, ?N)} OPT {(?X , email, ?E )}]]G
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 17 / 34
Page 66
Example (OPT)
G :(R1, name, john) (R2, name, paul) (R3, name, ringo)(R1, email, [email protected] ) (R3, email, [email protected] )
(R3, webPage, www.ringo.com)
[[{(?X , name, ?N)} OPT {(?X , email, ?E )}]]G
[[{(?X , name, ?N)}]]G [[{(?X , email, ?E )}]]G
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 17 / 34
Page 67
Example (OPT)
G :(R1, name, john) (R2, name, paul) (R3, name, ringo)(R1, email, [email protected] ) (R3, email, [email protected] )
(R3, webPage, www.ringo.com)
[[{(?X , name, ?N)} OPT {(?X , email, ?E )}]]G
[[{(?X , name, ?N)}]]G [[{(?X , email, ?E )}]]G
?X ?Nµ1 R1 johnµ2 R2 paulµ3 R3 ringo
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 17 / 34
Page 68
Example (OPT)
G :(R1, name, john) (R2, name, paul) (R3, name, ringo)(R1, email, [email protected] ) (R3, email, [email protected] )
(R3, webPage, www.ringo.com)
[[{(?X , name, ?N)} OPT {(?X , email, ?E )}]]G
[[{(?X , name, ?N)}]]G [[{(?X , email, ?E )}]]G
?X ?Nµ1 R1 johnµ2 R2 paulµ3 R3 ringo
?X ?Eµ4 R1 [email protected] µ5 R3 [email protected]
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 17 / 34
Page 69
Example (OPT)
G :(R1, name, john) (R2, name, paul) (R3, name, ringo)(R1, email, [email protected] ) (R3, email, [email protected] )
(R3, webPage, www.ringo.com)
[[{(?X , name, ?N)} OPT {(?X , email, ?E )}]]G
[[{(?X , name, ?N)}]]G [[{(?X , email, ?E )}]]G
?X ?Nµ1 R1 johnµ2 R2 paulµ3 R3 ringo
?X ?Eµ4 R1 [email protected] µ5 R3 [email protected]
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 17 / 34
Page 70
Example (OPT)
G :(R1, name, john) (R2, name, paul) (R3, name, ringo)(R1, email, [email protected] ) (R3, email, [email protected] )
(R3, webPage, www.ringo.com)
[[{(?X , name, ?N)} OPT {(?X , email, ?E )}]]G
[[{(?X , name, ?N)}]]G [[{(?X , email, ?E )}]]G
?X ?Nµ1 R1 johnµ2 R2 paulµ3 R3 ringo
?X ?Eµ4 R1 [email protected] µ5 R3 [email protected]
?X ?N ?Eµ1 ∪ µ4 R1 john [email protected] µ3 ∪ µ5 R3 ringo [email protected]
µ2 R2 paul
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 17 / 34
Page 71
Example (OPT)
G :(R1, name, john) (R2, name, paul) (R3, name, ringo)(R1, email, [email protected] ) (R3, email, [email protected] )
(R3, webPage, www.ringo.com)
[[{(?X , name, ?N)} OPT {(?X , email, ?E )}]]G
[[{(?X , name, ?N)}]]G [[{(?X , email, ?E )}]]G
?X ?Nµ1 R1 johnµ2 R2 paulµ3 R3 ringo
?X ?Eµ4 R1 [email protected] µ5 R3 [email protected]
?X ?N ?Eµ1 ∪ µ4 R1 john [email protected] µ3 ∪ µ5 R3 ringo [email protected]
µ2 R2 paul
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 17 / 34
Page 72
Example (UNION)
G :(R1, name, john) (R2, name, paul) (R3, name, ringo)(R1, email, [email protected] ) (R3, email, [email protected] )
(R3, webPage, www.ringo.com)
[[{(?X , email, ?Info)} UNION {(?X , webPage, ?Info)}]]G
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 18 / 34
Page 73
Example (UNION)
G :(R1, name, john) (R2, name, paul) (R3, name, ringo)(R1, email, [email protected] ) (R3, email, [email protected] )
(R3, webPage, www.ringo.com)
[[{(?X , email, ?Info)} UNION {(?X , webPage, ?Info)}]]G
[[{(?X , email, ?Info)}]]G ∪ [[{(?X , webPage, ?Info)}]]G
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 18 / 34
Page 74
Example (UNION)
G :(R1, name, john) (R2, name, paul) (R3, name, ringo)(R1, email, [email protected] ) (R3, email, [email protected] )
(R3, webPage, www.ringo.com)
[[{(?X , email, ?Info)} UNION {(?X , webPage, ?Info)}]]G
[[{(?X , email, ?Info)}]]G ∪ [[{(?X , webPage, ?Info)}]]G
?X ?Info
µ1 R1 [email protected] µ2 R3 [email protected]
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 18 / 34
Page 75
Example (UNION)
G :(R1, name, john) (R2, name, paul) (R3, name, ringo)(R1, email, [email protected] ) (R3, email, [email protected] )
(R3, webPage, www.ringo.com)
[[{(?X , email, ?Info)} UNION {(?X , webPage, ?Info)}]]G
[[{(?X , email, ?Info)}]]G ∪ [[{(?X , webPage, ?Info)}]]G
?X ?Info
µ1 R1 [email protected] µ2 R3 [email protected]
?X ?Info
µ3 R3 www.ringo.com
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 18 / 34
Page 76
Example (UNION)
G :(R1, name, john) (R2, name, paul) (R3, name, ringo)(R1, email, [email protected] ) (R3, email, [email protected] )
(R3, webPage, www.ringo.com)
[[{(?X , email, ?Info)} UNION {(?X , webPage, ?Info)}]]G
[[{(?X , email, ?Info)}]]G ∪ [[{(?X , webPage, ?Info)}]]G
?X ?Info
µ1 R1 [email protected] µ2 R3 [email protected]
∪?X ?Info
µ3 R3 www.ringo.com
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 18 / 34
Page 77
Example (UNION)
G :(R1, name, john) (R2, name, paul) (R3, name, ringo)(R1, email, [email protected] ) (R3, email, [email protected] )
(R3, webPage, www.ringo.com)
[[{(?X , email, ?Info)} UNION {(?X , webPage, ?Info)}]]G
[[{(?X , email, ?Info)}]]G ∪ [[{(?X , webPage, ?Info)}]]G
?X ?Info
µ1 R1 [email protected] µ2 R3 [email protected]
∪?X ?Info
µ3 R3 www.ringo.com
?X ?Info
µ1 R1 [email protected] µ2 R3 [email protected] µ3 R3 www.ringo.com
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 18 / 34
Page 78
Boolean filter expressions (value constraints)
In filter expressions we consider
◮ the equality = among variables and RDF terms
◮ a unary predicate bound
◮ boolean combinations (∧, ∨, ¬)
A mapping µ satisfies
◮ ?X = c if µ(?X ) = c
◮ ?X =?Y if µ(?X ) = µ(?Y )
◮ bound(?X ) if µ is defined in ?X , i.e. ?X ∈ dom(µ)
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 19 / 34
Page 79
Satisfaction of value constraints
◮ If P is a graph pattern and R is a value constraint then(P FILTER R) is also a graph pattern.
Definition
Given a graph G
◮ [[(P FILTER R)]]G = {µ ∈ [[P ]]G | µ satisfies R}i.e. mappings in the evaluation of P that satisfy R .
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 20 / 34
Page 80
Satisfaction of value constraints
◮ If P is a graph pattern and R is a value constraint then(P FILTER R) is also a graph pattern.
Definition
Given a graph G
◮ [[(P FILTER R)]]G = {µ ∈ [[P ]]G | µ satisfies R}i.e. mappings in the evaluation of P that satisfy R .
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 20 / 34
Page 81
Example (FILTER)
G :(R1, name, john) (R2, name, paul) (R3, name, ringo)(R1, email, [email protected] ) (R3, email, [email protected] )
(R3, webPage, www.ringo.com)
[[({(?X , name, ?N)} FILTER (?N = ringo ∨ ?N = paul))]]G
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 21 / 34
Page 82
Example (FILTER)
G :(R1, name, john) (R2, name, paul) (R3, name, ringo)(R1, email, [email protected] ) (R3, email, [email protected] )
(R3, webPage, www.ringo.com)
[[({(?X , name, ?N)} FILTER (?N = ringo ∨ ?N = paul))]]G
?X ?Nµ1 R1 johnµ2 R2 paulµ3 R3 ringo
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 21 / 34
Page 83
Example (FILTER)
G :(R1, name, john) (R2, name, paul) (R3, name, ringo)(R1, email, [email protected] ) (R3, email, [email protected] )
(R3, webPage, www.ringo.com)
[[({(?X , name, ?N)} FILTER (?N = ringo ∨ ?N = paul))]]G
?X ?Nµ1 R1 johnµ2 R2 paulµ3 R3 ringo
?N = ringo ∨ ?N = paul
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 21 / 34
Page 84
Example (FILTER)
G :(R1, name, john) (R2, name, paul) (R3, name, ringo)(R1, email, [email protected] ) (R3, email, [email protected] )
(R3, webPage, www.ringo.com)
[[({(?X , name, ?N)} FILTER (?N = ringo ∨ ?N = paul))]]G
?X ?Nµ1 R1 johnµ2 R2 paulµ3 R3 ringo
?N = ringo ∨ ?N = paul
?X ?Nµ2 R2 paulµ3 R3 ringo
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 21 / 34
Page 85
Example (FILTER)
G :(R1, name, john) (R2, name, paul) (R3, name, ringo)(R1, email, [email protected] ) (R3, email, [email protected] )
(R3, webPage, www.ringo.com)
[[(({(?X , name, ?N)} OPT {(?X , email, ?E )}) FILTER ¬ bound(?E ))]]G
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 22 / 34
Page 86
Example (FILTER)
G :(R1, name, john) (R2, name, paul) (R3, name, ringo)(R1, email, [email protected] ) (R3, email, [email protected] )
(R3, webPage, www.ringo.com)
[[(({(?X , name, ?N)} OPT {(?X , email, ?E )}) FILTER ¬ bound(?E ))]]G
?X ?N ?Eµ1 ∪ µ4 R1 john [email protected] µ3 ∪ µ5 R3 ringo [email protected]
µ2 R2 paul
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 22 / 34
Page 87
Example (FILTER)
G :(R1, name, john) (R2, name, paul) (R3, name, ringo)(R1, email, [email protected] ) (R3, email, [email protected] )
(R3, webPage, www.ringo.com)
[[(({(?X , name, ?N)} OPT {(?X , email, ?E )}) FILTER ¬ bound(?E ))]]G
?X ?N ?Eµ1 ∪ µ4 R1 john [email protected] µ3 ∪ µ5 R3 ringo [email protected]
µ2 R2 paul
¬ bound(?E )
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 22 / 34
Page 88
Example (FILTER)
G :(R1, name, john) (R2, name, paul) (R3, name, ringo)(R1, email, [email protected] ) (R3, email, [email protected] )
(R3, webPage, www.ringo.com)
[[(({(?X , name, ?N)} OPT {(?X , email, ?E )}) FILTER ¬ bound(?E ))]]G
?X ?N ?Eµ1 ∪ µ4 R1 john [email protected] µ3 ∪ µ5 R3 ringo [email protected]
µ2 R2 paul
¬ bound(?E )
?X ?Nµ2 R2 paul
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 22 / 34
Page 89
FILTER: differences with the official specification
◮ We restrict to the case in which all variables in R arementioned in P .
◮ This restriction is not imposed in the official specification byW3C.
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 23 / 34
Page 90
FILTER: differences with the official specification
◮ We restrict to the case in which all variables in R arementioned in P .
◮ This restriction is not imposed in the official specification byW3C.
◮ The semantics without the restriction does not modify theexpressive power of the language.
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 23 / 34
Page 91
SPARQL Datasets
◮ One of the interesting features of SPARQL is that a querymay retrieve data from different sources.
Definition
A SPARQL dataset is a set
D = {G0, 〈u1,G1〉, 〈u2,G2〉, . . . , 〈un,Gn〉}
◮ G0 is the default graph, 〈ui ,Gi 〉 are named graphs
◮ name(D) = {u1, u2, . . . , un}
◮ dD is a function such dD(ui ) = Gi .
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 24 / 34
Page 92
SPARQL Datasets
◮ One of the interesting features of SPARQL is that a querymay retrieve data from different sources.
Definition
A SPARQL dataset is a set
D = {G0, 〈u1,G1〉, 〈u2,G2〉, . . . , 〈un,Gn〉}
◮ G0 is the default graph, 〈ui ,Gi 〉 are named graphs
◮ name(D) = {u1, u2, . . . , un}
◮ dD is a function such dD(ui ) = Gi .
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 24 / 34
Page 93
SPARQL Datasets
◮ One of the interesting features of SPARQL is that a querymay retrieve data from different sources.
Definition
A SPARQL dataset is a set
D = {G0, 〈u1,G1〉, 〈u2,G2〉, . . . , 〈un,Gn〉}
◮ G0 is the default graph, 〈ui ,Gi 〉 are named graphs
◮ name(D) = {u1, u2, . . . , un}
◮ dD is a function such dD(ui ) = Gi .
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 24 / 34
Page 94
SPARQL Datasets
◮ One of the interesting features of SPARQL is that a querymay retrieve data from different sources.
Definition
A SPARQL dataset is a set
D = {G0, 〈u1,G1〉, 〈u2,G2〉, . . . , 〈un,Gn〉}
◮ G0 is the default graph, 〈ui ,Gi 〉 are named graphs
◮ name(D) = {u1, u2, . . . , un}
◮ dD is a function such dD(ui ) = Gi .
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 24 / 34
Page 95
The GRAPH operator
if u is an IRI, ?X is a variable and P is a graph pattern, then
◮ (u GRAPH P) is a graph pattern
◮ (?X GRAPH P) is a graph pattern
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 25 / 34
Page 96
The GRAPH operator
if u is an IRI, ?X is a variable and P is a graph pattern, then
◮ (u GRAPH P) is a graph pattern
◮ (?X GRAPH P) is a graph pattern
GRAPH will permit us to dynamically change the graph againstwhich our pattern is evaluated.
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 25 / 34
Page 97
Semantics of GRAPH
Definition
Given a dataset D and a graph pattern P
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 26 / 34
Page 98
Semantics of GRAPH
Definition
Given a dataset D and a graph pattern P
[[(u GRAPH P)]]G = [[P ]]dD(u)
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 26 / 34
Page 99
Semantics of GRAPH
Definition
Given a dataset D and a graph pattern P
[[(u GRAPH P)]]G = [[P ]]dD(u)
[[(?X GRAPH P)]]G =
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 26 / 34
Page 100
Semantics of GRAPH
Definition
Given a dataset D and a graph pattern P
[[(u GRAPH P)]]G = [[P ]]dD(u)
[[(?X GRAPH P)]]G =⋃
u∈name(D)
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 26 / 34
Page 101
Semantics of GRAPH
Definition
Given a dataset D and a graph pattern P
[[(u GRAPH P)]]G = [[P ]]dD(u)
[[(?X GRAPH P)]]G =⋃
u∈name(D)
[[P ]]dD(u)
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 26 / 34
Page 102
Semantics of GRAPH
Definition
Given a dataset D and a graph pattern P
[[(u GRAPH P)]]G = [[P ]]dD(u)
[[(?X GRAPH P)]]G =⋃
u∈name(D)
(
[[P ]]dD(u) {{?X → u}}
)
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 26 / 34
Page 103
Semantics of GRAPH
Definition
Given a dataset D and a graph pattern P
[[(u GRAPH P)]]G = [[P ]]dD(u)
[[(?X GRAPH P)]]G =⋃
u∈name(D)
(
[[P ]]dD(u) {{?X → u}}
)
Definition
The evaluation of a general pattern P against a dataset D, denotedby [[P ]]D, is the set [[P ]]G0
where G0 is the default graph in D.
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 26 / 34
Page 104
Example (GRAPH)
DG0:
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 27 / 34
Page 105
Example (GRAPH)
DG0:
〈 tb, G1:(R1, name, john) (R2, name, paul)(R1, email, [email protected] )
〉
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 27 / 34
Page 106
Example (GRAPH)
DG0:
〈 tb, G1:(R1, name, john) (R2, name, paul)(R1, email, [email protected] )
〉
〈 trs, G2:(R4, name, mick) (R5, name, keith)(R4, email, [email protected] ) (R5, email, [email protected] )
〉
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 27 / 34
Page 107
Example (GRAPH)
DG0:
〈 tb, G1:(R1, name, john) (R2, name, paul)(R1, email, [email protected] )
〉
〈 trs, G2:(R4, name, mick) (R5, name, keith)(R4, email, [email protected] ) (R5, email, [email protected] )
〉
[[( trs GRAPH {(?X , name, ?N)})]]D
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 27 / 34
Page 108
Example (GRAPH)
DG0:
〈 tb, G1:(R1, name, john) (R2, name, paul)(R1, email, [email protected] )
〉
〈 trs, G2:(R4, name, mick) (R5, name, keith)(R4, email, [email protected] ) (R5, email, [email protected] )
〉
[[( trs GRAPH {(?X , name, ?N)})]]D
[[{(?X , name, ?N)}]]G2
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 27 / 34
Page 109
Example (GRAPH)
DG0:
〈 tb, G1:(R1, name, john) (R2, name, paul)(R1, email, [email protected] )
〉
〈 trs, G2:(R4, name, mick) (R5, name, keith)(R4, email, [email protected] ) (R5, email, [email protected] )
〉
[[( trs GRAPH {(?X , name, ?N)})]]D
[[{(?X , name, ?N)}]]G2
?X ?Nµ1 R4 mickµ2 R5 keith
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 27 / 34
Page 110
Example (GRAPH)
DG0:
〈 tb, G1:(R1, name, john) (R2, name, paul)(R1, email, [email protected] )
〉
〈 trs, G2:(R4, name, mick) (R5, name, keith)(R4, email, [email protected] ) (R5, email, [email protected] )
〉
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 28 / 34
Page 111
Example (GRAPH)
DG0:
〈 tb, G1:(R1, name, john) (R2, name, paul)(R1, email, [email protected] )
〉
〈 trs, G2:(R4, name, mick) (R5, name, keith)(R4, email, [email protected] ) (R5, email, [email protected] )
〉
[[(?G GRAPH {(?X , name, ?N)})]]D
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 28 / 34
Page 112
Example (GRAPH)
DG0:
〈 tb, G1:(R1, name, john) (R2, name, paul)(R1, email, [email protected] )
〉
〈 trs, G2:(R4, name, mick) (R5, name, keith)(R4, email, [email protected] ) (R5, email, [email protected] )
〉
[[(?G GRAPH {(?X , name, ?N)})]]D
[[{(?X , name, ?N)}]]G1 {{?G → tb}}
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 28 / 34
Page 113
Example (GRAPH)
DG0:
〈 tb, G1:(R1, name, john) (R2, name, paul)(R1, email, [email protected] )
〉
〈 trs, G2:(R4, name, mick) (R5, name, keith)(R4, email, [email protected] ) (R5, email, [email protected] )
〉
[[(?G GRAPH {(?X , name, ?N)})]]D
[[{(?X , name, ?N)}]]G1 {{?G → tb}} ∪
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 28 / 34
Page 114
Example (GRAPH)
DG0:
〈 tb, G1:(R1, name, john) (R2, name, paul)(R1, email, [email protected] )
〉
〈 trs, G2:(R4, name, mick) (R5, name, keith)(R4, email, [email protected] ) (R5, email, [email protected] )
〉
[[(?G GRAPH {(?X , name, ?N)})]]D
[[{(?X , name, ?N)}]]G1 {{?G → tb}} ∪[[{(?X , name, ?N)}]]G2 {{?G → trs}}
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 28 / 34
Page 115
Example (GRAPH)
DG0:
〈 tb, G1:(R1, name, john) (R2, name, paul)(R1, email, [email protected] )
〉
〈 trs, G2:(R4, name, mick) (R5, name, keith)(R4, email, [email protected] ) (R5, email, [email protected] )
〉
[[(?G GRAPH {(?X , name, ?N)})]]D
[[{(?X , name, ?N)}]]G1 {{?G → tb}} ∪[[{(?X , name, ?N)}]]G2 {{?G → trs}}
?X ?Nµ1 R1 johnµ2 R2 paul
{{?G → tb}}
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 28 / 34
Page 116
Example (GRAPH)
DG0:
〈 tb, G1:(R1, name, john) (R2, name, paul)(R1, email, [email protected] )
〉
〈 trs, G2:(R4, name, mick) (R5, name, keith)(R4, email, [email protected] ) (R5, email, [email protected] )
〉
[[(?G GRAPH {(?X , name, ?N)})]]D
[[{(?X , name, ?N)}]]G1 {{?G → tb}} ∪[[{(?X , name, ?N)}]]G2 {{?G → trs}}
?X ?Nµ1 R1 johnµ2 R2 paul
{{?G → tb}} ∪?X ?N
µ3 R4 mickµ4 R5 keith
{{?G → trs}}
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 28 / 34
Page 117
Example (GRAPH)
DG0:
〈 tb, G1:(R1, name, john) (R2, name, paul)(R1, email, [email protected] )
〉
〈 trs, G2:(R4, name, mick) (R5, name, keith)(R4, email, [email protected] ) (R5, email, [email protected] )
〉
[[(?G GRAPH {(?X , name, ?N)})]]D
[[{(?X , name, ?N)}]]G1 {{?G → tb}} ∪[[{(?X , name, ?N)}]]G2 {{?G → trs}}
?X ?Nµ1 R1 johnµ2 R2 paul
{{?G → tb}} ∪?X ?N
µ3 R4 mickµ4 R5 keith
{{?G → trs}}
?G ?X ?Ntb R1 johntb R2 paultrs R4 micktrs R5 keith
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 28 / 34
Page 118
SELECT
◮ Up to this point we have concentrated in the body of aSPARQL query, i.e. in the graph pattern matching expression.
◮ A query can also process the values of the variables. Themost simple processing operation is the selection of somevariables appearing in the query.
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 29 / 34
Page 119
SELECT
◮ Up to this point we have concentrated in the body of aSPARQL query, i.e. in the graph pattern matching expression.
◮ A query can also process the values of the variables. Themost simple processing operation is the selection of somevariables appearing in the query.
Definition◮ A SELECT query is a tuple (W ,P) where P is a graph
pattern and W is a set of variable.
◮ The answer of a SELECT query against a dataset D is
{µ|W | µ ∈ [[P ]]D}
where µ|W is the restriction of µ to domain W .
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 29 / 34
Page 120
SELECT
◮ Up to this point we have concentrated in the body of aSPARQL query, i.e. in the graph pattern matching expression.
◮ A query can also process the values of the variables. Themost simple processing operation is the selection of somevariables appearing in the query.
Definition◮ A SELECT query is a tuple (W ,P) where P is a graph
pattern and W is a set of variable.
◮ The answer of a SELECT query against a dataset D is
{µ|W | µ ∈ [[P ]]D}
where µ|W is the restriction of µ to domain W .
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 29 / 34
Page 121
SELECT
◮ Up to this point we have concentrated in the body of aSPARQL query, i.e. in the graph pattern matching expression.
◮ A query can also process the values of the variables. Themost simple processing operation is the selection of somevariables appearing in the query.
Definition◮ A SELECT query is a tuple (W ,P) where P is a graph
pattern and W is a set of variable.
◮ The answer of a SELECT query against a dataset D is
{µ|W | µ ∈ [[P ]]D}
where µ|W is the restriction of µ to domain W .
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 29 / 34
Page 122
CONSTRUCT
◮ A query can also output an RDF graph.
◮ The construction of the output graph is based on a template.
◮ A template is a set of triple patterns possibly with bnodes.
Example
T1 = {(?X , name, ?Y ), (?X , info, ?I ), (?X , addr, B)}
with B a bnode
Definition
◮ A CONSTRUCT query is a tuple (T ,P) where P is a graphpattern and T is a template.
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 30 / 34
Page 123
CONSTRUCT
◮ A query can also output an RDF graph.
◮ The construction of the output graph is based on a template.
◮ A template is a set of triple patterns possibly with bnodes.
Example
T1 = {(?X , name, ?Y ), (?X , info, ?I ), (?X , addr, B)}
with B a bnode
Definition
◮ A CONSTRUCT query is a tuple (T ,P) where P is a graphpattern and T is a template.
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 30 / 34
Page 124
CONSTRUCT
◮ A query can also output an RDF graph.
◮ The construction of the output graph is based on a template.
◮ A template is a set of triple patterns possibly with bnodes.
Example
T1 = {(?X , name, ?Y ), (?X , info, ?I ), (?X , addr, B)}
with B a bnode
Definition
◮ A CONSTRUCT query is a tuple (T ,P) where P is a graphpattern and T is a template.
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 30 / 34
Page 125
CONSTRUCT: Semantics
Definition
The answer of a CONSTRUCT query (T ,P) against a dataset Dis obtained by
◮ for every µ ∈ [[P ]]D create a template Tµ with fresh bnodes
◮ take the union of µ(Tµ) for every µ ∈ [[P ]]D◮ discard the not valid RDF triples
◮ some variables have not been instantiated.◮ bnodes in predicate positions
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 31 / 34
Page 126
CONSTRUCT: Semantics
Definition
The answer of a CONSTRUCT query (T ,P) against a dataset Dis obtained by
◮ for every µ ∈ [[P ]]D create a template Tµ with fresh bnodes
◮ take the union of µ(Tµ) for every µ ∈ [[P ]]D◮ discard the not valid RDF triples
◮ some variables have not been instantiated.◮ bnodes in predicate positions
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 31 / 34
Page 127
CONSTRUCT: Semantics
Definition
The answer of a CONSTRUCT query (T ,P) against a dataset Dis obtained by
◮ for every µ ∈ [[P ]]D create a template Tµ with fresh bnodes
◮ take the union of µ(Tµ) for every µ ∈ [[P ]]D◮ discard the not valid RDF triples
◮ some variables have not been instantiated.◮ bnodes in predicate positions
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 31 / 34
Page 128
CONSTRUCT: Semantics
Definition
The answer of a CONSTRUCT query (T ,P) against a dataset Dis obtained by
◮ for every µ ∈ [[P ]]D create a template Tµ with fresh bnodes
◮ take the union of µ(Tµ) for every µ ∈ [[P ]]D◮ discard the not valid RDF triples
◮ some variables have not been instantiated.◮ bnodes in predicate positions
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 31 / 34
Page 129
CONSTRUCT: Semantics
Definition
The answer of a CONSTRUCT query (T ,P) against a dataset Dis obtained by
◮ for every µ ∈ [[P ]]D create a template Tµ with fresh bnodes
◮ take the union of µ(Tµ) for every µ ∈ [[P ]]D◮ discard the not valid RDF triples
◮ some variables have not been instantiated.◮ bnodes in predicate positions
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 31 / 34
Page 130
CONSTRUCT: Semantics
Definition
The answer of a CONSTRUCT query (T ,P) against a dataset Dis obtained by
◮ for every µ ∈ [[P ]]D create a template Tµ with fresh bnodes
◮ take the union of µ(Tµ) for every µ ∈ [[P ]]D◮ discard the not valid RDF triples
◮ some variables have not been instantiated.◮ bnodes in predicate positions
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 31 / 34
Page 131
Blank nodes in graph patterns
◮ We allow now bnodes in triple patterns.
◮ Bnodes act as existentials scoped to the basic graph pattern.
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 32 / 34
Page 132
Blank nodes in graph patterns
◮ We allow now bnodes in triple patterns.
◮ Bnodes act as existentials scoped to the basic graph pattern.
Definition
The evaluation of the BGP P with bnodes over the graph G
denoted [[P ]]G , is the set of all mappings µ such that:
◮ dom(µ) is exactly the set of variables occurring in P ,
◮ there exists a function θ from bnodes of P to G such that
µ(θ(P)) ⊆ G .
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 32 / 34
Page 133
Blank nodes in graph patterns
◮ We allow now bnodes in triple patterns.
◮ Bnodes act as existentials scoped to the basic graph pattern.
Definition
The evaluation of the BGP P with bnodes over the graph G
denoted [[P ]]G , is the set of all mappings µ such that:
◮ dom(µ) is exactly the set of variables occurring in P ,
◮ there exists a function θ from bnodes of P to G such that
µ(θ(P)) ⊆ G .
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 32 / 34
Page 134
Blank nodes in graph patterns
◮ We allow now bnodes in triple patterns.
◮ Bnodes act as existentials scoped to the basic graph pattern.
Definition
The evaluation of the BGP P with bnodes over the graph G
denoted [[P ]]G , is the set of all mappings µ such that:
◮ dom(µ) is exactly the set of variables occurring in P ,
◮ there exists a function θ from bnodes of P to G such that
µ(θ(P)) ⊆ G .
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 32 / 34
Page 135
Blank nodes in graph patterns
◮ We allow now bnodes in triple patterns.
◮ Bnodes act as existentials scoped to the basic graph pattern.
Definition
The evaluation of the BGP P with bnodes over the graph G
denoted [[P ]]G , is the set of all mappings µ such that:
◮ dom(µ) is exactly the set of variables occurring in P ,
◮ there exists a function θ from bnodes of P to G such that
µ(θ(P)) ⊆ G .
◮ A natural extension of BGPs without bnodes.
◮ The algebra remains the same.
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 32 / 34
Page 136
Bag/Multiset semantics
◮ In a bag, a mapping can have cardinality greater than one.
◮ Every mapping µ in a bag M is annotated with an integercM(µ) that represents its cardinality (cM(µ) = 0 if µ /∈ M).
◮ Operations between sets of mappings can be extended to bagsmaintaining duplicates:
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 33 / 34
Page 137
Bag/Multiset semantics
◮ In a bag, a mapping can have cardinality greater than one.
◮ Every mapping µ in a bag M is annotated with an integercM(µ) that represents its cardinality (cM(µ) = 0 if µ /∈ M).
◮ Operations between sets of mappings can be extended to bagsmaintaining duplicates:
Definition
µ ∈ M = M1 M2, cM(µ) =∑
µ=µ1∪µ2
cM1(µ1) · cM2
(µ2),
µ ∈ M = M1 ∪ M2, cM(µ) = cM1(µ) + cM2
(µ),
µ ∈ M = M1 r M2, cM(µ) = cM1(µ).
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 33 / 34
Page 138
Bag/Multiset semantics
◮ In a bag, a mapping can have cardinality greater than one.
◮ Every mapping µ in a bag M is annotated with an integercM(µ) that represents its cardinality (cM(µ) = 0 if µ /∈ M).
◮ Operations between sets of mappings can be extended to bagsmaintaining duplicates:
Definition
µ ∈ M = M1 M2, cM(µ) =∑
µ=µ1∪µ2
cM1(µ1) · cM2
(µ2),
µ ∈ M = M1 ∪ M2, cM(µ) = cM1(µ) + cM2
(µ),
µ ∈ M = M1 r M2, cM(µ) = cM1(µ).
◮ Intuition: we simply do not discard duplicates.
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 33 / 34
Page 139
References
◮ R. Cyganiak, A Relational Algebra for SPARQL. Tech ReportHP Laboratories, HPL-2005-170.
◮ E. Prud’hommeaux, A. Seaborne, SPARQL Query Language
for RDF. W3C Working Draft, 2007.
◮ J. Perez, M. Arenas, C. Gutierrez, Semantics and Complexity
of SPARQL. In Int. Semantic Web Conference 2006.
◮ J. Perez, M. Arenas, C. Gutierrez, Semantics of SPARQL.Tech Report Universidad de Chile 2006, TR/DCC-2006-17.
M. Arenas, C. Gutierrez, J. Perez – SPARQL Formalization 34 / 34