I try to query a database like this:
from rdflib import Graph, Literal, URIRef
from rdflib.namespace import RDF, SKOS
from rdflib.plugins.stores import sparqlstore
# define endpoint according to https://www.stardog.com/docs/
endpoint = 'http://path/to/query' # http://<server>:<port>/{db}/query
# create store
store = sparqlstore.SPARQLUpdateStore()
# I only want to query
store.open(endpoint)
store.setCredentials('me', 'my_pw')
# What does this actually do? That runs through
default_graph = URIRef('some:stuff')
ng = Graph(store, identifier=default_graph)
# # If identifier is not defined, it crashes
# ng = Graph(store)
rq = """
SELECT ?foo ?bar
WHERE {
?something a <http://path/to/data/.ttl#SomeValues>.
?something <http://path/to/data/.ttl#foo> ?foo.
?something <http://path/to/data/.ttl#bar> ?bar.
}
"""
query_res = ng.query(rq)
for s, l in query_res:
print(s, l)
Unfortunately, I don't get any results at the moment:
<head><variable name="foo"></variable><variable name="bar"></variable></head><results></results></sparql>
My question is, what the identifier
in Graph
is doing i.e. whether this is important and if so, how it should be defined. When I do not define it, the code crashes with:
Response: b'{"message":"No separator character found in the URI: N53e412e0f3a74d6eab7ed6da163463bf"}'
If I put in anything else that has a colon, or slash in it, it runs through (but the query still does not return anything).
Could anyone briefly explain, what one should put in there and whether this might be the cause for the unsuccessful query (the query command itself is correct; when I call it from another tool, it works fine)?