Introduction to OWL API


Monsoon 2018
Instructor: Raghava Mutharaju
IIIT-Delhi
IIIT Delhi

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


  • Use OWLOntologyManager
 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); 
					

References


  1. An Introduction to OWL API. Nicolas Matentzoglu, and Ignazio Palmisano. 2017
  2. The OWL API: A Java API for OWL Ontologies. Matthew Horridge, and Sean Bechhofer. Semantic Web Journal. 2011