RDFLib/rdfextras — Issue #10: OPTIONAL doesn't work in SPARQL queries
Author: gjhiggins
Created: 2012-02-20 07:57:04+00:00
State: closed

gjhigg...@gmail.com, 2010-09-14T22:27:35.000Z

Imported from rdflib http://code.google.com/p/rdflib/issues/detail?id=92

Extant in rdfextras.

import rdflib
rdflib.plugin.register('sparql', rdflib.query.Processor,
'rdfextras.ccfsparql.processor', 'Processor')
rdflib.plugin.register('sparql', rdflib.query.Result,
'rdfextras.ccfsparql.QueryResult', 'SPARQLQueryResult')
from rdflib.graph import ConjunctiveGraph
from rdflib.term import URIRef
x = ConjunctiveGraph()
x.add((URIRef("http://a"), URIRef("http://b"), URIRef("http://c")))
print(list(x.query("SELECT ?s WHERE { ?s ?p ?o } ",
processor="sparql",initNs={},initBindings={},DEBUG=False)))
# [rdflib.term.URIRef('http://a')
# Expect to get the same result with OPTIONAL:
print(list(x.query("SELECT ?s WHERE { OPTIONAL { ?s ?p ?o } } ",
processor="sparql",initNs={},initBindings={},DEBUG=False)))
# []

Comment 1 by cuu...@gmail.com
Confirming this still is an issue in current rdfextras (hgsnapshot-20100728)

Comment 2 by christop...@gmail.com
See issue 7 for a patch to solve both issues. Also see rdflib-dev mailing list (http://groups.google.com/group/rdflib-dev/topics) for a discussion on this.

Comment 3 by gromgull
This issue was closed by revision 136351810d66.