更新 Triplestore 中的 RDF
我正在尝试使用 Sesame 和 Virtuoso Triplestores。目前,我使用 Sesame Java API 将 RDF 数据添加到两个 Triplestore。
我的 RDF 数据代表不同的事物,例如视频数据、用户数据等。 目前,我可以将视频的 RDF(标题、描述、位置等)添加到 Triplestore,
但是如何更新商店中的 RDF?
例如,如果我使用芝麻的 REST 接口并使用更新的 RDF 发出 PUT 请求,则商店中的所有内容都会首先被删除。
当我将 POST 与更新的数据一起使用时(例如视频的标题已更改),两个标题(旧的和新的)都会被存储。
你们如何与三网店合作? 也许我在这里错过了一些重要的东西。
编辑:
我现在对每个 RDF 条目使用 Sesame 中的 Context 和 Virtuoso 中的 Graphs。通过这种方式进行更新,我可以先清除上下文,然后再次添加。由于我对两个 Triplestore 使用 Sesame API(我们仍然不知道要使用哪一个),因此代码看起来完全相同。
ValueFactory f = rep.getValueFactory();
URI uri = f.createURI(urn);
con.clear(uri);
con.add(reader,this.baseURI, RDFFormat.RDFXML,uri);
谢谢你的帮助
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 clear 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我假设您正在使用 SPARQL。如果您不这样做,那么您可能应该:-)
许多三重存储支持 SPARQL 更新,一种用于修改 SPARQL 存储中的 RDF 三元组的语言。就像SQL的INSERT、UPDATE、DELETE等。我不确定 Sesame 是否还支持它——SPARQL Update 仍然是一个非常新的规范,甚至还没有完全确定。
另一个需要注意的有用的事情是 命名图。这允许管理不同图表中的三元组,因此您可以将数据分开。例如,您可以将每个视频的三元组保留在单独的命名图中,然后在 PUT 请求上仅更新该命名图。您仍然可以使用 SPARQL 跨所有命名图查询整个存储。同样,我也不完全确定 Sesame 的 REST API 是否提供对命名图的访问。 (我很确定 Java API 确实如此;但我认为他们称之为不同的东西。上下文?)
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?)
因此,以标题的具体示例为例,假设您有原始的 RDF,如下所示:
并且您希望将其更改为:
使用 Sesame 的 POST 仅向命名图形添加新信息(芝麻中的上下文)术语),重要的是它不会删除任何现有信息。
在 RDF 术语中,这两个三元组代表不同的事实。 Sesame(或任何其他三元组存储)不知道第二个三元组应该取代第一个。这与您可能习惯更新属性的传统 SQL/关系模型有很大不同,RDF 对此没有正确的概念,因为您无法修改三元组本身。您可以添加新的三元组或删除现有的三元组。
要获得您想要的更新行为,您必须删除旧的三元组(Sesame 的 REST API 为此支持 HTTP DELETE),然后添加新的三元组来替换它(如您当前所做的那样,使用 Sesame 的 POST 操作)。
这同样适用于您使用的几乎所有三重存储。如果像 cyrgi 建议您使用 SPARQL 更新支持存储,那么您可以向更新端点发出以下命令(假设您使用命名图):
So taking your concrete example of a title assuming you have the original RDF like so:
And you want to change it to be something like:
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: