我使用OWL-API创建了Ontology。我已经使用数组添加了Instances。但是Ontology按字母顺序表示它,而不是按照我在数组中包含的顺序。因此,其他情况不匹配。
String Item1_List[]={"PencilBox","Box"};
int Item1_QuntList[] = {5,4};
Set<OWLAxiom> axioms = new HashSet<OWLAxiom>();
for( int i=0 ; i<Item1_List.length ; i++){
axioms.add(df.getOWLDataPropertyAssertionAxiom(Item1_Name, Item1,Item1_List[i])); }
for( int i=0 ; i<Item1_QuntList.length ; i++){
axioms.add(df.getOWLDataPropertyAssertionAxiom(Item1_Quantity,Item1,Item1_QuntList[i])); }
manager.addAxioms(ontology2, axioms);
这是输出本体。
<!-- Item1 -->
<owl:NamedIndividual rdf:about="http://www.semanticweb.org/imesha/ontologies/2015/7/untitled-ontology-26#Item1">
<rdf:type rdf:resource="http://www.semanticweb.org/imesha/ontologies/2015/7/untitled-ontology-26#Item"/>
<Item1_Name rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Box</Item1_Name>
<Item1_Name rdf:datatype="http://www.w3.org/2001/XMLSchema#string">PencilBox</Item1_Name>
<Item1_Quantity rdf:datatype="http://www.w3.org/2001/XMLSchema#integer">4</Item1_Quantity>
<Item1_Quantity rdf:datatype="http://www.w3.org/2001/XMLSchema#integer">5</Item1_Quantity>
<has rdf:resource="http://www.semanticweb.org/imesha/ontologies/2015/7/untitled-ontology-26#Item2"/>
</owl:NamedIndividual>
实例“Box”位于实例“PencilBox”之前。我怎么能避免这个?
答案 0 :(得分:1)
本体被定义为一组公理。订单未指定且与语义无关。当编辑本体时,owl api会尝试使其保持不变,以减少对源控制系统中可能保存的文件的更改 - 例如git存储库。
为什么需要以特定顺序表示实例?
编辑:添加示例以跟进评论。
Pencil
和Box
字符串似乎代表具有附加属性的个人,例如quantity
属性。可以使用以下代码获得不依赖于将数量附加到个人的顺序的替代建模:
代码:
OWLIndividual Item1 = df.getOWLNamedIndividual(IRI.create("http://test.com/test#Item1"));
OWLObjectProperty Item1_Name = df.getOWLObjectProperty(IRI.create("http://test.com/test#Item"));
OWLDataProperty Item1_Quantity = df.getOWLDataProperty(IRI.create("http://test.com/test#Quantity"));
OWLIndividual Item1_List[] = { df.getOWLNamedIndividual(IRI.create("http://test.com/test#PencilBox")), df
.getOWLNamedIndividual(IRI.create("http://test.com/test#Box")) };
int Item1_QuntList[] = { 5, 4 };
Set<OWLAxiom> axioms = new HashSet<OWLAxiom>();
for (int i = 0; i < Item1_List.length; i++) {
axioms.add(df.getOWLObjectPropertyAssertionAxiom(Item1_Name, Item1, Item1_List[i]));
axioms.add(df.getOWLDataPropertyAssertionAxiom(Item1_Quantity, Item1_List[i], Item1_QuntList[i]));
}
输出:
<?xml version="1.0"?>
<rdf:RDF xmlns="owlapi:ontology#ont1#"
xml:base="owlapi:ontology#ont1"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:test="http://test.com/test#"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:xml="http://www.w3.org/XML/1998/namespace">
<owl:Ontology rdf:about="owlapi:ontology#ont1"/>
<owl:ObjectProperty rdf:about="http://test.com/test#Item"/>
<owl:DatatypeProperty rdf:about="http://test.com/test#Quantity"/>
<owl:NamedIndividual rdf:about="http://test.com/test#Box">
<test:Quantity rdf:datatype="http://www.w3.org/2001/XMLSchema#integer">4</test:Quantity>
</owl:NamedIndividual>
<owl:NamedIndividual rdf:about="http://test.com/test#Item1">
<test:Item rdf:resource="http://test.com/test#Box"/>
<test:Item rdf:resource="http://test.com/test#PencilBox"/>
</owl:NamedIndividual>
<owl:NamedIndividual rdf:about="http://test.com/test#PencilBox">
<test:Quantity rdf:datatype="http://www.w3.org/2001/XMLSchema#integer">5</test:Quantity>
</owl:NamedIndividual>
</rdf:RDF>