SPARQL OPTIONAL Odd Behaviour?
From: Will Daniels
Subject: SPARQL OPTIONAL Odd Behaviour?
Date: Tue, 24 Mar 2009 01:54:57 +0200
Hello!
I'm finding some behaviour in ARC2's SPARQL implementation that doesn't
look quite right to me. In certain formulations, an OPTIONAL pattern
appears to cause duplication in the results such that where the optional
pattern matches, I get two solutions, one extended with the optional
variable, and one without it.
Take for example:
LOAD <http://xmlns.com/foaf/0.1/> INTO <urn:/test/optional>
Then run the query:
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
SELECT * FROM <urn:/test/optional> WHERE
{ ?id a owl:Ontology . OPTIONAL { { ?id dc:date ?version } UNION { ?id
owl:versionInfo ?version } } }
You get:
0 =>
array (
'id' => 'http://xmlns.com/foaf/0.1/',
'id type' => 'uri',
'version' => '$Date: 2007-06-16 23:18:26 $',
'version type' => 'literal',
),
1 =>
array (
'id' => 'http://xmlns.com/foaf/0.1/',
'id type' => 'uri',
),
It seems that the unbound solution { ?id owl:versionInfo ?version } from
the alternative UNION pattern is still being used to extend the
solution, which to my interpretation of the spec is not right. I tried
this out in Virtuoso before raising the issue here, and Virtuoso seems
to agree with me...I only get the one solution.
Or is there something I have misunderstood about it all?
Thanks,
Will