Reputation: 157
I have ontology file. owl from that i need to get all classes, subclasses from owl
File file = new File("myontology.owl");
OWLOntology myontology = manager.loadOntologyFromOntologyDocument(file);
System.out.println("Loaded ontology: " + myontology);
// We can always obtain the location where an ontology was loaded from
IRI documentIRI = manager.getOntologyDocumentIRI(myontology);
OWLDataFactory factory = manager.getOWLDataFactory();
OWLClass clsOwl = factory.getOWLClass(documentIRI);
then what should i write? i checked OWLAPI, but i am very new on semantic. In order to get ,
like following example, using owl2api i need a code ,
String uri = "http://protege.cim3.net/file/pub/ontologies/travel/travel.owl";
OWLModel owlModel = ProtegeOWL.createJenaOWLModelFromURI(uri);
Collection classes = owlModel.getUserDefinedOWLNamedClasses();
for (Iterator it = classes.iterator(); it.hasNext();) {
OWLNamedClass cls = (OWLNamedClass) it.next();
Collection instances = cls.getInstances(false);
System.out.println("Class " + cls.getBrowserText() + " (" + instances.size() + ")");
for (Iterator jt = instances.iterator(); jt.hasNext();) {
OWLIndividual individual = (OWLIndividual) jt.next();
System.out.println(" - " + individual.getBrowserText());
}
}
thank you
Upvotes: 3
Views: 2442
Reputation: 36767
Not sure if that's what you need, but
OwlOntology.getClassesInSignature()
returns the set of all classes that are used to build axioms in the current ontology.
Also once you have OwlClass you can get it's subclasses using
OwlClass.getSubClasses(OWLOntology)
Upvotes: 2