Reputation: 4382
How can I get all the classes from a loaded ontology with owlapi? Here I have an example on how to get one class, but I'm interested on accessing all the classes defined at the ontology.
OWLOntologyManager manager = WLManager.createOWLOntologyManager();
OWLOntology ontology = manager.loadOntology(IRI.create(fileURI));
OWLDataFactory owlDF = manager.getOWLDataFactory();
//Example to get ONE class, but I want ALL!
OWLClass stringDocuClass = owlDF.getOWLClass(IRI.create("http://example.com/my_ontology.owl#StringDocu"));
I'm working with java owlapi 4.2.3 (see the API: http://owlapi.sourceforge.net/javadoc/)
Upvotes: 3
Views: 1987
Reputation: 2366
For owlapi-v5.0
use:
ArrayList<OWLClass> classes = new ArrayList<OWLClass>();
ontology.classesInSignature().forEach(classes::add);
For owlapi-v4.2.3
use:
Set<OWLClass> classes = ontology.getClassesInSignature();
Upvotes: 6
Reputation: 95
As of OWLAPI 5.0, one can use stream iterators:
ArrayList<OWLClass> classes = new ArrayList<OWLClass>();
ontology.classesInSignature().forEach(classes::add);
Upvotes: 3