Setting Up
- Current version of OWL API is 5.1.7
- It depends on Java 8
- Available either as a jar or on maven central
- Javadoc for OWL API is here
Creating an Ontology
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLOntology ontology = manager.createOntology();
Load Ontology from File
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
File file = new File("file_path");
OWLOntology ontology = manager.loadOntologyFromOntologyDocument(file);
Save Ontology to File
manager.saveOntology(ontology, new FunctionalSyntaxDocumentFormat(), new FileOutputStream(fileout));
SubClass Axiom
IRI baseIRI = IRI.create("http://www.iiitd.ac.in/");
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
OWLDataFactory df = manager.getOWLDataFactory();
OWLClass person = df.getOWLClass(baseIRI+"Person");
OWLClass woman = df.getOWLClass(baseIRI+"Woman");
OWLSubClassOfAxiom womanSubPerson = df.getOWLSubClassOfAxiom(woman, person);
Get All Axioms
Set<OWLLogicalAxiom> axioms = ontology.getLogicalAxioms();
Get All Classes
Set<OWLClass> classes = ontology.getClassesInSignature(false);
Get Properties
Set<OWLObjectProperty> objProperties = ontology.getObjectPropertiesInSignature(false);
Set<OWLDataProperty> dataProperties = ontology.getDataPropertiesInSignature(false);