gjhiggins/rdfextras — Issue #8: OPTIONAL doesn't work in SPARQL queries
Author: gjhiggins
Created: 2011-10-19 02:58:52+00:00
State: open

Originally filed by gjhigg...@gmail.com on 2010-09-14T22:27:35

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)))
# []