A question about the OPTIONAL pattern(B

From: Lu Jing(B <robert_lu00@hotmail.com>
Date: Thu, 21 Sep 2006 14:00:17 +0900
Message-ID: <BAY104-F15A833EB289C6850C4ED3795200@phx.gbl>

I feel that the semantics of OPTIONAL pattern is still not clear.  If my
understanding is correct, according to the specification, OPTIONAL pattern
can modify the solutions of a pattern by adding new bindings to unbounded
variables.  The problem is, in some cases, add additional binding to a
unbounded variable may cause this solution no longer a valid solution of
the original pattern.  We can see the following example.

Assume the data is:

:a :p1 :b
:a :p2 :c

If we have the following SPARQL:

SELECT ?x ?y ?z WHERE { { ?x :p1 ?y } UNION { ?x :p3 ?z } }

The result should contain only one solution:

( :a :b _ )
Here, I use "_" to represent a unbound variable.

Now if we add an optional pattern to the above query, that is:

SELECT ?x ?y ?z WHERE { { { ?x :p1 ?y } UNION { ?x :p3 ?z } } . OPTIONAL {
?x :p2 ?z } }

According to the definition, the optional pattern additionally add a
binding to the variable ?z. So the solution should be:
( :a :b :c )

It seems OK in this case, as the ( :a :b :c ) is also a solution to the
UNION pattern.
But now if we add a filter to the first query, that is:

SELECT ?x ?y ?z WHERE { { { ?x :p1 ?y } UNION { ?x :p3 ?z } } . FILTER (
!BOUND(?z) ) }

The solution of this query should be:
( :a :b _ )
That is, not changed from the first query.  But now if we again add an
option pattern to it, that is:

SELECT ?x ?y ?z WHERE { { { { ?x :p1 ?y } UNION { ?x :p3 ?z } } . FILTER (
!BOUND(?z) ) } . OPTIONAL { ?x :p2 ?z } }

If we follow the definition, the solution should be still:
( :a :b :c )
But this time, we have a filter in the first pattern that says the ?z
should not be bound.  That means, this answer is not a solution of the
pattern without the optional pattern.

So I wonder what is the exact definition of an optional pattern, and what
should the answers of the above querys be?
Received on Thursday, 21 September 2006 05:00:28 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 20:52:07 UTC