如何使用owlapi 5.1检索OWL类的子类?

问题描述 投票:0回答:1

我正在重写一个Java程序,该程序读取OWL文件并构建图形数据库。该程序使用了较旧的OWLAPI版本,现已弃用了许多get方法。我已经重构了代码以使用Stream。现在,我正在尝试检索OWL文件中每个类的子类。

使用OWLSubClassOfAxiom,我可以检索所需的子类,但是我仍然需要过滤结果以仅获取子类

    final OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
    OWLOntology ontology = load(manager);

    //--create a reasoner to check that the ontology is consistent
    OWLReasonerFactory reasonerFactory = new 
    StructuralReasonerFactory();
    OWLReasoner reasoner = reasonerFactory.createReasoner(ontology);
    reasoner.precomputeInferences();
    boolean consistent = reasoner.isConsistent();


    if (consistent) {
      //--get all classes in the ontology
      for (OWLClass oc : ontology.classesInSignature().collect(Collectors.toSet())) {
          System.out.println( "Class: " + oc.toString() );
          //--get all the SubClassOfAxiom of each class
          for (OWLSubClassOfAxiom sca: ontology.subClassAxiomsForSuperClass(oc).collect(Collectors.toSet())) {
            System.out.println( "    Subclass: " + sca.toString() );
          }
        }
    }

输出示例如下:

Class: <http://www.nist.gov/el/ontologies/kitting.owl#PoseLocation>
    Subclass: SubClassOf(<http://www.nist.gov/el/ontologies/kitting.owl#PoseLocationIn> <http://www.nist.gov/el/ontologies/kitting.owl#PoseLocation>)

在此示例中,使用owlapi 5.1,如何检索PoseLocationIn,它是PoseLocation的子类?

java owl owl-api
1个回答
0
投票

使用Searcher类,它是对从OWLAPI 3到5删除的方法的方便替代。Searcher::getSubClasses做同样的工作。

© www.soinside.com 2019 - 2024. All rights reserved.