如何从耶拿(Jena)获取嵌套的RDF/XML? [英] How to get nested RDF/XML from Jena?

查看:97
本文介绍了如何从耶拿(Jena)获取嵌套的RDF/XML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建如下所示的RDF:

I need to create RDF that looks like this:

<rdf:Description rdf:about='uri1'>
  <namespace:level1>
    <rdf:Description>
      <namespace:blankNode rdf:resource='uri2'/>
      <namespace:text></namespace:text> 
    </rdf:Description>
  </namespace:level1>
</rdf:Description>

<rdf:Description rdf:about="uri2">
  some properties here
</rdf:Description>

如您所见,存在嵌套结构以及空白节点. (我不知道这是否是结构中"blankNode"属性的确切术语.)如果我使用

As you can see, there are nested structures, as well as blank nodes. (I don't know if that's the exact terminology for the "blankNode" property in my structure.) If I use

model.write(System.out, "RDF/XML-ABBREV");

然后,即使是空白节点也被嵌套,这是我不想要的.有什么办法可以使用耶拿获得这种结构吗?还是有其他Java库可以更好地处理此问题?

then even the blank node is nested, which I don't want. Is there any way to get this kind of structure using Jena? Or is there any other library for Java that can handle this better?

推荐答案

我认为您的做法是错误的.

I think you're going at this the wrong way.

嵌套是一个仅在谈论树木时才有意义的概念.但是RDF与树木无关,而是三倍.暂时忘掉XML的结构,而想一想XML中编码的三元组.我发现model.write(System.out, "N-TRIPLES");对此最有用.

Nesting is a concept that only makes sense when talking about trees. But RDF is not about trees, it's about triples. Forget for a while about the structure of the XML, and think about the triples that are encoded in the XML. I find model.write(System.out, "N-TRIPLES"); most useful for that.

首先,您需要了解RDF/XML文件要表达的三元组.只要能表达正确的三元组,一个节点是嵌套在另一个节点内还是以什么顺序出现都无所谓.这些都是纯粹的美容"问题,例如缩进.

You first need to understand what triples you want your RDF/XML file to express. As long as it expresses the right triples, it doesn't matter whether the one node is written nested inside the other or what order things appear in. These are purely "cosmetic" questions, like indentation.

这篇关于如何从耶拿(Jena)获取嵌套的RDF/XML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆