如何检索具有必要和足够限制的所有类的集合

时间:2017-01-30 15:45:50

标签: java ontology owl-api

在OWL API中,我们可以检索:

  • 指定
  • 的子类
  • 指定
  • 的超类
  • 等同于指定
  • 的类集

我想要的是从本体中检索所有 定义的类的集合(具有足够限制的类,即非原始类)。

请问我们怎么做?

例如:

OWLClass CheesyPizza = factory.getOWLClass(":CheesyPizza",pm); 
OWLClassExpression hasCheese_some_restriction = 
            factory.getOWLObjectSomeValuesFrom(hasTopping, CheeseTopping);
OWLClassExpression Pizza_hasCheeseTopping_intersection =
            factory.getOWLObjectIntersectionOf(Pizza, hasCheese_some_restriction);
OWLEquivalentClassesAxiom CheesyPizza_Definition = 
            factory.getOWLEquivalentClassesAxiom(CheesyPizza, Pizza_hasCheeseTopping_intersection);
tempChange.add(new AddAxiom(localOntology, CheesyPizza_Definition));
managerLocal.applyChanges(tempChange);

Cheesy Pizza是一个 Defined 类,假设我们在Ontology中有许多其他定义类(具有必要和充分的类)。 我想获得那些类(换句话说,我想获得在黄色图标中有三行的类)。

据我所知,没有短手功能。因此,我添加了第2部分代码:

OWLOntologyWalker walker = new OWLOntologyWalker(Collections.singleton(localOntology));
OWLOntologyWalkerVisitorEx<Object> visitor = new OWLOntologyWalkerVisitorEx<Object>(walker)
{
 @Override
 public Object visit(OWLEquivalentClassesAxiom ce)
  {
  System.out.println(" " + getCurrentAxiom());
// this will print the relating axioms EquivalentClasses(<http://www.semanticweb.org/ontologies/myontology/CheesyPizza> ObjectIntersectionOf(<http://www.semanticweb.org/ontologies/myontology/Pizza> ObjectSomeValuesFrom(<http://www.semanticweb.org/ontologies/myontology/hasTopping> <http://www.semanticweb.org/ontologies/myontology/CheeseTopping>)) )
// this axioms is correct and it is the axiom we want
// now lets try to get our Class CheesyPizza!
  for (OWLClass clazz : getCurrentAxiom().getClassesInSignature())  
  {
  if(! clazz.isAnonymous())
  System.out.println(clazz);
// this is printing 
//<http://www.semanticweb.org/ontologies/myontology/CheesyPizza>
//<http://www.semanticweb.org/ontologies/myontology/CheeseTopping>
//<http://www.semanticweb.org/ontologies/myontology/Pizza>
  }
}

我只想获得CheesyPizza,Cheesy Pizza定义为代码的第1部分,相当于类pizza和hasCheese_some_restriction之间交集的匿名类。

如何获取CheesyPizza类(它是唯一一个非匿名的类,并且附加了OWLEquivalentClassesAxiom。为什么这么复杂?:(

1 个答案:

答案 0 :(得分:0)

版本5上的OWLOntology::getAxioms(OWLClass c) - 或OWLOntology::axioms(OWLClass c) - 应该执行您正在寻找的内容。