Hi Rob,
Thanks. I think I understand. I don't know whether I like it very much
with a Prolog view ... In good old SPARQL, I could simply translate the
query into a Prolog control structure and call it. Better, as long as
one ensures that arguments to FILTER expressions are instantiated before
evaluating the FILTER, every permutation of the resulting conjunction
was the same query. I use this to optimize queries. I understand that
SPARQL 1.1 is much more difficult.
Anyway, the good news is that SPARQL 1.1 is rich enough such that you
can write meaningful queries! It only should have been called SPARQL 3.0
if I compare the complexity :-)
Thanks --- Jan
On 10/19/2012 09:26 PM, Rob Vesse wrote:
Hi Jan
This one is a scoping issue. The Union is a child graph pattern of the
main graph pattern and as SPARQL is evaluated bottom up the variable ?o is
not in scope within the union and so the bind expressions will always
evaluate to no result.
If you put the query into the validator at sparql.org
(http://www.sparql.org/query-validator.html) and select the SPARQL Algebra
option you'll see the following:
(base <http://example/base/>
(prefix ((: <http://example.org/>))
(project (?s ?p ?o ?z)
(join
(bgp (triple ?s ?p ?o))
(union
(extend ((?z (+ ?o 1)))
(table unit))
(extend ((?z (+ ?o 2)))
(table unit)))))))
Hope this helps makes the scoping clear
Rob
On 10/19/12 12:03 PM, "Jan Wielemaker" <[email protected]> wrote:
Hi,
I'm trying to update ClioPatria's SPARQL support to 1.1. I get this
result:
15 ?- query_test('bind07 - BIND').
======================== BEGIN 'bind07 - BIND' =========================
% Parsed "data.ttl" in 0.00 sec; 4 triples
=========================== 'bind07 - BIND' ============================
TYPE: select(names(s,p,o,z))
RESULTS: 8; 4 missed, 8 incorrect
MISSED: <http://example.org/s1> <http://example.org/p> "1"^^xsd:integer
NULL .
<http://example.org/s2> <http://example.org/p> "2"^^xsd:integer
NULL .
<http://example.org/s3> <http://example.org/p> "3"^^xsd:integer
NULL .
<http://example.org/s4> <http://example.org/p> "4"^^xsd:integer
NULL .
EXTRA: <http://example.org/s1> <http://example.org/p> "1"^^xsd:integer
"2"^^xsd:integer .
<http://example.org/s1> <http://example.org/p> "1"^^xsd:integer
"3"^^xsd:integer .
<http://example.org/s2> <http://example.org/p> "2"^^xsd:integer
"3"^^xsd:integer .
<http://example.org/s2> <http://example.org/p> "2"^^xsd:integer
"4"^^xsd:integer .
<http://example.org/s3> <http://example.org/p> "3"^^xsd:integer
"4"^^xsd:integer .
<http://example.org/s3> <http://example.org/p> "3"^^xsd:integer
"5"^^xsd:integer .
<http://example.org/s4> <http://example.org/p> "4"^^xsd:integer
"5"^^xsd:integer .
<http://example.org/s4> <http://example.org/p> "4"^^xsd:integer
"6"^^xsd:integer .
========================================================================
The query is this:
PREFIX : <http://example.org/>
SELECT ?s ?p ?o ?z
{
?s ?p ?o .
{ BIND(?o+1 AS ?z) } UNION { BIND(?o+2 AS ?z) }
}
and the data is
org:s1 org:p 1 .
org:s2 org:p 2 .
org:s3 org:p 3 .
org:s4 org:p 4 .
Can anyone explain me by which rules the UNION of the two BIND
operations should
be NULL instead of resulting in two alternative answers?
Thanks --- Jan