[redland-dev] Status of OPTIONAL
Seaborne, Andy
andy.seaborne at hp.com
Wed Mar 21 09:41:05 UTC 2007
-------- Original Message --------
> From: Richard Newman <>
> Date: 20 March 2007 20:10
>
> Try nesting them.
>
> PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?name ?mbox ?hpage
> WHERE { ?x foaf:name ?name . OPTIONAL {
> ?x foaf:mbox ?mbox .
> OPTIONAL { ?x foaf:homepage ?hpage }
> }
> }
>
> The semantics should be the same, and it might work (that's a problem
> with a few RDF toolkits).
>
> -R
The semantics aren't the same!
Pattern 1:
WHERE { ?x foaf:name ?name .
OPTIONAL { ?x foaf:mbox ?mbox } .
OPTIONAL { ?x foaf:homepage ?hpage } }
Pattern 2:
WHERE { ?x foaf:name ?name .
OPTIONAL {
?x foaf:mbox ?mbox .
OPTIONAL { ?x foaf:homepage ?hpage }
In pattern 2, ?hpage can only be bound if ?mbox is also bound.
If ?mbox does not match, it will fail the outer OPTIONAL and so the inner one, with ?hpage, will not return a binding regardless of whether the inner pattern matches.
In pattern 1, one, both or neither of ?mbox, ?hpage can be bound.
Andy
>
>
> On 20 Mar 2007, at 1:06 PM, Knud Hinnerk Möller wrote:
>
> > Hi,
> >
> > I know OPTIONAL doesn't work properly yet - do you have any idea when
> > it will? Single OPTIONALS seem to work fine, but multiples don't seem
> > to work. In particular, this query from the SPARQL spec seems to work:
> >
> > PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?name ?mbox WHERE {
> > ?x foaf:name ?name . OPTIONAL { ?x foaf:mbox ?mbox }
> > }
> >
> > But this one doesn't:
> >
> > PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?name ?mbox ?hpage
> > WHERE { ?x foaf:name ?name .
> > OPTIONAL { ?x foaf:mbox ?mbox } .
> > OPTIONAL { ?x foaf:homepage ?hpage } }
> >
> > The first OPTIONAL is ignored, and the query evaluates identically to:
> >
> > PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?name ?mbox ?hpage
> > WHERE { ?x foaf:name ?name .
> > ?x foaf:mbox ?mbox .
> > OPTIONAL { ?x foaf:homepage ?hpage } }
> >
> > In the meantime, are there any code examples that show how to do a
> > workaround programmatically?
> >
> > Cheers,
> > Knud
> > -------------------------------------------------
> > Knud Möller, MA
> > +353 - 91 - 495086
> > Digital Enterprise Research Institute
> > National University of Ireland, Galway Institiúid Taighde na
> > Fiontraíochta Digití Ollscoil na hÉireann, Gaillimh
> >
> >
> > _______________________________________________
> > redland-dev mailing list
> > redland-dev at lists.librdf.org
> > http://lists.librdf.org/mailman/listinfo/redland-dev
>
> _______________________________________________
> redland-dev mailing list
> redland-dev at lists.librdf.org
> http://lists.librdf.org/mailman/listinfo/redland-dev
More information about the redland-dev
mailing list