gjhiggins/rdfextras — Issue #10: query() behaves differently whether i ask for named variables or for *
Author: gjhiggins
Created: 2011-10-19 02:59:08+00:00
State: open

Originally filed by gjhigg...@gmail.com on 2010-09-14T22:52:30

Issue 99 migrated from rdflib

see http://paste.lisp.org/display/92767

I get answers with

res = g.query("SELECT ?g ?s ?p ?o WHERE { GRAPH ?g { ?s ?p ?o } } ")

... but if I use "SELECT * WHERE (etc...)" it fails - ValueError: need more
than 0 values to unpack

http://www.w3.org/TR/rdf-sparql-query/#select

"The SELECT form of results returns variables and their bindings directly. The syntax
SELECT * is an abbreviation that selects all of the variables in a query."

Persisted into rdfextras.

from rdflib.graph import ConjunctiveGraph
import rdflib
rdflib.plugin.register('sparql', rdflib.query.Processor,
'rdfextras.sparql.processor', 'Processor')
rdflib.plugin.register('sparql', rdflib.query.Result,
'rdfextras.sparql.query', 'SPARQLQueryResult')
g = ConjunctiveGraph()
g.parse("http://inkdroid.org/journal/network", format='rdfa', lax=True)
g.parse("http://danbri.org/words/network", format='rdfa', lax=True)

res = g.query("SELECT ?g ?s ?p ?o WHERE { GRAPH ?g { ?s ?p ?o } } ",
processor="sparql",initNs={},initBindings={},DEBUG=False)
for src, sub, pred, obj in res:
print src, sub, pred, obj

res = g.query("SELECT * WHERE { GRAPH ?g { ?s ?p ?o } } ",
processor="sparql",initNs={},initBindings={},DEBUG=False)
for src, sub, pred, obj in res:
print src, sub, pred, obj

ValueError: need more than 0 values to unpack