From NeOn Wiki

Earlier versions of NTK (up until v1.2.3) were using the KAON2 API for ontology handling.

With the introduction of OWL2 we are migrating the NTK to the upcoming OWL API 3.0.0 (Note: as of today the sourceforge page of the OWL API is only talking about v2 of the OWL API which is greatly incompatible with OWL 2). This wiki page is intended to give plugin developers guidelines on how to port their plugins to the OWL API.

A detailed table comparing the classes and methods from KAON2 with those of the OWL API can be found on its own wiki page. Other relevant changes after NTK 1.2 are documented on the GUI-level API changes for NTK 2.3 and Datamodel-level API changes for NTK 2.3 wiki pages.

Contents

Essential Class Equivalences

org.semanticweb.kaon2.api.OntologyManager => org.semanticweb.owlapi.model.OWLOntologyManager
org.semanticweb.kaon2.api.Ontology        => org.semanticweb.owlapi.model.OWLOntology

Projects and OWLOntologyManager

The top level elements in the ontology navigator of NTK are projects. A project is represented by an IOntologyProject instance.

Each project has exactly one associated OWLOntologyManager instance which contains all the ontologies contained in the project.

Please note that a project is (strictly) more than an OWLOntologyManager instance. If you create a new OWLOntologyManager instance, e.g. by using

OWLManager.createOWLOntologyManager()

the new OWLOntologyManager instance is not associated with a project and ontologies in that ontology manager will thereby never appear in the ontology navigator of NTK!

Create a new Project

To create a new project you have to execute a CreateProject command:

new CreateProject(projectName, OWLManchesterProjectFactory.FACTORY_ID, new Properties()).run();

Once the command has been executed, the newly created project will automatically appear in the ontology navigator.

Fetching an existing Project

To get the IOntologyProject instance for an existing project use

NeOnCorePlugin.getDefault().getOntologyProject(projectName);

To get all existing project names you can use

OWLPlugin.getDefault().getOntologyProjects();

Get an OWLOntologyManager Instance

You can ask for the OWLOntologyManager instance of a project by using

IOntologyProject.getAdapter(OWLOntologyManager.class);


A plugin may use any non modifying (=read only) methods of OWLOntologyManager. The following modifying methods are allowed, too:

addAxiom(...)
addAxioms(...)
removeAxiom(...)
removeAxioms(...)

applyChange(...)
applyChanges(...)

addOntologyChangeListener(...)
addOntologyChangeProgessListener(...)
removeOntologyChangeListener(...)
removeOntologyChangeProgessListener(...)

Important: any other modifying method of OWLOntologyManager has the potential to break the NTK Framework when directly used by plugins! Do not use them!

Create a new Ontology

To create a new ontology use

IOntologyProject.createOntology(...)

The newly created ontology will automatically appear within the ontology navigator.

Please note that creating a new ontology by using

OWLOntologyManager.createOntology(...)

will not be noticed by the NTK UI! This is because the OWL API does not send an event after creating an ontology and thereby the NTK framework does not know that a new ontology is there. As one side effects the ontology will not automatically appear in the ontology navigator. In addition the paths for storing the ontology will not be set up correctly.

Always create a new ontology for a project by using IOntologyProject.createOntology(...).

Listeners

To receive project related events like "ontology created", register an IOntologyProjectListener with

NeOnCorePlugin.addOntologyProjectListener(...)

For ontology related events register an OWLOntologyChangeListener by using

OWLOntologyManager.addOntologyChangeListener(...)

Useful Methods

In this section, we provide some useful methods in the OWLAPI version of NeOnToolkit:

Method Description Remark
OWLPlugin.getDefault().getOntologyProjects() Return the name of all projects in the current workspace
OWLModelFactory.getOWLModel(ontologyID, projectName) Return an OWLModel with the given ontology ID and project name.
OWLModel.getOntology() Return an OWLOntology
OWLModelFactory.getOWLModels(projectName) Return all OWLModel instances for the given project
NeOnCorePlugin.getDefault().getOntologyProject(projectName) Return the ontology project for a given project name
IOntologyProject.createOntology(...) Create a new ontology
IOntologyProject.getAdapter(OWLOntologyManager.class) Return the ontology manager associated with a project Use IOntologyProject instead of OWLOntologyManager for ontology management whenever possible! Otherwise you will break NTK (missing refreshs etc.)

Requests - Retrieving Axioms and Entities

With KAON2 one can create Requests for Axiom types and set conditions on it. E.g. create a ClassMember request and set a condition on the description, thereby (indirectly) asking for all (asserted) individuals of a given description.

Set<ClassMember> classMembers = ontology.createAxiomRequest(ClassMember.class).setCondition("description", myClass).get()

KAON2 also has some shortcut methods available on OWLEntity sub-interfaces, e.g.

ObjectProperty.getObjectPropertyMembers(Ontology ontology)

which asks for all ObjectPropertyMember axioms in which the object property is the one on which the method is called.

The OWL API does not have a generic request interface. Instead OWLOntology provides a lot of "get" methods with conditions as arguments. E.g.

Set<OWLClassAssertion> classAssertions = ontology.getClassAssertionAxioms(myClass);

Sadly some "get" methods are missing, e.g. one cannot ask for all OWLObjectPropertyAssertionAxioms for a given OWLObjectProperty as one can with KAON2 by using a request or ObjectProperty.getObjectPropertyMembers(Ontology ontology). If such functionality is needed one needs to ask for all axioms of the given type

OWLOntology.getAxioms(AxiomType)

and has to filter them manually afterwards.

Experience with Migration

Reasoning

We have developed a plug-in "org.neontoolkit.owlreasoning" to do reasoning tasks using HermiT 1.0. Specifically, the following functionalities are included:

  • Check unsatisfiability of a concept: This functionality is to check whether a concept is unsatisfiable or not, where a concept is unsatisfiable means the interpretation of this concept is empty. This functionality corresponds to the method of "isSatisfiable(OWLClass)" in the class of "org.neontoolkit.owlreasoning.OWLReasoning".
  • Compute all unsatisfiable concepts: This functionality is to obtain all the unsatisfiable concepts in an ontology. This functionality corresponds to the method of "getUnsatisfiableClasses()" in the class of "org.neontoolkit.owlreasoning.OWLReasoning".
  • Check consistency of an ontology: This functionality is to check whether an ontology is inconsistent or not, where an ontology is inconsistent means this ontology has no interpretation. This functionality corresponds to the method of "isConsistent()" in the class of "org.neontoolkit.owlreasoning.OWLReasoning".
  • Check coherence of an ontology: This functionality is to check whether an ontology is incoherent or not, where an ontology is incoherent means this ontology contains at least on unsatisfiable concept. This functionality corresponds to the method of "isCoherent()" in the class of "org.neontoolkit.owlreasoning.OWLReasoning".

Note: We also developed another plug-in "org.neontoolkit.reasoningtest" depending on "org.neon-toolkit.owlreasoning" to provide a user interface for the functionalities above. These two plug-ins are available in googlecode (http://neon-plugins.googlecode.com/svn/trunk/).