Jena将路径/ url添加到URI

时间:2014-08-05 10:15:41

标签: rdf jena

我刚开始与RDF和Jena合作。 我有一个RDF模型,我想再次阅读,修改和写出。 假设我的模型文件位于http://xyz/model.ttl并且包含一个带有URI" someURI"的元素。 当我做的时候

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不变?

1 个答案:

答案 0 :(得分:3)

在RDF(如HTML)中,URL(/ URIs / IRI)相对于基本URL(通常是源文档的URL)进行解析。

因此,在someURI中阅读http://xyz/model.ttl变为http://xyz/someURI,并从文件中获取file://pathToFile/someURI

您可以通过提供明确的基础来避免这种情况,这将使得结果URL在各个来源之间保持一致。

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");

(文档说明基础和lang参数已切换为readingwriting,这似乎很奇怪)

相关问题