0

I am using python to insert data into blazegraph. I saw in the documentation of SparqlWrapper that I can set the defaultGraph as its parameter.

wrapper = SPARQLWrapper("http://localhost:9999/blazegraph/namespace/kbss/sparql", defaultGraph='http://example.org/defaultName')

However, data still gets inserted into the default named graph bd:nullGraph. How could I solve this issue and insert data into http://example.org/defaultName?

I also tried like this:


from SPARQLWrapper import SPARQLWrapper, JSON
from rdflib.plugins.shared.jsonld.keys import JSON

sparql = SPARQLWrapper("http://localhost:9999/blazegraph/namespace/kbss/sparql", defaultGraph='http://example.org/default')

queryString = '''
INSERT { <http://example/egbook3> <http://purl.org/dc/elements/1.1/title>  "This is an example title". } where {}
'''
sparql.addParameter("default-graph-uri", 'http://example.org/default')
sparql.setQuery(queryString)
sparql.method = 'POST'
sparql.query()

But still the same result-inserting data into the bd:nullGraph.

Ian Kurtis
  • 137
  • 7
  • https://stackoverflow.com/questions/69826998/how-to-insert-data-into-named-graph-using-sparql : updates are not queries. – AndyS Nov 08 '21 at 16:10
  • @AndyS the SPARQLWrapper code is fine, they do not distinguish between update and query when creating the request, see the example [in their Wiki](https://github.com/RDFLib/sparqlwrapper#sparql-update-example) - and I mean, the data is inserted, just not in a named graph. – UninformedUser Nov 08 '21 at 17:13
  • is the command `INSERT DATA { GRAPH { "This is an example title". } }` not working? Is `http://example.org/default` a named graph in Blazegraph or what is it? You can also try add the HTTP param`context-uri` with value `https://example.org/default` – UninformedUser Nov 08 '21 at 17:19
  • 1
    `default-graph-uri` is for queries, not updates (Nearest is "using-graph-uri" and it does not influence the place the triples get added, only the WHERE pattern). – AndyS Nov 08 '21 at 21:31
  • `sparql = SPARQLWrapper("http://localhost:9999/blazegraph/namespace/kbss/sparql/update") queryString = ''' INSERT DATA { GRAPH { "This is an example title". } where {} ''' sparql.setQuery(queryString) sparql.method = 'POST' sparql.query()` It worked for me – rshar Apr 20 '23 at 12:35

0 Answers0