耶拿(Jena)将路径/URL添加到URI [英] Jena adds path/url to URIs
问题描述
我刚刚开始使用RDF和Jena.
我得到了一个RDF模型,我想再次读取,修改和写出它.
假设我的模型文件位于http://xyz/model.ttl
,并且包含带有URI"someURI"的元素.
当我这样做
I just started working with RDF and Jena.
I got a RDF model which I want to read, modify and write out again.
Assume my model file is located at http://xyz/model.ttl
and contains an element with URI "someURI".
When I do
Model model = ModelFactory.createDefaultModel();
model.read("http://xyz/model.ttl", "", "TURTLE");
model.write(System.out, "TURTLE");
输出中的URI从"someURI"更改为http://xyz/someURI
.
当我从本地文件系统读取模型时,URI更改为file://pathToFile/someURI
.
有没有办法避免这种行为并保持URI不变?
the URI in the output changes from "someURI" to http://xyz/someURI
.
When I read the model from the local filesystem, the URI changes to file://pathToFile/someURI
.
Is there a way to avoid this behaviour and keep the URI unchanged?
推荐答案
在RDF(例如HTML)中,相对于基本URL(通常是源文档的URL)解析URL(/URI/IRI).
In RDF (like HTML) URLs (/ URIs / IRIs) are resolved relative to a base URL, typically the URL of the source document.
因此,在http://xyz/model.ttl
中读取someURI
变为http://xyz/someURI
,并且从文件中获得file://pathToFile/someURI
.
So reading someURI
in http://xyz/model.ttl
becomes http://xyz/someURI
, and from a file you get file://pathToFile/someURI
.
您可以通过提供一个明确的基数来避免这种情况,这将使结果URL在各个源之间保持一致.
You can avoid this by supplying an explicit base, which will make the resulting URLs consistent across sources.
model.read("http://xyz/model.ttl", "http://xyz/model.ttl", "TURTLE");
// or with same result
model.read(fileSource, "http://xyz/model.ttl", "TURTLE");
并相对化结果:
model.write(System.out, "TURTLE", "http://xyz/model.ttl");
(文档指出,已将写作,这似乎很奇怪)
(The documentation states that the base and lang arguments are switched for reading and writing, which seems odd)
这篇关于耶拿(Jena)将路径/URL添加到URI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!