Search code examples
javastreamowlowl-api

how to get all the classes defined in an ontology, using owlapi in a none deprecated way


How can I find all the defined classes using owlapi in Java? I'm aware of the deprecated getClassesInSignature method, but the documentation (JavaDocs) are lacking a bit in regards, what should be used instead?


Solution

  • The modern way is to use the java Stream. You can use it like the following :

        Stream<OWLClass> stream = ontology.classesInSignature();
        Set<OWLClass> set = ontology.classesInSignature().collect(Collectors.toSet());
        OWLClass[] array = ontology.classesInSignature().toArray(OWLClass[]::new);