Question

I inserted RDF formatted data into Sesame in a repository, but when I try to append some more data into that repository, my previous data is gone and new data is being overwritten into that repository. What am I doing wrong?

import urllib2
import urllib 
import httplib2


par = {"text": "he is a good boy"}
headers={"Accept" : "application/rdf+xml"}
request = urllib2.Request("http://wit.istc.cnr.it/stlab-tools/fred/?" + urllib.urlencode(par),headers=headers)
contents = urllib2.urlopen(request).read()
print contents

repository = 'good_boy'
graph      = 'http://wit.istc.cnr.it/sentilo-dev/fred/xdot/graphviz_139546518295.gv'

print "Loading into Sesame"
params = { 'context': '<' + graph + '>' }
endpoint = "http://localhost:3030/openrdf-sesame/repositories/%s/statements?%s" % (repository, urllib.urlencode(params))
(response, content) = httplib2.Http().request(endpoint, 'PUT',
body=contents, headers={ 'content-type': 'application/rdf+xml' })
print "Response %s" % response.status
print content
Was it helpful?

Solution

The problem is that you are using a HTTP PUT request, instead of a POST request, to add your data to the Sesame repository.

A PUT request overwrites existing data, it is a replace (rather than append) operation. See the Sesame REST protocol documentation, particularly the section on adding statements, for details.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top