1

我有一个用 protege 4.2 创建的 owl 文件。当我使用 Jena 添加一些实例时,Jena 更改了文件结构,但文件扩展名保持不变(.owl),该文件在 protege 中是可读的,但有一些错误。任何人都知道我的代码的问题在哪里?

因为在使用 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");


}

}
4

1 回答 1

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

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

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

于 2013-01-29T14:58:49.083 回答