Skip to content

better handling of FILTER in translation to algebra #250

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 18 additions & 37 deletions spec/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8924,28 +8924,6 @@ <h5>Expand Syntax Forms</h5>
<p>Expand abbreviations for IRIs and triple patterns given in
<a href="#sparqlSyntax">section 4</a>.</p>
</section>
<section id="sparqlCollectFilters">
<h5>Collect <code>FILTER</code> Elements</h5>
<p><code>FILTER</code> expressions apply to the whole group graph pattern in which they
appear. The algebra operators to perform filtering are added to the group after
translation of each group element. We collect the filters together here and remove them
from group, then <a href="#sparqlAddFilters">apply them to the whole translated group
graph pattern</a>.</p>
<p>In this step, we also translate graph patterns within <code>FILTER</code> expressions
<a href="#func-filter-exists"><code>EXISTS</code></a> and
<a href="#func-filter-not-exists"><code>NOT EXISTS</code></a>.</p>

<pre class="code nohighlightBlock">
Let FS := empty set
For each form FILTER(expr) in the group graph pattern
In expr, replace NOT EXISTS{P} with fn:not(<a href="#defn_evalExists">exists(translate(P)))</a>
In expr, replace EXISTS{P} with <a href="#defn_evalExists">exists(translate(P))</a>
FS := FS ∪ {expr}
End
</pre>
<p>The set of filter expressions <code>FS</code> is <a href="#sparqlAddFilters">used
later</a>.</p>
</section>
<section id="sparqlTranslatePathExpressions">
<h5>Translate Property Path Expressions</h5>
<p>The following table gives the translation
Expand Down Expand Up @@ -9137,15 +9115,18 @@ <h5>Translate Graph Patterns</h5>
If the form is GRAPH Var GroupGraphPattern
The result is Graph(Var, Translate(GroupGraphPattern))
</pre>

<blockquote>
<p>If the form is <code><a href="#rGroupGraphPattern">GroupGraphPattern</a></code>:</p>
<p>If the form is <code><a href="#rGroupGraphPattern">GroupGraphPattern</a></code> with child <code>P</code>:</p>
</blockquote>
<pre class="code nohighlightBlock">The result is Translate(P).</pre>
<blockquote>
<p>If the form is <code><a href="#rGroupGraphPatternSub">GroupGraphPatternSub</a></code>:</p>
</blockquote>
<pre class="code nohighlightBlock">
Let FS := the empty set
Let FS := the empty sequence
Let G := the empty pattern, a basic graph pattern which is the empty set.

For each element E in the sequence of elements in the GroupGraphPattern
For each element E in the sequence of elements that are the GroupGraphPattern's TriplesBlock children and the children of its other children, in order:

If E is of the form OPTIONAL{P}
Let A := Translate(P)
Expand All @@ -9160,6 +9141,12 @@ <h5>Translate Graph Patterns</h5>
G := Minus(G, Translate(P))
End

If E is of the form FILTER(expr)
In expr, replace NOT EXISTS{P} with fn:not(exists(translate(P)))
In expr, replace EXISTS{P} with exists(translate(P))
FS := FS + expr
End

If E is of the form BIND(expr AS var)
G := Extend(G, var, expr)
End
Expand All @@ -9171,6 +9158,11 @@ <h5>Translate Graph Patterns</h5>

End

If FS is not empty
Let X := Conjunction of expressions in FS
G := Filter(X, G)
End

The result is G.
</pre>
<blockquote>
Expand All @@ -9190,17 +9182,6 @@ <h5>Translate Graph Patterns</h5>
</blockquote>
<pre class="code nohighlightBlock">The result is ToMultiset(Translate(SubSelect))</pre>
</section>
<section id="sparqlAddFilters">
<h5>Filters of Group</h5>
<p>After the group has been translated, the filter expressions are added so they wil
apply to the whole of the rest of the group:</p>
<pre class="code nohighlightBlock">
If FS is not empty
Let G := output of preceding step
Let X := Conjunction of expressions in FS
G := Filter(X, G)
End</pre>
</section>
<section id="sparqlSimplification">
<h5>Simplification step</h5>
<p>Some groups of one graph pattern become <code>join(Z, A)</code>, where Z is the empty
Expand Down
Loading