Strange behavior

8 views
Skip to first unread message

Pedro Ferreira

unread,
Jan 22, 2008, 6:28:24 PM1/22/08
to rdflib-dev
Hello.
I'm sorry if the question is dumb, but... considering the following
segment of code:

from rdflib.Graph import ConjunctiveGraph

g = ConjunctiveGraph()
fd = open('test.rdf','r')

g.parse(fd)
res1 = g.query("SELECT ?x ?y ?z WHERE {?x ?y ?z .}")

res2 = []
t = g.triples((None,None,None))
for r in t :
res2.append(r)

print len(res1), len(res2)


shouldn't the output be N, N , being N the number of triples in the
RDF graph? Strangely, the query is not working for me. Maybe I'm not
using it in the right way?

Thanks in advance,

Pedro

Sidney

unread,
Jan 22, 2008, 8:29:40 PM1/22/08
to rdfli...@googlegroups.com
Try this: print res1

'res1' is a sparql query result, which is different then a set of triples.

Try this instead:

res1 = g.query("CONSTRUCT { ?x ?y ?z } WHERE { ?x ?y ?z }")
triples1 = list(res1.triples((None,None,None)))

res2 = list(g.triples((None,None,None))

print len(triples1), len(res2)

....

They should be the same.

SELECT will return a sparql query result type. See module
rdflib.sparql.QueryResult for available serialization methods.

CONSTRUCT, DESCRIBE will return a graph.

ASK will return a boolean.

Best of luck.

Pedro Ferreira

unread,
Jan 23, 2008, 2:05:28 AM1/23/08
to rdflib-dev
I get this error:

Traceback (most recent call last):
File "testrdflib.py", line 15, in <module>
triples1 = list(res1.triples((None,None,None)))
AttributeError: 'SPARQLQueryResult' object has no attribute 'triples'

Thanks for your help,

Pedro

Pedro Ferreira

unread,
Jan 23, 2008, 3:09:13 AM1/23/08
to rdflib-dev
Hello.
OK, I guess you meant:

res1 = g.query("CONSTRUCT { ?x ?y ?z } WHERE { ?x ?y ?z }")
triples1 = list(list(res1)[0].triples((None,None,None)))

res2 = list(g.triples((None,None,None)))


but the result is the same :(

Cheers,

Pedro

Pedro Ferreira

unread,
Feb 3, 2008, 2:22:26 PM2/3/08
to rdflib-dev
OK, it's solved. I was using the dev branch, whose sparql support was
broken...
Reply all
Reply to author
Forward
0 new messages