One version of the problem is included below. I thought that there might be an issue with how I have to name the graphs I want to select in the query, but actually it seems to me that things already go wrong with parsing the query. From the sources it looks to me that FROM, FROM NAMED and also FROM DEFAULT clauses should be recognized, if not implemented.
Can anyone point me to a way to get this working? In the docs or sources, nor on the Web I have found any working examples.
Thanks in advance!
Jeroen.
===== mytest.py =====
from rdflib import Graph, Dataset, URIRef
from rdflib.graph import DATASET_DEFAULT_GRAPH_ID
ds = Dataset()
ng1 = Graph(ds.store, identifier=URIRef('http://www.example.org/ds-ng-1'))
ng2 = Graph(ds.store, identifier=URIRef('http://www.example.org/ds-ng-2'))
gdef = Graph(ds.store, identifier=DATASET_DEFAULT_GRAPH_ID)
gdef.parse(data='''
@prefix dc: <http://purl.org/dc/elements/1.1/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
<http://www.example.org/ds-ng-1> dc:date "2005-07-14T03:18:56+0100"^^xsd:dateTime .
<http://www.example.org/ds-ng-2> dc:date "2005-09-22T05:53:05+0100"^^xsd:dateTime .
''', format='turtle')
ng1.parse(data='''
@prefix dc: <http://purl.org/dc/elements/1.1/> .
[] dc:title "Harry Potter and the Philospher's Stone" .
[] dc:title "Harry Potter and the Chamber of Secrets" .
''', format='turtle')
ng2.parse(data='''
@prefix dc: <http://purl.org/dc/elements/1.1/> .
[] dc:title "Harry Potter and the Sorcerer's Stone" .
[] dc:title "Harry Potter and the Chamber of Secrets" .
''', format='turtle')
queryString = '''
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
SELECT *
FROM NAMED <http://www.example.org/ds-ng-1>
FROM NAMED <http://www.example.org/ds-ng-2>
}
{ ?s ?p ?o } UNION { GRAPH ?g { ?s ?p ?o } }
}
'''
qres = ds.query(queryString)
for row in qres:
print(row)
===== result =====
Traceback (most recent call last):
File "/Users/(...)/Developer/Eclipse workspace/RDFTutorial/src/sparqltest/mytest.py", line 44, in <module>
qres = ds.query(queryString)
File "/Users/(...)/Developer/Eclipse workspace/RDFTutorial/rdflib_sources/rdflib_4.2.2_dev/rdflib/graph.py", line 1084, in query
query_object, initBindings, initNs, **kwargs))
File "/Users/(...)/Developer/Eclipse workspace/RDFTutorial/rdflib_sources/rdflib_4.2.2_dev/rdflib/plugins/sparql/processor.py", line 72, in query
parsetree = parseQuery(strOrQuery)
File "/Users/(...)/Developer/Eclipse workspace/RDFTutorial/rdflib_sources/rdflib_4.2.2_dev/rdflib/plugins/sparql/parser.py", line 1053, in parseQuery
return Query.parseString(q, parseAll=True)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pyparsing.py", line 1041, in parseString
raise exc
pyparsing.ParseException: Expected "{" (at char 194), (line:8, col:1)
===== end =====
It did not solve the problem completely, however.
Thanks to your second answer I found that my second and real mistake was the way I made reference to the graphs in the FROM NAMED clause.
This is now cleared up and I can move on. Everything works, including a FROM clause. Thanks again!
Jeroen.
Op zaterdag 28 november 2015 00:09:13 UTC+1 schreef gjh:
Op zaterdag 28 november 2015 00:09:13 UTC+1 schreef gjh:
Op zaterdag 28 november 2015 00:09:13 UTC+1 schreef gjh: