From c8deb22250c7fda5af04f607905e50f7724c9b4a Mon Sep 17 00:00:00 2001
From: Olaf Hartig
+ A SPARQL expression is evaluated
+ with respect to a solution mapping
+ and in the context of an RDF dataset
+ with an active graph.
+ The result of such an evaluation is either
+ an RDF term or
+ an [=error=].
+
SPARQL provides a subset of the functions and operators defined by
XPath and XQuery Functions and Operators.
@@ -10048,16 +10057,18 @@ Operand Data Types
Expression Evaluation
+ SPARQL Algebra
|D| be a dataset,
and |G| be the active graph.
We define:
Filter(expr, Ω, |D|, |G|) = { μ in Ω | expr(μ) is an expression that has an - [=effective boolean value=] of true }
-Filter(expr, Ω, |D|, |G|) = + { μ in Ω | + |expr|(μ, |D|, |G|) is an RDF term |t| + such that EBV(|t|) is `"true"^^xsd:boolean` }
multiplicity( μ | Filter(expr, Ω, |D|, |G|) ) = multiplicity( μ | Ω )
-
- Note that evaluating an exists(pattern)
expression uses the dataset |D| and
- active graph |G|. See the evaluation of filter.
-
+ + where, for every solution mapping μ, + |expr|(μ, |D|, |G|) is the result of + evaluating expression |expr| + with respect to μ, in the context of dataset |D| with active graph |G|. +
Definition: Join
@@ -10077,29 +10088,43 @@Definition: Diff
-Let Ω1 and Ω2 be multisets of solution mappings and expr be an - expression. We define:
-Diff(Ω1, Ω2, expr) = { μ | μ in Ω1 such that ∀ μ' in - Ω2, either μ and μ' are not compatible or μ and μ' are compatible and - expr(merge(μ, μ')) does not have an [=effective boolean value=] of true }
-multiplicity( μ | Diff(Ω1, Ω2, expr) ) = +
Let Ω1 and Ω2 be multisets of solution mappings, + expr be an expression, + |D| be a dataset, + and |G| be the active graph. + We define:
+Diff(Ω1, Ω2, expr, |D|, |G|) = { μ | μ in Ω1 such that ∀ μ' in + Ω2, either i) μ and μ' are not compatible, + or + ii) μ and μ' are compatible and + |expr|(merge(μ, μ'), |D|, |G|) is an [=error=], + or + iii) μ and μ' are compatible and + |expr|(merge(μ, μ'), |D|, |G|) is an RDF term |t| for which + EBV(|t|) is not `"true"^^xsd:boolean` }
+multiplicity( μ | Diff(Ω1, Ω2, expr, |D|, |G|) ) = multiplicity( μ | Ω1 )
++ where, for every solution mapping μ, + |expr|(μ, |D|, |G|) is the result of + evaluating expression |expr| + with respect to μ, in the context of dataset |D| with active graph |G|. +
The evaluation of expr(merge(μ, μ')) does not have an - [=effective boolean value=] of true if it evaluates to false or if it raises an error.
Diff is used internally for the definition of LeftJoin.
Definition: LeftJoin
-Let Ω1 and Ω2 be multisets of solution mappings and expr be an - expression. We define:
-LeftJoin(Ω1, Ω2, expr) = Filter(expr, Join(Ω1, - Ω2)) ∪ Diff(Ω1, Ω2, expr)
-multiplicity( μ | LeftJoin(Ω1, Ω2, expr) ) = - multiplicity( μ | Filter(expr, Join(Ω1, Ω2)) ) + +
Let Ω1 and Ω2 be multisets of solution mappings, + expr be an expression, + |D| be a dataset, + and |G| be the active graph. + We define:
+LeftJoin(Ω1, Ω2, expr, |D|, |G|) = Filter(expr, Join(Ω1, + Ω2), |D|, |G|) ∪ Diff(Ω1, Ω2, expr, |D|, |G|)
+multiplicity( μ | LeftJoin(Ω1, Ω2, expr, |D|, |G|) ) = + multiplicity( μ | Filter(expr, Join(Ω1, Ω2), |D|, |G|) ) + multiplicity( μ | Diff(Ω1, Ω2, - expr) )
+ expr, |D|, |G|) )P
.
Definition: Extend
-Let μ be a solution mapping, Ω a multiset of solution mappings, var a variable - and expr be an expression, then we define:
-Extend(μ, var, expr) = μ ∪ { (var, value) | var not in dom(μ) and value = expr(μ) }
-Extend(μ, var, expr) = μ if var not in dom(μ) and expr(μ) is an error
-Extend is undefined if var in dom(μ).
-Extend(Ω, var, expr) = { Extend(μ, var, expr) | μ in Ω }
+Let μ be a solution mapping, Ω a multiset of solution mappings, + var be a variable, + expr be an expression, + |D| be a dataset, + and |G| be the active graph. + We define:
+Extend(Ω, var, expr, |D|, |G|) = { |Extend|(μ, var, expr, |D|, |G|) | μ in Ω },
+where, for every solution mapping μ,
+|Extend|(μ, var, expr, |D|, |G|) = μ ∪ { (var, |expr|(μ, |D|, |G|)) } + if var not in dom(μ) and + |expr|(μ, |D|, |G|) is an RDF term,
+|Extend|(μ, var, expr, |D|, |G|) = μ + if var not in dom(μ) and + |expr|(μ, |D|, |G|) is an [=error=],
+|Extend|(μ, var, expr, |D|, |G|) is undefined + if var in dom(μ), and
+|expr|(μ, |D|, |G|) is the result of + evaluating expression |expr| + with respect to μ, in the context of dataset |D| with active graph |G|. +
+Write [ x | C ] for a sequence of elements where C is a condition on x.
Definition: Evaluation of LeftJoin
-eval( |D|(|G|), LeftJoin(P1, P2, |F|) ) = LeftJoin( eval(|D|(|G|), P1), eval(|D|(|G|), P2), |F| ) +eval( |D|(|G|), LeftJoin(P1, P2, |F|) ) = LeftJoin( eval(|D|(|G|), P1), eval(|D|(|G|), P2), |F|, |D|, |G| )
Note that if eval(|D|(|G|), Ai) is an error, it is ignored.
Definition: Evaluation of Extend
+Definition: Evaluation of Extend
-eval( |D|(|G|), Extend(|P|, |var|, |expr|) ) = Extend( eval(|D|(|G|), |P|), |var|, |expr| ) +eval( |D|(|G|), Extend(|P|, |var|, |expr|) ) = Extend( eval(|D|(|G|), |P|), |var|, |expr|, |D|, |G| )
Diff(Ω1, Ω2, expr, |D|, |G|) = { μ | μ in Ω1 such that ∀ μ' in - Ω2, either i) μ and μ' are not compatible, - or - ii) μ and μ' are compatible and - |expr|(merge(μ, μ'), |D|, |G|) is an [=error=], - or - iii) μ and μ' are compatible and - |expr|(merge(μ, μ'), |D|, |G|) is an RDF term |t| for which - EBV(|t|) is not `"true"^^xsd:boolean` }
+Diff(Ω1, Ω2, expr, |D|, |G|) + = { μ in Ω1 | for every μ' in Ω2, + either of the following conditions holds:
+}
multiplicity( μ | Diff(Ω1, Ω2, expr, |D|, |G|) ) = multiplicity( μ | Ω1 )
From a21e4938d4d146b1a70d65d5e3428aea7393d75e Mon Sep 17 00:00:00 2001
From: Olaf Hartig SPARQL Algebra
We define:
Diff(Ω1, Ω2, expr, |D|, |G|) = { μ in Ω1 | for every μ' in Ω2, - either of the following conditions holds:
+ any of the following conditions holds: