user2302244
user2302244

Reputation: 935

Store add_graph appears to do nothing with rdflib and Fuseki

I have a Fuseki endpoint and want to use the python rdflib library to add graphs to it.

I connect to the Fuseki server as follows:

import rdflib

from rdflib import Graph, Literal, URIRef
from rdflib.plugins.stores import sparqlstore

query_endpoint = 'http://localhost:3030/dsone/query'
update_endpoint = 'http://localhost:3030/dsone/update'
store = sparqlstore.SPARQLUpdateStore()
store.open((query_endpoint, update_endpoint))

Then I set-up an rdflib ConjunctiveGraph as follows:

g = rdflib.ConjunctiveGraph(identifier=URIRef("http://localhost/dsone/g3"))

g.parse(data="""
@base <http://example.com/base> .
@prefix : <#> .
<> a :document1 .
""", format='turtle', publicID = "http://example.com/g3")

g now contains one triple:

for r in g:
    print(r)

Which results in:

(rdflib.term.URIRef('http://example.com/base'), rdflib.term.URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), rdflib.term.URIRef('http://example.com/base#document1'))

Now I add the graph to the store with:

store.add_graph(g)

The server shows a 200 return code. When I do the insert directly over REST, it returns 204 - which could be a clue.

Now there is nothing in the store.

for r in store.query("""
select ?g (count(*) as ?count) {graph ?g {?s ?p ?o .}} group by ?g
"""):
    print(r)

Which has no output.

As far as I can tell store.add_graph(g) is doing nothing.

Any ideas?

Upvotes: 0

Views: 327

Answers (1)

Nicholas Car
Nicholas Car

Reputation: 1241

store.add_graph(g)

Just created the graph itself, it won't take your graph content and put it in there. So add_graph() is really only just using the graph's identifier, not it's data.

Try calling add_graph() then adding data to the graph.

Upvotes: 0

Related Questions