Jena在添加实例后更改了我的owl文件

时间:2013-01-28 13:12:35

标签: jena owl protege

我有一个使用protege 4.2创建的owl文件。当我使用Jena添加一些实例时,Jena会更改文件结构,但文件扩展名保持不变(.owl),文件可读时会出现一些错误。有人知道我的代码有什么问题吗?

因为使用Jena编辑后,查询的结果有些奇怪。

例如,在使用Jena编辑之前

 <owl:NamedIndividual rdf:about="&ontologies;thesis_ontology_1try#AM6">
    <rdf:type rdf:resource="&ontologies;thesis_ontology_1try#ApplicationModel"/>
    <hasID rdf:datatype="&xsd;string">20125157-d62b-45de-8809-84186c7169b5AM6</hasID>
    <name rdf:datatype="&xsd;string">Gebäudemodell / Buildingmodel</name>
    <hasContent rdf:resource="&ontologies;cpixml"/>
    <hasLevelOfDetail rdf:resource="&ontologies;thesis_ontology_1try#4"/>
    <hasDomain rdf:resource="&ontologies;thesis_ontology_1try#BIM"/>
    <hasType rdf:resource="&ontologies;thesis_ontology_1try#Object"/>
    <hasPhase rdf:resource="&ontologies;thesis_ontology_1try#SLCT"/>
    <hasContent rdf:resource="&ontologies;thesis_ontology_1try#ifc"/>
</owl:NamedIndividual>

耶拿之后

<rdf:Description rdf:about="http://www.semanticweb.org/thato/ontologies/2012/10/9/thesis_ontology_1try#AM6">
<hasContent rdf:resource="http://www.semanticweb.org/thato/ontologies/2012/10/9/cpixml"/>
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#NamedIndividual"/>
<hasDomain rdf:resource="http://www.semanticweb.org/thato/ontologies/2012/10/9/thesis_ontology_1try#BIM"/>
<hasType rdf:resource="http://www.semanticweb.org/thato/ontologies/2012/10/9/thesis_ontology_1try#Object"/>
<hasID rdf:datatype="http://www.w3.org/2001/XMLSchema#string">20125157-d62b-45de-8809-84186c7169b5AM6</hasID>
<hasPhase rdf:resource="http://www.semanticweb.org/thato/ontologies/2012/10/9/thesis_ontology_1try#SLCT"/>
<rdf:type rdf:resource="http://www.semanticweb.org/thato/ontologies/2012/10/9/thesis_ontology_1try#ApplicationModel"/>
<hasContent rdf:resource="http://www.semanticweb.org/thato/ontologies/2012/10/9/thesis_ontology_1try#ifc"/>
<name rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Gebäudemodell / Buildingmodel</name>
<hasLevelOfDetail rdf:resource="http://www.semanticweb.org/thato/ontologies/2012/10/9/thesis_ontology_1try#4"/>
<rdf:type rdf:nodeID="A28"/>
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Thing"/>
<rdf:type rdf:nodeID="A29"/>
<rdf:type rdf:nodeID="A30"/>
<rdf:type rdf:nodeID="A31"/>
<rdf:type rdf:nodeID="A32"/>
<rdf:type rdf:resource="http://www.w3.org/2000/01/rdf-schema#Resource"/>
<rdf:type rdf:nodeID="A33"/>
<rdf:type rdf:nodeID="A34"/>
<rdf:type rdf:nodeID="A12"/>
<rdf:type rdf:nodeID="A15"/>
<rdf:type rdf:nodeID="A35"/>
<rdf:type rdf:nodeID="A5"/>
<Linkedby rdf:resource="http://www.semanticweb.org/thato/ontologies/2012/10/9/thesis_ontology_1try#LM2"/>
<isAMof rdf:resource="http://www.semanticweb.org/thato/ontologies/2012/10/9/thesis_ontology_1try#MMC2"/>

这是代码

public static void main(String[] args) throws IOException {
InputStream in = FileManager.get().open("./src/thesis_ontology_1try.owl");
OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM_MICRO_RULE_INF, null);
model.read(in, null);
in.close();

String NS = "http://www.semanticweb.org/thato/ontologies/2012/10/9/thesis_ontology_1try#";
OntClass ApplicationModel = model.getOntClass(NS + "ApplicationModel");


Individual dom = model.getIndividual(NS + "RFP");
Individual pha = model.getIndividual(NS + "SLCT");
Individual lev =  model.getIndividual(NS + "3");

Individual new1 = model.createIndividual(NS + "new1", ApplicationModel);  

ObjectProperty domain = model.createObjectProperty(NS +"hasDomain");
ObjectProperty phase = model.createObjectProperty(NS +"hasPhase");
ObjectProperty lod = model.createObjectProperty(NS +"hasLevelOfDetail");

model.add(new1, domain, dom);
model.add(new1, phase, pha);
model.add(new1, lod, lev);


PrintStream p= new PrintStream("./src/thesis_ontology_1try.owl");
model.writeAll(p, "RDF/XML", null);
p.close();

System.out.println("Done");


}

}

1 个答案:

答案 0 :(得分:2)

model.writeAll(p, "RDF/XML", null);

尝试“漂亮的打印机”RDF / XML-ABBREV。

但无论哪种方式,它都是相同的三元组,用不同的方式写出来,这才是最重要的。