耶拿模型将我的RDF类型显式声明转换为隐式,并将格式弄乱 [英] Jena Model converts my RDF type explicit declaration to implicit and messes with the format

查看:84
本文介绍了耶拿模型将我的RDF类型显式声明转换为隐式,并将格式弄乱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码,该代码创建具有某些设置属性的RDF资源并将其打印在控制台上.

I have the following code that creates an RDF resource with some set properties and prints it on console.

    String uri = "http://krweb/";
    String name = "Giorgos Georgiou";
    String phone = "6976067554";
    String age = "27";
    String department = "ceid";
    String teaches = "java";

    Model model = ModelFactory.createOntologyModel();
    model.setNsPrefix("krweb", uri);

    Resource giorgosgeorgiou = model.createResource(uri+name.toLowerCase().replace(" ", ""), model.createResource(uri+"Professor"));

    Property has_name = model.createProperty(uri+"has_name");
    Property has_phone = model.createProperty(uri+"has_phone");
    Property has_age = model.createProperty(uri+"has_age");
    Property member_of = model.createProperty(uri+"member_of");
    Property teach = model.createProperty(uri+"teaches");

    giorgosgeorgiou.addProperty(teach, model.createResource(uri+teaches));
    giorgosgeorgiou.addProperty(member_of, model.createResource(uri+department));
    giorgosgeorgiou.addProperty(has_age,age);
    giorgosgeorgiou.addProperty(has_phone,phone);
    giorgosgeorgiou.addProperty(has_name,name);
   //giorgosgeorgiou.addProperty(RDF.type, model.createResource(uri+"Professor"));
    model.write(System.out,"RDF/XML");

我希望模型以这种格式打印:

I want the model printed in this format:

<rdf:Description rdf:about="http://krweb/giorgosgeorgiou">
    <rdf:type rdf:resource="http://krweb/Professor"/>
    <krweb:has_name>Giorgos Georgiou</krweb:has_name>
    <krweb:has_phone>6976067554</krweb:has_phone>
    <krweb:has_age>27</krweb:has_age>
    <krweb:member_of rdf:resource="http://krweb/ceid"/>
    <krweb:teaches rdf:resource="http://krweb/java" />
</rdf:Description>

相反,我得到了:

  <krweb:Professor rdf:about="http://krweb/giorgosgeorgiou">
    <krweb:has_name>Giorgos Georgiou</krweb:has_name>
    <krweb:has_phone>6976067554</krweb:has_phone>
    <krweb:has_age>27</krweb:has_age>
    <krweb:member_of rdf:resource="http://krweb/ceid"/>
    <krweb:teaches rdf:resource="http://krweb/java"/>
  </krweb:Professor>

以某种方式,rdf类型属性被转换为一些隐式声明,并以我认为是漂亮"的格式呈现.有办法绕过这个吗?

Somehow, the rdf type property gets converted to some implicit declaration and is presented in what I suppose is a "pretty" format. Is there a way to bypass this?

推荐答案

内部RDF数据保存为三元组-不知道如何存储它们在输入时的格式.

Internally the RDF data is held as triples - no knowledge of how they were formatted on input is stored.

默认输出是漂亮的RDF/XML.

The default output is pretty RDF/XML.

要使用纯净的平面格式,请使用RDFFormat.RDFXML_PLAIN

To get the plain, flat format use RDFFormat.RDFXML_PLAIN

RDFDataMgr.write(System.out, model, RDFFormat.RDFXML_PLAIN);

这篇关于耶拿模型将我的RDF类型显式声明转换为隐式,并将格式弄乱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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