Using OWLAPI Version 3.5.0.
Is it possible to get all OWLAnonymousClassExpressions within an ontology? Or even the OWLAnonymousClassExpressions that belong to a single OWLClass?
You can obtain the direct, asserted superclasses for the named class from an OWLOntology object by calling the getSubClassAxiomsForSubClass method.
This will return axioms with both kinds of superclass - anonymous and western, err, I mean named. If you iterate over the result, you can select the anonymous class expressions using the isAnonymous method. If you need indirect superclasses, you can recursively fetch the subclass axioms for any named classes.
Depending on your requirements, you may also want to check equivalent class axioms, since every equivalent class expression in an axiom is a superclass of all the others. These can be retrieved using the getEquivalentClassesAxioms method.
If you do follow parent links, or expand equivalences, you may need to keep track of the named classes you have already processed in case there are cycles.
If you want to include inferred superclasses as well as directly asserted ones, you can create a reasoner and use that to find the named superclasses of your chosen class. You can then retrieve the anonymous superclasses by fetching the subclass axioms as described above.
Let me know if this makes sense, or if sample code would be useful.
Edit: OWLClassExpressionCollector
could also be useful, as it collects all class expressions from any OWLObject
: ontology, axiom, or expression.