jcreek.representation
Class Partition

java.lang.Object
  extended byjcreek.representation.SubModel
      extended byjcreek.representation.Partition

public class Partition
extends SubModel

A Partition is a submodel of a KnowledgeModel. Unlike the SubModel class, the Partition is a persistent part of the model, and can be looked up, retrieved and accessed through a KnowledgeModel instance. In addition, it to limit the scope of model inference and browsing to a partition so that e.g. an Entity object will only return relations from this entity that are in the "current partition", and inheritance will only work on relations and entities present in this partition. To do this, see the setCurrentPartition() method in the Entity and Relation classes. It is also possible to register ModelChangeListener instances to a partition. This will allow the listener to only get events when a change occurs in the partition, i.e. an entity or relation is the partition is changed or a change is done to the partition itself. Each Partition also have an inference cache associated with it. When possible, it is wise to use this cache instead of the one from the KnowledgeModel class as a Partition's inference cache is only flushed when a change occurs in the Partition while the KnowledgeModel inference cache is flushed whenever any change occurs.

Version:
1.0
Author:
Frode Sørmo

Constructor Summary
Partition(KnowledgeModel model, java.lang.String name)
          Creates a new Partition with the given name in the given KnowledgeModel.
 
Method Summary
 void add(Entity entity)
          Adds an entity to the partition.
 void add(Entity[] ents)
          Adds a set of entitites to the partition.
 void add(Relation r)
          Adds a relation to the partition.
 void add(Relation[] rels)
          Adds an array of relations to the partition.
 boolean contains(Entity ent)
          Returns true if the submodel contains the entity.
 boolean contains(Relation rel)
          Returns true if the submodel contains the relation.
 boolean equals(java.lang.Object ob)
          Two entities are considered equal if they represent the same PartitionData object.
 long getCreationTime()
          Returns the time of creation of this partition, in the the format as System.currentTimeMillis();
 Entity[] getEntities()
          Returns an array of all the entities in the submodel.
 java.lang.Object getID()
          Returns the unique ID of this partition.
 KnowledgeModel getKnowledgeModel()
          Returns the knowledgemodel this partition belongs to.
 java.lang.String getName()
          Returns the name of this Partition.
protected  PartitionData getPartitionData()
          Returns the PartitionData object in case a subclass needs to manipulate it directly.
 Relation[] getRelations()
          Returns an array of all the relations in the submodel.
 int hashCode()
          Overrides the hashCode() method to match the class' new equals() method.
 void remove()
          Removes the partition from the KnowledgeModel.
 boolean remove(Entity ent)
          Removes an entity from the submodel.
 boolean remove(Relation r)
          Removes a relation from the partition.
 void setName(java.lang.String name)
          Sets the name of the Partition.
 java.lang.String toString()
           
 
Methods inherited from class jcreek.representation.SubModel
add, addExpanded, addExpanded, clear, contains, joinWith, remove, size, toSet, union
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Partition

public Partition(KnowledgeModel model,
                 java.lang.String name)
          throws NameAlreadyExistException
Creates a new Partition with the given name in the given KnowledgeModel. If there already exists a partition in the model with this, a NameAlreadyExistException is thrown.

Parameters:
model - The KnowledgeModel to make a new Partition in.
name - The name of the new Parition.
Method Detail

setName

public void setName(java.lang.String name)
             throws NameAlreadyExistException
Sets the name of the Partition. If there is already a Partition with the new name already exists in the KnowledgeModel, a NameAlreadyExistException is thrown.

Parameters:
name - The new name of the Partition.
Throws:
NameAlreadyExistException

getName

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


add

public void add(Entity entity)
Adds an entity to the partition.

Overrides:
add in class SubModel
Parameters:
entity - The entity to add.

add

public void add(Entity[] ents)
Adds a set of entitites to the partition.

Overrides:
add in class SubModel
Parameters:
ents - The arrays of entities to add.

add

public void add(Relation r)
Adds a relation to the partition.

Overrides:
add in class SubModel
Parameters:
r - The relation to add.

add

public void add(Relation[] rels)
Adds an array of relations to the partition.

Overrides:
add in class SubModel
Parameters:
rels - The array of relations to add.

remove

public boolean remove(Relation r)
Removes a relation from the partition. Returns false if the relation is not present in the partition.

Overrides:
remove in class SubModel

remove

public boolean remove(Entity ent)
Removes an entity from the submodel. Return false if the relation is not present in the partition.

Overrides:
remove in class SubModel

contains

public boolean contains(Entity ent)
Returns true if the submodel contains the entity.

Overrides:
contains in class SubModel

contains

public boolean contains(Relation rel)
Returns true if the submodel contains the relation.

Overrides:
contains in class SubModel

getEntities

public Entity[] getEntities()
Returns an array of all the entities in the submodel.

Overrides:
getEntities in class SubModel

getRelations

public Relation[] getRelations()
Returns an array of all the relations in the submodel.

Overrides:
getRelations in class SubModel

remove

public void remove()
Removes the partition from the KnowledgeModel.


getPartitionData

protected PartitionData getPartitionData()
Returns the PartitionData object in case a subclass needs to manipulate it directly.


getID

public java.lang.Object getID()
Returns the unique ID of this partition. The kind of object this method returns depends on the implementation of the PartitionData class.


getKnowledgeModel

public KnowledgeModel getKnowledgeModel()
Returns the knowledgemodel this partition belongs to.


getCreationTime

public long getCreationTime()
Returns the time of creation of this partition, in the the format as System.currentTimeMillis();


equals

public boolean equals(java.lang.Object ob)
Two entities are considered equal if they represent the same PartitionData object.


toString

public java.lang.String toString()
Overrides:
toString in class SubModel

hashCode

public int hashCode()
Overrides the hashCode() method to match the class' new equals() method.



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