我在eclipse中使用owl api 4.0。 ontotlogy的设计使得个人拥有属性,并且每个属性都具有inturn属性,如下图所示: -
我想分别检索主要属性,即canCraw,canBreath,leg和它们的子属性。我使用以下代码: -
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
我做错了什么。提前谢谢。
答案 0 :(得分:1)
reasoner.getSubDataProperties((OWLDataProperty) ax.getProperty(), false);
false
参数表示任何级别的子属性。
如果将其切换为true,则推理器将仅为您提供直接子属性。如果我正确理解您的要求,那就是您正在寻找的内容。