Javadoc for the API is included with the release
In order to use the API in your own applications, you should download the latest binary release and ensure that all of the jar files are in the application class path.
The central point of access is the OWLOntologyManager, which is used to load and create and access ontologies. The examples below show how to create an instance of this class and how to use it.
Code examples
- Example 1 - Shows how to load and save an ontology
- Example 2 - Shows how to create an empty ontology, add axioms and save
- Example 3 - Shows how to create an ontology and add some rules
- Example 4 - Shows how to add an object property assertion (triple) to an ontology
- Example 5 - Shows how to delete entities (classes, properties and individuals) from an ontology
- Example 6 - Shows how to create restrictions and “add them to classes” as superclasses
- Example 7 - Shows how to work with user defined data ranges (e.g. int > 10)
- Example 8 - Shows how to interact with a reasoner
- Example 9 - Shows how to collect the properties that are used in restrictions on a given class
- Example 10 - Shows how to work with annotations such as labels and comments
- Example 11 - Shows how to save inferred axioms into a new ontology, or back into an existing ontology
- Example 12 - Shows how two (or more) ontologies can be merged in a simple way
- Example 13 - Shows how to 'walk' over the asserted structure of an ontology. In this example, we find out where existential restrictions are used.
Utility Classes
Documentation on utility classes that can be used to solve common tasks can be found here.Programming with the OWL API Tutorial
A set of tutorial slides are available below. Some simple examples that relate to the tutorial slides are provided. These illustrate parsing ontologies from concrete formats; rendering to concrete formats; manipulating ontologies and using inference services. If you check out the OWL API source code from the sourceforge website, the tutorial examples can be found in the tutorial directory.Slides
Slides are available in PDF format:
Code examples
Simple Hierarchy
This example shows how we can calculate and display a basic ontology hierarchy. The example makes use of an OWLClassReasoner to calculate the class hierarchy, then navigates the structure obtained, printing out basic information for each of the classes.
The example either uses a ToldClassHierarchyReasoner, which returns information about the hierarchy based solely on the assertions that are made in the ontology, or a DIGReasoner, which will make use of an external Description Logic reasoner in order to calculate the inferred class hierarchy.
Rendering example
This example shows the definition of a simple renderer. The renderer provided an HTML page describing the entities in the ontology.
Closure Axioms
This example illstrates manipulation of axioms in an ontology.
Debugging
This example illustrates the use of the debugger. The debugger identifies axioms causing inconsistencies in OWL ontologies.