Skip to content

Commit 6878281

Browse files
authored
Merge pull request #325 from w3c/Issue302_Step3
Formal definition of the evaluation of EXISTS expressions
2 parents 24e27b4 + c5dceb7 commit 6878281

File tree

1 file changed

+36
-16
lines changed

1 file changed

+36
-16
lines changed

spec/index.html

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5687,31 +5687,46 @@ <h5>COALESCE</h5>
56875687
<span id="func-filter-not-exists"></span>
56885688
<h5>NOT EXISTS and EXISTS</h5>
56895689
<p>There is a filter operator <code>EXISTS</code> that takes a graph pattern.
5690-
<code>EXISTS</code> returns <code>true</code>/<code>false</code> depending on whether the
5691-
pattern matches the dataset given the bindings in the current group graph pattern, the
5692-
dataset and the <a href="#defn_ActiveGraph">active graph</a> at this point in the query
5693-
evaluation. No additional binding of variables occurs. The <code>NOT EXISTS</code> form
5694-
translates into <code>fn:not(EXISTS{...})</code>.</p>
5690+
<code>EXISTS</code> returns <code>true</code> or <code>false</code>,
5691+
depending on whether the pattern,
5692+
together with the solution mapping,
5693+
matches the dataset.
5694+
No additional binding of variables occurs. The `NOT EXISTS` form
5695+
translates into <code><a data-cite="XPATH-FUNCTIONS-31#func-not">fn:not</a>(EXISTS {...})</code>.</p>
56955696
<pre class="prototype nohighlight">
56965697
<span class="return">xsd:boolean</span> <span class="operator">NOT EXISTS</span> { <span class="pattern">pattern</span> }
56975698
</pre>
5698-
<p>Returns <code>false</code> if <code>pattern</code> matches. Returns true
5699+
<p>Returns `false` if `pattern` matches. Returns `true`
56995700
otherwise.</p>
5700-
<p><code>NOT EXISTS { pattern }</code> is equivalent to <code>fn:not(EXISTS { pattern
5701+
<p>`NOT EXISTS { pattern }` is equivalent to <code><a data-cite="XPATH-FUNCTIONS-31#func-not">fn:not</a>(EXISTS { pattern
57015702
})</code>.</p>
57025703
<pre class="prototype nohighlight">
57035704
<span class="return">xsd:boolean</span> EXISTS { <span class="pattern">pattern</span> }
57045705
</pre>
5705-
<p>Returns <code>true</code> if <code>pattern</code> matches. Returns false
5706+
<p>Returns `true` if `pattern` matches. Returns `false`
57065707
otherwise.</p>
5707-
<p>Variables in the <code>pattern</code> that are bound in the current
5708-
<a data-cite="SPARQL11-QUERY#defn_sparqlSolutionMapping">solution mapping</a> take the value that they
5709-
have from the solution mapping. Variables in the pattern <code>pattern</code> that are
5710-
not bound in the current solution mapping take part in pattern matching.</p>
5711-
<p>To facilitate this, we introduce a function <a href="#defn_exists">Exists</a> that
5712-
evaluates a SPARQL Algebra expression and returns true or false, depending on whether
5713-
there are any solutions to the pattern, given the solution mapping being tested by the
5714-
filter operation.</p>
5708+
<p>Formally, for every <a href="#expressions">expression</a> |expr|
5709+
that is of the form `EXISTS { pattern }`,
5710+
the result of <a href="#expression-evaluation">evaluating</a> |expr|
5711+
with respect to a <a href="#defn_sparqlSolutionMapping">solution mapping</a> <var>μ</var>,
5712+
in the context of a <a href="#sparqlDataset">dataset</a> |D|
5713+
with <a href="#defn_ActiveGraph">active graph</a> |G|,
5714+
is:</p>
5715+
<ul>
5716+
<li>`"true"^^xsd:boolean` if
5717+
<a href="#defn_eval" class="evalFct">eval</a>(|D|(|G|), |A|, <var>μ</var>) is not empty</li>
5718+
<li>`"false"^^xsd:boolean` if
5719+
<a href="#defn_eval" class="evalFct">eval</a>(|D|(|G|), |A|, <var>μ</var>) is empty</li>
5720+
</ul>
5721+
<p>where |A| is the <a href="#defn_AlgebraicQueryExpression">algebraic query expression</a>
5722+
obtained by translating `{ pattern }` as per <a href="#translation" class="sectionRef"></a>.</p>
5723+
<p class="note">
5724+
As per the <a href="#rExistsFunc">ExistsFunc</a> production
5725+
of the <a href="#sparqlGrammar">grammar</a>,
5726+
`{ pattern }` matches the <a href="#rGroupGraphPattern">GroupGraphPattern</a> production.
5727+
The specific subsection of <a href="#translation" class="sectionRef"></a>
5728+
that covers the translation of any <a href="#rGroupGraphPattern">GroupGraphPattern</a>
5729+
is <a href="#sparqlTranslateGraphPatterns" class="sectionRef"></a>.</p>
57155730
</section>
57165731
<section id="func-logical-or">
57175732
<h5>logical-or</h5>
@@ -10675,6 +10690,11 @@ <h3>Evaluation Semantics</h3>
1067510690
in correlation with solution mapping <var>μ<sub>ctx</sub></var>.</p>
1067610691
<p>The active graph is initially the default graph of |D| and
1067710692
<var>μ<sub>ctx</sub></var> is initially the empty solution mapping <var>μ<sub>0</sub></var>.</p>
10693+
<p class="note">The case in which <var>μ<sub>ctx</sub></var>
10694+
may be different from <var>μ<sub>0</sub></var>
10695+
is when evaluating an <a href="#expressions">expression</a>
10696+
of the form `EXISTS pattern` or `NOT EXISTS pattern`,
10697+
as defined in <a href="#func-filter-exists" class="sectionRef"></a>.</p>
1067810698
<p>Further symbols used in the following definitions are:</p>
1067910699
<ul>
1068010700
<li>|P|, <var>P<sub>1</sub></var>, <var>P<sub>2</sub></var> : graph patterns</li>

0 commit comments

Comments
 (0)