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

How to retrieve subclasses of an OWL class using owlapi 5.1?

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

使用 OWLSubClassOfAxiom 我可以检索我需要的 subclasses 但我仍然需要过滤结果以仅获取 subclass

    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 的子 class?

使用 Searcher class,它旨在方便地替代从 OWLAPI 3 到 5 时删除的方法。Searcher::getSubClasses 做同样的工作。