edit uri of existing resource using jena

╄→гoц情女王★ 提交于 2019-12-17 14:54:36

问题


I try to modify the uri of an existing resource of a ontology model. I thought of creating a new model, new resource (including the new desired uri) and duplicating the content of the old resource.

By iterating and adding the statements doens't work properly. Is there another workaround?

I'm working with jena in java and RDF/XML models.


回答1:


As you've found resources are immutable. You can bring about the same effect using ResourceUtils.renameResource(resource, newName). This goes through your model removing statements mentioning the old resource and adding the equivalents with the new, which is as close as you're going to get to a rename.

Example:

Resource renamed = 
  ResourceUtils.renameResource(originalResource, "http://example.com/new");



回答2:


Use ResourceUtils.renameResource(oldResource, newURI). It does the iteration over all triples for you.




回答3:


If you are doing this on a large database, it may be better to dump the database to Turtle or N-Triples, run a text changing script, and reload the database.



来源:https://stackoverflow.com/questions/12914890/edit-uri-of-existing-resource-using-jena

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!