jcreek.representation
Interface KnowledgeModel

All Known Implementing Classes:
AbstractKnowledgeModel

public interface KnowledgeModel

The KnowledgeModel is the main interface to the model of entities and relations. As the entities can be compared to a node and a relation to an edge, the KnowledgeModel can be thought of as the graph containing these nodes and edges. The KnowledgeModel interface provides a uniform way of accessing the data that is independent on how this data is stored. Any code that access and manipulate model contents should refer to this interface instead of any specific implementations of the interface.

Version:
1.0
Author:
Frode Sørmo

Method Summary
 void addContext(Context c)
          Registers a context with the KnowledgeModel.
 void addModelChangeListener(ModelChangeListener listen)
          Registrers a listener that will get notified if there are any changes to the model.
 int entitySize()
          Returns the number of entities in the model.
 void fireModelChangeEvent(ModelChangeEvent event)
          Notifies the listeners that a change has occured in the model.
 java.lang.String getAuthor()
          Returns the author of the model.
 Constraint getConstraint(java.lang.Object id)
          Find a constraint in the model with the given ID.
 java.util.Iterator getConstraintIterator()
          Returns an iterator of all the constraints in the model.
 Constraint[] getConstraints()
          Returns an array of all constraints in the model.
 Context[] getContexts()
          Returns an array of all registered contexts.
 Context[] getContexts(java.lang.Class c)
          Returns all context object registrered with the KnowledgeModel that is of the Class given as a parameter to the method.
 java.lang.String getDescription()
          Returns the description of the model.
 Entity[] getEntities()
          Returns an array of all entities in the model.
 Entity getEntity(java.lang.Object id)
          Find an entity in the model with the given name or ID.
 java.util.Iterator getEntityIterator()
          Returns an iterator of all the entities in the model.
 LRUCache getInferenceCache()
          Returns this models inference cache.
 java.lang.String getName()
          Returns the name of the model.
 Partition getPartition(java.lang.Object id)
          Returns the partition with the given name or ID.
 java.util.Iterator getPartitionIterator()
          Returns an iterator for all the partitions in this KnowledgeModel.
 Partition[] getPartitions()
          Returns an array of all partitions in this KnowledgeModel.
 Relation getRelation(java.lang.Object id)
          Find a relation in the model with the given ID.
 java.util.Iterator getRelationIterator()
          Returns an iterator of all the realtions in the model.
 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.
 java.lang.String getTitle()
          Returns the title of the model.
 boolean hasContext(Context c)
          Returns true if the give context is registred with the KnowledgeModel.
 boolean hasEntity(java.lang.Object id)
          Returns true if an entity with the given name exists in the KnowledgeModel or an entity is registered with this key.
 boolean hasPartition(java.lang.Object id)
          Returns true if the KnowledgeModel contains a Partition with the given ID or name.
 void importModel(KnowledgeModel model)
          Removes any existing content from the KnowledgeModel and replaces it with the contents of the current model.
 ConstraintData makeConstraint()
           
 EntityData makeEntity()
          Creates a new data object for storing data for an Entity.
 PartitionData makePartition()
          Creates a new data object for storing data for a Partition.
 RelationData makeRelation(Entity from, Entity type, Entity value)
          Creates a new data object for storing data for a Relation.
 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 registerEntity(java.lang.String name, Entity ent)
          Indexes a given entity with the given name.
 void registerPartition(java.lang.String name, Partition partition)
          Registers a partition under the given name in this models partition index.
 int relationSize()
          Returns the number of relations in the model.
 void removeContext(Context c)
          Removes the given context from this KnowledgeModel.
 void removeModelChangeListener(ModelChangeListener listen)
          Removes a ModelChangeListener listening to changes to this model.
 void setAuthor(java.lang.String authorName)
          Sets the author of the model.
 void setDescription(java.lang.String description)
          Sets description of model.
 void setName(java.lang.String name)
          Sets name of model.
 void setTitle(java.lang.String title)
          Sets title of model.
 void unregisterEntity(java.lang.String name)
          Removes the index with the given name from the entity index.
 void unregisterPartition(java.lang.String name)
          Unregisters an index entry from the parition index.
 

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.

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.

Parameters:
model - The knowledgemodel to merge into this model.

setName

public void setName(java.lang.String name)
Sets name of model.

Parameters:
name - The name of the model.

getName

public java.lang.String getName()
Returns the name of the model.


setDescription

public void setDescription(java.lang.String description)
Sets description of model.

Parameters:
description - The description of the model.

getDescription

public java.lang.String getDescription()
Returns the description of the model.


setTitle

public void setTitle(java.lang.String title)
Sets title of model.

Parameters:
title - The title of the model.

getTitle

public java.lang.String getTitle()
Returns the title of the model. If none is set and there is a file associated with the model, the filename is returned.


getAuthor

public java.lang.String getAuthor()
Returns the author of the model.


setAuthor

public void setAuthor(java.lang.String authorName)
Sets the author of the model.

Parameters:
authorName - The name of the author.

getEntity

public Entity getEntity(java.lang.Object id)
Find an entity in the model with the given name or ID.

Parameters:
id - The name or ID of the entity to be found.
Returns:
The entity-object, or null if no entity with that name or ID is found.

getRelation

public Relation getRelation(java.lang.Object id)
Find a relation in the model with the given ID.

Parameters:
id - The unique identifier for this relation.

registerEntity

public void registerEntity(java.lang.String name,
                           Entity ent)
                    throws NameAlreadyExistException
Indexes a given entity with the given name. This is automatically done with the name when generating an entity, but additional indexes may be made. An name may only be used once, or a NameAleadyExistException will be returned.

Parameters:
name - The name to assoicate with this entity.
ent - The Entity object.
Throws:
NameAlreadyExistException

unregisterEntity

public void unregisterEntity(java.lang.String name)
Removes the index with the given name from the entity index.

Parameters:
name - The name (key) of the index entry to remove.

hasEntity

public boolean hasEntity(java.lang.Object id)
Returns true if an entity with the given name exists in the KnowledgeModel or an entity is registered with this key.

Parameters:
id - The index key of the entity.

entitySize

public int entitySize()
Returns the number of entities in the model.


relationSize

public int relationSize()
Returns the number of relations in the model.


getEntityIterator

public java.util.Iterator getEntityIterator()
Returns an iterator of all the entities in the model.


getRelationIterator

public java.util.Iterator getRelationIterator()
Returns an iterator of all the realtions in the model.


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.


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.


getInferenceCache

public LRUCache getInferenceCache()
Returns this models inference cache. This cache is flushed each time the model is changed, but can be used to cache inferences done with the basis of the current model.


matchEntityType

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

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.

Parameters:
name - The name of the relation class to be found
Returns:
The relation-class.

addModelChangeListener

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

Parameters:
listen - The ModelChangeListener to add.

removeModelChangeListener

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

Parameters:
listen - The ModelChangeListener to remove.

makeEntity

public EntityData makeEntity()
Creates a new data object for storing data for an Entity. This is a part of the creation of a new Entity, and should only be used from an Entity constructor. The new entity will not be index under a name.


makeRelation

public RelationData makeRelation(Entity from,
                                 Entity type,
                                 Entity value)
Creates a new data object for storing data for a Relation. This is a part of the creation of a new Relation, and should only be used from a Relation constructor. The Relation is required to have from, value and type entities.

Parameters:
from - The Entity this relation is from (the origin).
value - The Entity this relation is to (the target).
type - The Entity that represents the type of the relation.

makePartition

public PartitionData makePartition()
                            throws NameAlreadyExistException
Creates a new data object for storing data for a Partition. This is part of the creation of a new Partition and should only be used from the Partition constructor. The Partition is required to have a unique name or a NameAlreadyExistException is thrown.

Throws:
NameAlreadyExistException

getPartitions

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


getPartitionIterator

public java.util.Iterator getPartitionIterator()
Returns an iterator for all the partitions in this KnowledgeModel.


getPartition

public Partition getPartition(java.lang.Object id)
Returns the partition with the given name or ID. If no parition with this name is found, null is returned.

Parameters:
id - The name or ID of the partition to return.

registerPartition

public void registerPartition(java.lang.String name,
                              Partition partition)
                       throws NameAlreadyExistException
Registers a partition under the given name in this models partition index. The partition can then be accessed through the getPartition(Object id) method using this string. If there is already a partition registered with this name, a NameAlreadyExistException will be thrown.

Parameters:
name - The name (key) to register the partition under.
partition - The Partition to register under this name.
Throws:
NameAlreadyExistException

unregisterPartition

public void unregisterPartition(java.lang.String name)
Unregisters an index entry from the parition index.

Parameters:
name - The name of the index entry to remove.

hasPartition

public boolean hasPartition(java.lang.Object id)
Returns true if the KnowledgeModel contains a Partition with the given ID or name.

Parameters:
id - The name (string) or id of a partition to test for.

fireModelChangeEvent

public void fireModelChangeEvent(ModelChangeEvent event)
Notifies the listeners that a change has occured in the model.

Parameters:
event - The event object reporting this change.

addContext

public void addContext(Context c)
Registers a context with the KnowledgeModel. Only here for compatibility reasons. Should be removed.


getContexts

public Context[] getContexts()
Returns an array of all registered contexts. Only here for compatibility reasons. Should be removed.


getContexts

public Context[] getContexts(java.lang.Class c)
Returns all context object registrered with the KnowledgeModel that is of the Class given as a parameter to the method. Objects that are subclasses of the given class is also returned.


removeContext

public void removeContext(Context c)
Removes the given context from this KnowledgeModel. Only here for compatibility reasons. Should be removed.


hasContext

public boolean hasContext(Context c)
Returns true if the give context is registred with the KnowledgeModel. Only here for compatibility reasons. Should be removed.


makeConstraint

public ConstraintData makeConstraint()

getConstraint

public Constraint getConstraint(java.lang.Object id)
Find a constraint in the model with the given ID.

Parameters:
id - The unique identifier for this constraint.

getConstraintIterator

public java.util.Iterator getConstraintIterator()
Returns an iterator of all the constraints in the model.


getConstraints

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



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