jcreek.representation
Class AbstractKnowledgeModel

java.lang.Object
  extended byjcreek.representation.AbstractKnowledgeModel
All Implemented Interfaces:
KnowledgeModel
Direct Known Subclasses:
LocalKnowledgeModel

public abstract class AbstractKnowledgeModel
extends java.lang.Object
implements KnowledgeModel

An abstract implementation of the methods of the KnowledgeModel interface that is not dependent on the mode of storage.

Version:
1.0
Author:
Frode Sørmo

Field Summary
protected  java.util.ArrayList modelChangeListeners
           
 
Constructor Summary
protected AbstractKnowledgeModel()
           
  AbstractKnowledgeModel(KnowledgeModel model)
          Creates a new KnowledgeModel by importing the contents of the supplied model.
 
Method Summary
 void addModelChangeListener(ModelChangeListener listen)
          Registrers a listener that will get notified if there are any changes to the model.
 Constraint[] getConstraints()
          Returns an array of all constraints in the model.
 Entity[] getEntities()
          Returns an array of all entities in the model.
 Partition[] getPartitions()
          Returns an array of all partitions in this KnowledgeModel.
 Relation[] getRelations()
          Returns an array of all relations in the model.
 RelationType getRelationType(java.lang.String name)
          Find a relation class in the model of the given name.
 void importModel(KnowledgeModel model)
          Removes any existing content from the KnowledgeModel and replaces it with the contents of the current model.
 EntityType[] matchEntityType(EntityType[] arr)
          Returns an array of all entities in the model that match a given EntityType.
 void mergeModel(KnowledgeModel model)
          This method merges the contents of a given model into the current model.
 void removeModelChangeListener(ModelChangeListener listen)
          Removes a ModelChangeListener listening to changes to this model.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface jcreek.representation.KnowledgeModel
addContext, entitySize, fireModelChangeEvent, getAuthor, getConstraint, getConstraintIterator, getContexts, getContexts, getDescription, getEntity, getEntityIterator, getInferenceCache, getName, getPartition, getPartitionIterator, getRelation, getRelationIterator, getTitle, hasContext, hasEntity, hasPartition, makeConstraint, makeEntity, makePartition, makeRelation, registerEntity, registerPartition, relationSize, removeContext, setAuthor, setDescription, setName, setTitle, unregisterEntity, unregisterPartition
 

Field Detail

modelChangeListeners

protected transient java.util.ArrayList modelChangeListeners
Constructor Detail

AbstractKnowledgeModel

public AbstractKnowledgeModel(KnowledgeModel model)
Creates a new KnowledgeModel by importing the contents of the supplied model.

Parameters:
model - The KnowledgeModel to import.

AbstractKnowledgeModel

protected AbstractKnowledgeModel()
Method Detail

importModel

public void importModel(KnowledgeModel model)
Removes any existing content from the KnowledgeModel and replaces it with the contents of the current model. This is useful for transferring models across different implemetnations of this interface, e.g. from a KnowledgeModel storing the data locally and a KnowledgeModel storing the information in a database. It will not transfer non-permanent data like change listeners.

Specified by:
importModel in interface KnowledgeModel
Parameters:
model - The KnowledgeModel that will have its contents copied into this model.

mergeModel

public void mergeModel(KnowledgeModel model)
This method merges the contents of a given model into the current model. Non-permanent data is not merged, i.e. listeners and such. The model that is merged into this model is not changed. The merge will only contain one copy of each entity that has the same name in both models. If there exists a relation between two entities in the current model, another relation of the same relation type between the same entities will not be imported even though they may contain the same entities. Partitions are imported if they have different names than the already existing partitions. Already existing partitions will not be changed.

Specified by:
mergeModel in interface KnowledgeModel
Parameters:
model - The knowledgemodel to merge into this model.

matchEntityType

public EntityType[] matchEntityType(EntityType[] arr)
Returns an array of all entities in the model that match a given EntityType.

Specified by:
matchEntityType in interface KnowledgeModel
Parameters:
arr - An array of the type of EntityType to find.

getRelationType

public RelationType getRelationType(java.lang.String name)
Find a relation class in the model of the given name. If no relation type is indexed under that name, null is returned.

Specified by:
getRelationType in interface KnowledgeModel
Parameters:
name - The name of the relation class to be found
Returns:
The RelationType object for this type

getRelations

public Relation[] getRelations()
Returns an array of all relations in the model. This may be prohibitive for large models since it forces all relations to be stored in memory at once.

Specified by:
getRelations in interface KnowledgeModel

getEntities

public Entity[] getEntities()
Returns an array of all entities in the model. This may be prohibitive for large models since it forces all entities to be stored in memory at once.

Specified by:
getEntities in interface KnowledgeModel

getPartitions

public Partition[] getPartitions()
Returns an array of all partitions in this KnowledgeModel.

Specified by:
getPartitions in interface KnowledgeModel

getConstraints

public Constraint[] getConstraints()
Returns an array of all constraints in the model. This may be prohibitive for large models since it forces all entities to be stored in memory at once.

Specified by:
getConstraints in interface KnowledgeModel

addModelChangeListener

public void addModelChangeListener(ModelChangeListener listen)
Registrers a listener that will get notified if there are any changes to the model.

Specified by:
addModelChangeListener in interface KnowledgeModel
Parameters:
listen - The ModelChangeListener to add.

removeModelChangeListener

public void removeModelChangeListener(ModelChangeListener listen)
Removes a ModelChangeListener listening to changes to this model.

Specified by:
removeModelChangeListener in interface KnowledgeModel
Parameters:
listen - The ModelChangeListener to remove.


Created at IDI, NTNU by the Artificial Intelligence and Learning group