GATE
Version 3.1-2270

com.ontotext.gate.ontology
Class TaxonomyImpl

java.lang.Object
  extended by gate.util.AbstractFeatureBearer
      extended by gate.creole.AbstractResource
          extended by gate.creole.AbstractLanguageResource
              extended by com.ontotext.gate.ontology.TaxonomyImpl
All Implemented Interfaces:
Taxonomy, LanguageResource, Resource, FeatureBearer, NameBearer, Serializable
Direct Known Subclasses:
OntologyImpl

public class TaxonomyImpl
extends AbstractLanguageResource
implements Taxonomy

A Taxonomy Implementation Class

Author:
borislav popov, Valentin Tablan
See Also:
Serialized Form

Field Summary
static byte DIRECT_CLOSURE
          denotes a direct closure(no transitivity)
protected  long lastGeneratedId
           
protected  boolean modified
          Whether the ontology has been modified after loading. once it became true it stays true till a save takes place
protected  boolean nullBuffers
          Whether the ontology has been modified switches to true when null-ing and reinfering the subclasses and super classes and tops
static byte TRANSITIVE_CLOSURE
          denotes atransitive closure
 
Fields inherited from class gate.creole.AbstractLanguageResource
dataStore, lrPersistentId
 
Fields inherited from class gate.util.AbstractFeatureBearer
features
 
Constructor Summary
TaxonomyImpl()
           
 
Method Summary
 void addClass(TClass theClass)
          Adds a class to the ontology.
 void addObjectModificationListener(ObjectModificationListener listener)
          Adds an object modification listener.
 boolean containsClassByName(String theName)
          Checks if the ontology contains a class with the given name.
 TClass createClass(String aName, String aComment)
          Creates a new OClass and returns it.
 boolean equals(Object o)
          Compares the id,uri and url of the ontology.
protected  void fireObjectModificationEvent(Object source)
          Fires an object modification event.
 TClass getClassByName(String theName)
          Retrieves a class by its name.
 Set getClasses()
          Retrieves all classes as a set.
 Iterator getClasses(Comparator comp)
          Retireves an iterator over the classes, ordered according to the comparator.
 String getComment()
          Gets the comment of this ontology.
 String getDefaultNameSpace()
          Gets the default name space for this ontology.
 String getId()
          Gets the id of this ontology.
 String getLabel()
          Retrieves the label of the ontology
static Taxonomy getOntology(URL someUrl)
          Gets a taxonomy by URL.
 int getTaxonomicDistance(TClass class1, TClass class2)
          calculates the taxonomic distance between two classes. note that the method is relatively big, but in case similar methods are developed for graph traversal, some parts of this method would naturally become separate methods/members.
 Set getTopClasses()
          Gets the top classes.
 URL getURL()
          Gets the url of this ontology
 String getVersion()
          Gets the version of this ontology.
 Resource init()
          Initialises this resource, and returns it.
 boolean isDirectSubClassOf(String cls1, String cls2)
          Check for subclass relation with direct closure
 boolean isModified()
          Returns true of an LR has been modified since the last sync.
 boolean isSubClassOf(String cls1, String cls2)
          Check for subclass relation with transitive closure
 void load()
          Loads this ontology.
protected  void reinfer()
          Called when the ontology has been modified to re-infer all sub/super classes, tops, etc. currently could be implemented simpler but this implementation could be useful in the future
 void removeClass(TClass theClass)
          note: if a class is deleted and there aresome subclasses of this class which lack any other super classes : then they become top classes. this could be changed on request or made optional.
 void setComment(String theComment)
          Sets the comment of this ontology.
 void setDefaultNameSpace(String theURI)
          Sets the URI of the ontology
 void setId(String theID)
          Sets the id of this ontology.
 void setLabel(String theLabel)
          Sets the label of the ontology
 void setModified(boolean isModified)
          Sets the modified flag.
 void setURL(URL aUrl)
          Set the url of this ontology
 void setVersion(String theVersion)
          Sets version to this ontology.
 void store()
          Stores this ontology.
 String toString()
           
 
Methods inherited from class gate.creole.AbstractLanguageResource
cleanup, getDataStore, getLRPersistenceId, getParent, setDataStore, setLRPersistenceId, setParent, sync
 
Methods inherited from class gate.creole.AbstractResource
checkParameterValues, getBeanInfo, getName, getParameterValue, getParameterValue, removeResourceListeners, setName, setParameterValue, setParameterValue, setParameterValues, setParameterValues, setResourceListeners
 
Methods inherited from class gate.util.AbstractFeatureBearer
getFeatures, setFeatures
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface gate.LanguageResource
getDataStore, getLRPersistenceId, getParent, setDataStore, setLRPersistenceId, setParent, sync
 
Methods inherited from interface gate.Resource
cleanup, getParameterValue, setParameterValue, setParameterValues
 
Methods inherited from interface gate.util.FeatureBearer
getFeatures, setFeatures
 
Methods inherited from interface gate.util.NameBearer
getName, setName
 

Field Detail

DIRECT_CLOSURE

public static final byte DIRECT_CLOSURE
denotes a direct closure(no transitivity)

See Also:
Constant Field Values

TRANSITIVE_CLOSURE

public static final byte TRANSITIVE_CLOSURE
denotes atransitive closure

See Also:
Constant Field Values

lastGeneratedId

protected long lastGeneratedId

nullBuffers

protected boolean nullBuffers
Whether the ontology has been modified switches to true when null-ing and reinfering the subclasses and super classes and tops


modified

protected boolean modified
Whether the ontology has been modified after loading. once it became true it stays true till a save takes place

Constructor Detail

TaxonomyImpl

public TaxonomyImpl()
Method Detail

addObjectModificationListener

public void addObjectModificationListener(ObjectModificationListener listener)
Adds an object modification listener.

Parameters:
listener - listener to be added.

fireObjectModificationEvent

protected void fireObjectModificationEvent(Object source)
Fires an object modification event.

Parameters:
event - the event to be fired

getOntology

public static Taxonomy getOntology(URL someUrl)
                            throws ResourceInstantiationException
Gets a taxonomy by URL. The taxonomy will be searched first among the existing LRs and afterwards loaded by the URL if not found

Parameters:
someUrl - the url of the taxonomy
Returns:
the retrieved or loaded taxonomy
Throws:
ResourceInstantiationException - if something gets wrong with the loading

init

public Resource init()
              throws ResourceInstantiationException
Initialises this resource, and returns it.

Specified by:
init in interface Resource
Overrides:
init in class AbstractResource
Throws:
ResourceInstantiationException

getURL

public URL getURL()
Description copied from interface: Taxonomy
Gets the url of this ontology

Specified by:
getURL in interface Taxonomy
Returns:
the url of this ontology

setURL

public void setURL(URL aUrl)
Description copied from interface: Taxonomy
Set the url of this ontology

Specified by:
setURL in interface Taxonomy
Parameters:
aUrl - the url to be set

setLabel

public void setLabel(String theLabel)
Sets the label of the ontology

Specified by:
setLabel in interface Taxonomy
Parameters:
theLabel - the label to be set

getLabel

public String getLabel()
Retrieves the label of the ontology

Specified by:
getLabel in interface Taxonomy
Returns:
the label of the ontology

load

public void load()
          throws ResourceInstantiationException
Description copied from interface: Taxonomy
Loads this ontology. According to different storages - different implementations are expected. Should take care of the modifiedAfterLoading member

Specified by:
load in interface Taxonomy
Throws:
ResourceInstantiationException

store

public void store()
           throws ResourceInstantiationException
Description copied from interface: Taxonomy
Stores this ontology. According to different storages - different implementations are expected. Should take care of the modifiedAfterLoading member

Specified by:
store in interface Taxonomy
Throws:
ResourceInstantiationException

setDefaultNameSpace

public void setDefaultNameSpace(String theURI)
Description copied from interface: Taxonomy
Sets the URI of the ontology

Specified by:
setDefaultNameSpace in interface Taxonomy
Parameters:
theURI - the URI to be set

getDefaultNameSpace

public String getDefaultNameSpace()
Description copied from interface: Taxonomy
Gets the default name space for this ontology. This value is prepended to local URIs (the ones not containing '#'.

Specified by:
getDefaultNameSpace in interface Taxonomy
Returns:
a String value.

setVersion

public void setVersion(String theVersion)
Description copied from interface: Taxonomy
Sets version to this ontology.

Specified by:
setVersion in interface Taxonomy
Parameters:
theVersion - the version to be set

getVersion

public String getVersion()
Description copied from interface: Taxonomy
Gets the version of this ontology.

Specified by:
getVersion in interface Taxonomy
Returns:
the version of this ontology

getId

public String getId()
Description copied from interface: Taxonomy
Gets the id of this ontology.

Specified by:
getId in interface Taxonomy
Returns:
the id of this ontology

setId

public void setId(String theID)
Description copied from interface: Taxonomy
Sets the id of this ontology.

Specified by:
setId in interface Taxonomy
Parameters:
theID - the id to be set

getComment

public String getComment()
Description copied from interface: Taxonomy
Gets the comment of this ontology.

Specified by:
getComment in interface Taxonomy
Returns:
the comment of this ontology

setComment

public void setComment(String theComment)
Description copied from interface: Taxonomy
Sets the comment of this ontology.

Specified by:
setComment in interface Taxonomy
Parameters:
theComment - the comment to be set

createClass

public TClass createClass(String aName,
                          String aComment)
Description copied from interface: Taxonomy
Creates a new OClass and returns it.

Specified by:
createClass in interface Taxonomy
Parameters:
aName - the name of this class
aComment - the comment of this class
Returns:
the newly created class

removeClass

public void removeClass(TClass theClass)
note: if a class is deleted and there aresome subclasses of this class which lack any other super classes : then they become top classes. this could be changed on request or made optional.

Specified by:
removeClass in interface Taxonomy
Parameters:
theClass - the class to be removed

addClass

public void addClass(TClass theClass)
Description copied from interface: Taxonomy
Adds a class to the ontology.

Specified by:
addClass in interface Taxonomy
Parameters:
theClass - the class to be added

getClassByName

public TClass getClassByName(String theName)
Description copied from interface: Taxonomy
Retrieves a class by its name.

Specified by:
getClassByName in interface Taxonomy
Parameters:
theName - the name of the class
Returns:
the class matching the name or null if no matches.

containsClassByName

public boolean containsClassByName(String theName)
Description copied from interface: Taxonomy
Checks if the ontology contains a class with the given name.

Specified by:
containsClassByName in interface Taxonomy
Parameters:
theName - name of a class
Returns:
true if the ontology contains a class with the name specified

getClasses

public Set getClasses()
Description copied from interface: Taxonomy
Retrieves all classes as a set.

Specified by:
getClasses in interface Taxonomy
Returns:
set of all the classes in this ontology

getClasses

public Iterator getClasses(Comparator comp)
Description copied from interface: Taxonomy
Retireves an iterator over the classes, ordered according to the comparator.

Specified by:
getClasses in interface Taxonomy
Parameters:
comp - a comparator defining the order of iterating the classes
Returns:
an iterator over the classes

getTopClasses

public Set getTopClasses()
Description copied from interface: Taxonomy
Gets the top classes.

Specified by:
getTopClasses in interface Taxonomy
Returns:
set of the top classes of this ontology

getTaxonomicDistance

public int getTaxonomicDistance(TClass class1,
                                TClass class2)
calculates the taxonomic distance between two classes. note that the method is relatively big, but in case similar methods are developed for graph traversal, some parts of this method would naturally become separate methods/members.

Specified by:
getTaxonomicDistance in interface Taxonomy
Parameters:
class1 - the first class
class2 - the second class
Returns:
the taxonomic distance between the 2 classes

equals

public boolean equals(Object o)
Compares the id,uri and url of the ontology.

Specified by:
equals in interface Taxonomy
Overrides:
equals in class Object
Parameters:
o - another ontology to compare with
Returns:
true if id,uri and url match

toString

public String toString()
Overrides:
toString in class Object

reinfer

protected void reinfer()
Called when the ontology has been modified to re-infer all sub/super classes, tops, etc. currently could be implemented simpler but this implementation could be useful in the future


setModified

public void setModified(boolean isModified)
Description copied from interface: Taxonomy
Sets the modified flag.

Specified by:
setModified in interface Taxonomy
Parameters:
isModified - sets this param as a value of the modified property of the ontology

isModified

public boolean isModified()
Description copied from class: AbstractLanguageResource
Returns true of an LR has been modified since the last sync. Always returns false for transient LRs.

Specified by:
isModified in interface Taxonomy
Specified by:
isModified in interface LanguageResource
Overrides:
isModified in class AbstractLanguageResource
Returns:
whether the ontology has been modified after the loading

isSubClassOf

public boolean isSubClassOf(String cls1,
                            String cls2)
Check for subclass relation with transitive closure

Specified by:
isSubClassOf in interface Taxonomy
Parameters:
cls1 - the first class
cls2 - the second class

isDirectSubClassOf

public boolean isDirectSubClassOf(String cls1,
                                  String cls2)
Check for subclass relation with direct closure

Specified by:
isDirectSubClassOf in interface Taxonomy
Parameters:
cls1 - the first class
cls2 - the second class

GATE
Version 3.1-2270