0
我在eclipse中使用owl api 4.0。該ontotlogy是這樣設計的,一個人擁有的屬性,每個屬性都有,如下圖所示inturn子屬性: - 使用OWL API分別檢索數據屬性的DataProperties和Sub屬性
我想單獨檢索即canCraw,canBreath,腿的主要屬性,然後它們的子屬性。我用下面的代碼: -
OWLClass animalCl = datafactory.getOWLClass(IRI.create(myOntologyIRI + "Animal")); // Animal is the Class name
NodeSet<OWLNamedIndividual> animalIndl = reasoner.getInstances(animalCl, false);
for (OWLNamedIndividual animalNamedIndl : animalIndl.getFlattened())
{
line1: Set<OWLDataPropertyAssertionAxiom> animalPropAll= myOntology.getDataPropertyAssertionAxioms(animalNamedIndl);
mainprop: for (OWLDataPropertyAssertionAxiom ax: animalPropAll)
{
System.out.println("the propery retrieved = " + ax.getProperty()) ; // the sub properties are printed out here alongwith main properties
line2: NodeSet<OWLDataProperty> properties = reasoner.getSubDataProperties((OWLDataProperty) ax.getProperty(), false);
subprop: for (OWLDataProperty mysubproperty : properties.getFlattened())
System.out.println("and the sub property is " + mysubproperty); // this is where i expect the sub properties of the properties
}
}
的上述代碼的輸出是: -
the property retrieved = <http://localhost:3030/BiOnt.owl#canCrawl> // this is fine
the property retrieved = <http://localhost:3030/BiOnt.owl#crawlWt> // why is this sub property being printed here? (printing from mainprop for loop)
and the sub property is <http://localhost:3030/BiOnt.owl#crawlWt> // this is fine (printing from subprop for loop)
.
.
.
the property retrieved = <http://localhost:3030/BiOnt.owl#legs> // this is fine
the property retrieved = <http://localhost:3030/BiOnt.owl#legsWt> // why is this sub property being printed here?
and the sub property is <http://localhost:3030/BiOnt.owl#legsWt> // this is fine
我在做什麼錯。提前致謝。
感謝您的回覆。我修改了代碼。問題與第2行無關(您在答案中提到過)。問題是第1行。第1行不僅生成屬性,還生成這些屬性的子屬性。即getDataPropertyAssertionAxioms(animalNamedIndl)不僅打印個人'animalNamedIndl'的3個屬性,還打印這些屬性的3個子屬性,如我的問題中的快照中所示。 – learner 2014-10-21 19:30:31
該文檔說getDataPropertyAssertionAxioms返回本體中包含的具有指定個體作爲公理的主題的屬性。通過這個定義,所有的屬性和子屬性將被返回。我的問題是,如果我只想檢索主要屬性,那麼該怎麼做? – learner 2014-10-21 19:50:15
在這種情況下,您將不得不導航屬性層次結構。向推理者詢問TopDataProperty的直接子屬性,然後迭代結果以獲取下一級子屬性。 – Ignazio 2014-10-21 22:25:09