berlinguyinca berlinguyinca -4 years ago 97
Java Question

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 method 'getClassesInSignature', but the documentation (JavaDocs) are lacking a bit in regards, what should be used instead.

thanks!

Answer Source

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);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download