Reputation: 189
I am exploring python based library 'RDFlib' with native store (Sleepycat). A basic "select * ..." query works fine but COUNT does not seem to work.
Here is my code:
from rdflib import ConjunctiveGraph, Namespace, Literal
path = './mytriplestore'
graph = ConjunctiveGraph('Sleepycat')
graph.open(path, create = False)
query = """SELECT count(?o)
WHERE {
<http://examplesubject> ?p ?o.
}
Limit 10"""
qres = graph.query(query)
for row in qres:
print row
Error:
File "/usr/local/lib/python2.7/dist-packages/rdflib/graph.py", line 1085, in query
query_object, initBindings, initNs, **kwargs))
File "/usr/local/lib/python2.7/dist-packages/rdflib/plugins/sparql/processor.py", line 74, in query
parsetree = parseQuery(strOrQuery)
File "/usr/local/lib/python2.7/dist-packages/rdflib/plugins/sparql/parser.py", line 1058, in parseQuery
return Query.parseString(q, parseAll=True)
File "/usr/local/lib/python2.7/dist-packages/pyparsing-1.5.7-py2.7.egg/pyparsing.py", line 1006, in parseString
raise exc
pyparsing.ParseException: Expected "?" (at char 7), (line:1, col:8)
Could anyone help me solve this problem?
Upvotes: 0
Views: 859
Reputation: 1
You have to use group by to be able to get result for count, try something like :
query = """SELECT count(?o) As ?count
WHERE {
<http://examplesubject> ?p ?o.
}
GROUP BY ?o
Limit 10"""
Upvotes: 0