Java2OWL
Class J2OOntologyManager

Object
  extended by J2OOntologyManager

public class J2OOntologyManager
extends Object

This class manages the ontologies for the Java2OWL-System.

At compile time, there are usually two ontologies, a background ontology (which may be empty) and an extension ontology. The extension ontology may be filled with translated Java classes and methods. At run time there is the extension ontology or an extension of the original extension ontology.

Although there may be different J2OOntologyManagers with different ontologies in parallel, there is only one global OWL-ontology manager and OWL data factory.

The ontology manager can be in debug mode or run mode (debugMode = false). In debug mode all changes to the ontology are immediately forwarded to the reasoner and consistency is checked immediately. In run mode changes to the ontology are cached until the ontology is accessed in some way.

Notice that most of private variables are not set by the constructor, but when an ontology is loaded.

Thread Safety
All methods which are needed only during compilation and linking phase are not thread safe.

The methods needed during the application phase are synchronised with changeAxioms as monitor. The changeAxioms are the interface to the ontology.


Method Summary
 void addIRIMapper(AutoIRIMapper iriMapper)
          adds an IRIMapper to the ontology manager.
 boolean applyChanges(boolean checkConsistency)
          applies the change axioms to the extension ontology.
 void finalize()
          disposes of the reasoner
 OWLOntology getBackgroundOntology()
          returns the background ontology.
 Set<Object> getDataPropertyValues(OWLNamedIndividual individual, OWLDataProperty property)
          returns all role-fillers for data-properties as Java objects, or null if an error occurred.
 OWLOntology getExtensionOntology()
          returns the extension ontology.
 OWLDataProperty getFirstOWLDataProperty(String name)
          returns the first OWLDataProperty in the extensionOntology's import closure whose fragment equals 'name', or null if there is no such property.
 OWLObjectProperty getFirstOWLObjectProperty(String name)
          returns the first OWLObjectProperty in the extensionOntology's import closure whose fragment equals 'name', or null if there is no such property.
 Set<OWLNamedIndividual> getInstances(OWLClassExpression cle)
          returns all OWL-instances for the class expression.
 Set<OWLNamedIndividual> getInstances(String cles)
          returns the OWL-instances for the class expression, or null if an error occurred.
 String getName()
          returns the name of the ontology manager.
 Set<OWLNamedIndividual> getObjectPropertyValues(OWLNamedIndividual individual, OWLObjectProperty property)
          returns all role-fillers for object-properties as OWLNamedindividuals.
 Set<OWLClass> getOWLClasses(OWLNamedIndividual individual)
          returns the set of lowest OWL-Classes containing the individual, or null if an error occurred.
 ArrayList<OWLClass> getOWLClasses(String name)
          returns a set of OWLClasses with the given name.
 OWLOntologyManager getOWLOntologyManager()
          returns the OWL ontology manager (for advances purposes).
static Set<String> getReasoners()
          returns the names of all available reasoners.
 boolean isConsistent()
          returns true if the extension ontology is consistent.
 OWLOntology loadBackgroundOntology(String name)
          loads the background ontology.
 OWLOntology loadExtensionOntology(String name)
          loads the extension ontology.
 OWLOntology loadOntology(IRI iri, boolean background)
          loads an ontology from an IRI.
 OWLClassExpression parseClassExpression(String classExpressionString)
          parses a class expression string to obtain a class expression.
 void removeAllIndividuals(OWLClass ocl)
          creates the change axioms for removing all individuals in the given class.
 void removeIndividual(OWLNamedIndividual individual)
          creates the change axioms for removing the individual from all ontologies.
 boolean saveExtensionOntology()
          saves the extension ontology to the same file where it was loaded from OWLOntologyStorageExceptions are logged.
 boolean saveExtensionOntology(IRI iri)
          saves the extension ontology either to the previously specified IRI, or to the given file.
 boolean saveExtensionOntology(String filename)
          saves the extension ontology either to the previously specified IRI, or to the given file.
 OWLReasoner setReasoner(String reasonerName, boolean buffering, boolean monitorProgress, int timeout)
          installs a reasoner for the extension ontology.
 String toString()
          returns a string representation of the ontology manager.
 
Methods inherited from class Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

getName

public String getName()
returns the name of the ontology manager.


getOWLOntologyManager

public OWLOntologyManager getOWLOntologyManager()
returns the OWL ontology manager (for advances purposes).


getBackgroundOntology

public OWLOntology getBackgroundOntology()
returns the background ontology.


getExtensionOntology

public OWLOntology getExtensionOntology()
returns the extension ontology.


addIRIMapper

public void addIRIMapper(AutoIRIMapper iriMapper)
adds an IRIMapper to the ontology manager. The IRIMapper helps finding imported ontologies.


loadOntology

public OWLOntology loadOntology(IRI iri,
                                boolean background)
loads an ontology from an IRI.

A previously installed ontology is removed (and not saved).

Parameters:
iri - the document IRI of the ontology.
background - if true, then the background ontology is loaded, otherwise the extension ontology.
Returns:
the loaded ontology or null if something goes wrong.

loadBackgroundOntology

public OWLOntology loadBackgroundOntology(String name)
loads the background ontology.

Parameters:
name - the place to load the ontology from: - either an IRI as string, stating with http: or file: - or a pathname of a file where the ontology is stored.
Returns:
the loaded ontology or null if it could not be loaded.

loadExtensionOntology

public OWLOntology loadExtensionOntology(String name)
loads the extension ontology.

Parameters:
name - the place to load the ontology from: - either an IRI as string, stating with http: or file: - or a pathname of a file where the ontology is stored.
Returns:
the loaded ontology or null if it could not be loaded.

saveExtensionOntology

public boolean saveExtensionOntology(IRI iri)
saves the extension ontology either to the previously specified IRI, or to the given file.

Parameters:
iri - the IRI where the extension ontology is to be saved.
Returns:
true if the operation succeeded.

saveExtensionOntology

public boolean saveExtensionOntology(String filename)
saves the extension ontology either to the previously specified IRI, or to the given file.

Parameters:
filename - optionally a filename where the ontology is to be stored.
Returns:
true if the operation succeeded.

saveExtensionOntology

public boolean saveExtensionOntology()
saves the extension ontology to the same file where it was loaded from

OWLOntologyStorageExceptions are logged.

Returns:
true if the operation succeeded.

removeIndividual

public void removeIndividual(OWLNamedIndividual individual)
creates the change axioms for removing the individual from all ontologies.


removeAllIndividuals

public void removeAllIndividuals(OWLClass ocl)
creates the change axioms for removing all individuals in the given class.


getFirstOWLDataProperty

public OWLDataProperty getFirstOWLDataProperty(String name)
returns the first OWLDataProperty in the extensionOntology's import closure whose fragment equals 'name', or null if there is no such property.

To this end it searches through the imports closure of the extension ontology and the first one it finds with the given name is returned.


getFirstOWLObjectProperty

public OWLObjectProperty getFirstOWLObjectProperty(String name)
returns the first OWLObjectProperty in the extensionOntology's import closure whose fragment equals 'name', or null if there is no such property.

To this end it searches through the imports closure of the extension ontology and the first one it finds with the given name is returned.


getOWLClasses

public ArrayList<OWLClass> getOWLClasses(String name)
returns a set of OWLClasses with the given name.
There may be more than one class with the given name in the imports closure.

Parameters:
name - an OWLClass name.
Returns:
the set of OWLClasses with the given name.

getReasoners

public static Set<String> getReasoners()
returns the names of all available reasoners.


setReasoner

public OWLReasoner setReasoner(String reasonerName,
                               boolean buffering,
                               boolean monitorProgress,
                               int timeout)
installs a reasoner for the extension ontology.

Parameters:
reasonerName - the name of the reasoner.
buffering - if true, a buffering reasoner is to be installed.
monitorProgress - if true,a progress monitor is to be installed.
timeout - the timeout (in ms) for complex reasoning tasks.
Returns:
the installed reasoner, or null if there is not yet an extension ontology.

If there is already an extension ontology then the reasoner is loaded. Otherwise the parameters are stored and the reasoner is loaded after the extension ontology is loaded.


getOWLClasses

public Set<OWLClass> getOWLClasses(OWLNamedIndividual individual)
returns the set of lowest OWL-Classes containing the individual, or null if an error occurred.

Parameters:
individual - is the OWL-individual

getInstances

public Set<OWLNamedIndividual> getInstances(OWLClassExpression cle)
returns all OWL-instances for the class expression.


getInstances

public Set<OWLNamedIndividual> getInstances(String cles)
                                     throws ParserException
returns the OWL-instances for the class expression, or null if an error occurred.

Parameters:
cles - an OWL class-expression in Manchester Syntax
Returns:
the set of OWL-individuals which are instances of the class.
Throws:
ParserException - if the expression could not be parsed.

parseClassExpression

public OWLClassExpression parseClassExpression(String classExpressionString)
                                        throws ParserException
parses a class expression string to obtain a class expression.

Parameters:
classExpressionString - The class expression string
Returns:
The corresponding class expression
Throws:
ParserException - if the class expression string is malformed or contains unknown entity names.

isConsistent

public boolean isConsistent()
returns true if the extension ontology is consistent.

The reasoner may throw a ReasonerInterruptedException or a TimeOutException. In this case an error message is logged and the method returns false.


applyChanges

public boolean applyChanges(boolean checkConsistency)
applies the change axioms to the extension ontology.

If the system is in debug mode all changes are flushed to the reasoner and the consistency is checked.

Parameters:
checkConsistency - causes consistency check in the debug mode.
Returns:
true if the operation succeeded and the classes are consistent (if it is checked).

This method is called either in the compilation phase where no thread safety is implemented, or from methods which are protected by changeAxioms as monitor.


getDataPropertyValues

public Set<Object> getDataPropertyValues(OWLNamedIndividual individual,
                                         OWLDataProperty property)
returns all role-fillers for data-properties as Java objects, or null if an error occurred.

OWL-newLiterals which could not be parsed into Java-objects are ignored, only an error message is recorded in the logger.

Parameters:
individual - the individual whose OWL-role fillers are to he retrieved.
property - the data-property.
Returns:
the set of role-fillers as Java objects, or null if an error occurred.

getObjectPropertyValues

public Set<OWLNamedIndividual> getObjectPropertyValues(OWLNamedIndividual individual,
                                                       OWLObjectProperty property)
returns all role-fillers for object-properties as OWLNamedindividuals.

Parameters:
individual - the individual whose OWL-role fillers are to he retrieved.
property - the object-property.
Returns:
the set of role-fillers as OWLNamedindividuals.

toString

public String toString()
returns a string representation of the ontology manager.

Overrides:
toString in class Object

finalize

public void finalize()
disposes of the reasoner

Overrides:
finalize in class Object