Skip to content

Creating OWLOntology and PrefixManager Instances using the OWLAPI

Martin O'Connor edited this page Oct 21, 2015 · 3 revisions

The OWLAPI provides a Java API for interacting with an OWL ontology. The primary class it provides for interacting with an OWL ontology is called OWLOntology. It also provides a DefaultPrefixManager class for managing the prefixed in an ontology. The API provides a variety of mechanisms for creating instances of these two classes.

The following is an example of creating instances of these classes from a file-based OWL ontology.

  File oFile = new File("/ont/Ont1.owl");
  OWLOntologyManager ontologyManager = OWLManager.createOWLOntologyManager();
  OWLOntology ontology = ontologyManager.loadOntologyFromOntologyDocument(oFile);
  DefaultPrefixManager prefixManager = new DefaultPrefixManager();
  OWLDocumentFormat format 
    = ontology.getOWLOntologyManager().getOntologyFormat(ontology);
  
  if (format.isPrefixOWLOntologyFormat())
    prefixManager.copyPrefixesFrom(format.asPrefixOWLOntologyFormat().getPrefixName2PrefixMap());
  

More information on how the OWLAPI can be used to create instances of the classes can be found here.