从耶拿提取 FOAF 信息

发布于 2024-12-06 19:36:47 字数 1031 浏览 0 评论 0原文

我是新来的,我有一些关于 FOAF 的问题。我使用 jena 创建一个这样的 FOAF :

<rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person"/>
    <foaf:phone>12312312312</foaf:phone>
    <foaf:nick>L</foaf:nick>
    <foaf:name>zhanglu</foaf:name>

但我想要 FOAF 显示如下:

<foaf:Person>
    <foaf:phone>12312312312</foaf:phone>
    <foaf:nick>L</foaf:nick>
    <foaf:name>zhanglu</foaf:name>
</foaf:Person>

我能做什么?

这是我的源代码:

Model m = ModelFactory.createDefaultModel();
m.setNsPrefix("foaf", FOAF.NS);

Resource r = m.createResource(NS);
r.addLiteral(FOAF.name, "zhanglu");
r.addProperty(FOAF.nick, "L");
r.addProperty(FOAF.phone, "123123123");
r.addProperty(RDF.type, FOAF.Person);

FileOutputStream f = new FileOutputStream(fileName);
m.write(f);

谁能告诉我? 谢谢

I'm new here,and i have some problem about FOAF. I use jena create a FOAF like this :

<rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person"/>
    <foaf:phone>12312312312</foaf:phone>
    <foaf:nick>L</foaf:nick>
    <foaf:name>zhanglu</foaf:name>

But i want to the FOAF shows like this:

<foaf:Person>
    <foaf:phone>12312312312</foaf:phone>
    <foaf:nick>L</foaf:nick>
    <foaf:name>zhanglu</foaf:name>
</foaf:Person>

What can i do?

this is my source code:

Model m = ModelFactory.createDefaultModel();
m.setNsPrefix("foaf", FOAF.NS);

Resource r = m.createResource(NS);
r.addLiteral(FOAF.name, "zhanglu");
r.addProperty(FOAF.nick, "L");
r.addProperty(FOAF.phone, "123123123");
r.addProperty(RDF.type, FOAF.Person);

FileOutputStream f = new FileOutputStream(fileName);
m.write(f);

who can tell me?
thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

┈┾☆殇 2024-12-13 19:36:47

首先要说的是,您引用的两种形式对于 RDF 具有完全相同的含义 - 也就是说,它们在解析为 RDF 图时产生完全相同的三元组集合。因此,通常不必担心编写者生成的 XML 的确切语法。一般来说,RDF/XML 并不是一种易于阅读的语法。如果您只想序列化 Model,以便稍后可以再次读取它,我建议 Turtle 语法,因为它更紧凑,更容易人类阅读和理解。

然而,您可能想要特别关心 XML 序列化的原因有一个,即您是否希望文件成为 XML 处理管道(例如 XSLT 或类似管道)的一部分。在这种情况下,您可以通过更改示例的最后一行来生成所需的格式:

m.write( f, "RDF/XML-ABBREV" );

或者等效地,

m.write( f, FileUtils.langXMLAbbrev );

First thing to say is that the two forms that you quote have exactly the same meaning to RDF - that is, they produce exactly the same set of triples when parsed into an RDF graph. For this reason, it's generally not worth worrying about the exact syntax of the XML produced by the writer. RDF/XML is, in general, not a friendly syntax to read. If you just want to serialize the Model, so that you can read it in again later, I would suggest Turtle syntax as it's more compact and easier for humans to read and understand.

However, there is one reason you might want to care specifically about the XML serialization, which is if you want the file to be part of an XML processing pipeline (e.g. XSLT or similar). In this case, you can produce the format you want by changing the last line of your example:

m.write( f, "RDF/XML-ABBREV" );

or, equivalently,

m.write( f, FileUtils.langXMLAbbrev );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文