开发者

Update RDF in Triplestore

I'm experimenting with Sesame and Virtuoso Triplestores. At the Moment I use the Sesame Java API to add RDF Data to both Triplestores.

My RDF Data represents different things like Videodata, Userdata etc. At the moment I can add a RDF of a Video (title, description, location etc.) to the Triplestore

But How can I update a RDF in the store ?

For Example if I use the REST Interface of sesame and make a PUT Request with the updated RDF, everything in the store is removed first.

When I use POST with the updated Data (for example the title of the video has changed), both title (old and new) are stored.

How do you work with triplestores? Maybe I miss here something essential.


EDIT:

I use now Context in Sesame and Graphs in Virtuoso for every RDF entry. This way for update I can clea开发者_运维问答r the context first and add it again. As I use the Sesame API for both Triplestores (we still don't know which one we are going to use), the code looks exactly the same.

ValueFactory f = rep.getValueFactory();
URI uri = f.createURI(urn);
con.clear(uri);
con.add(reader,this.baseURI, RDFFormat.RDFXML,uri);

thanks for the help


I assume you're working with SPARQL. If you don't, then you probably should :-)

Many triple stores support SPARQL Update, a language for modifying RDF triples in a SPARQL store. It's like SQL's INSERT, UPDATE, DELETE and so on. I'm not sure whether Sesame supports it yet—SPARQL Update is still a very new spec that isn't even quite finalised yet.

Another useful thing to be aware of, especially if you want to work in a RESTful way, is Named Graphs. This allows managing triples in different graphs, so you can keep data separate. You could, for example, keep the triples about each video in a separate Named Graph, and then update only that Named Graph on a PUT request. You can still use SPARQL to query the entire store across all Named Graphs. Again I'm not entirely sure if Sesame's REST API provides access to Named Graphs. (I'm pretty sure that the Java API does; I think they call it something different though. Contexts?)


So taking your concrete example of a title assuming you have the original RDF like so:

:something :title "Original Title" .

And you want to change it to be something like:

:something :title "Updated Title" .

Using Sesame's POST only adds new information to a named graph (context in sesame terminology), importantly it does not remove any existing information.

In RDF terms these two triples represent different facts. Sesame (or any other triplestore for that matter) does not know that the 2nd triple should replace the 1st. This is quite different from the traditional SQL/relational model you may be used to where you would update a property, RDF does not have a proper notion of this since you cannot modify a triple as such. You can either add new triples or remove existing triples.

To get the update behaviour you desire you must delete the old triple (Sesame's REST API supports HTTP DELETE for this) and then add the new triple that replaces it (use Sesame's POST operation as you are doing currently).

The same will hold for pretty much any triple store you use. If like cyrgi suggests you use a SPARQL Update supporting store then you can issue the following (assumes you use named graphs) to the update endpoint:

DELETE DATA 
{ 
  GRAPH <http://example.org/graph> { :something :title "Original Title" . }
};
INSERT DATA 
{
   GRAPH <http://example.org/graph> { :something :title "Updated Title" . }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜