jcreek.representation
Class Entity

java.lang.Object
  extended byjcreek.representation.Entity
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Comparable
Direct Known Subclasses:
EntityType

public class Entity
extends java.lang.Object
implements java.lang.Comparable, java.lang.Cloneable

The Entity Class encapsulates a node in the semantic network, and has references to all relations from and to the entity. An Entity instance actually encapsulates the node, and there may be several instances of Entity representing each node, like a pointer. This means that an Entity can't be serialized directly (but a KnowledgeModel object may be), and a clone created of an Entity will not make another node in the semantic network but another pointer to the same node.

Version:
2.0
Author:
Frode Sørmo

Constructor Summary
Entity(KnowledgeModel knowledgeModel, java.lang.String name, java.lang.String description)
          Create a new entity with the given name, description and creator object.
Entity(KnowledgeModel knowledgeModel, java.lang.String name, java.lang.String description, java.lang.Object user)
          Added for compatibility reason.
 
Method Summary
 void addConstraint(Constraint constraint)
          Adds a constrait to the entity.
 Relation addRelation(RelationType relationType, Entity value)
          Adds a relation.
 Relation addRelation(RelationType relationType, Entity value, double strength)
          Adds a relation with the given strength.
 Relation addRelation(java.lang.String relationType, Entity value)
          Adds a relation.
 Relation addRelation(java.lang.String relationType, Entity value, double explanationStrength)
          Adds a relation with a given strength.
 Relation addRelation(java.lang.String relationType, java.lang.String value)
          Adds a relation with the default strength.
 Relation addRelation(java.lang.String relationType, java.lang.String value, double explanationStrength)
          Adds a relation with a given strength.
 java.lang.Object clone()
          Creates a clone of this Entity.
 int compareTo(java.lang.Object o)
          Sorting function, sorts the entity according to name.
 boolean equals(java.lang.Object ob)
          Two entities are considered equal if they represent the same EntityData object.
 Entity[] getAllSubclasses()
          Returns all direct and indirect subclasses of this entity.
 java.util.Collection getAllSubclassesCollection()
           
 Entity[] getAllSuperclasses()
          Returns all direct and indirect subclasses of this entity.
 java.util.Collection getAllSuperclassesCollection()
           
 Constraint[] getConstraints()
          Returns all local and inherited constraints for this entity.
 long getCreationTime()
          Returns the time of creation of this concept, in the the format as System.currentTimeMillis();
 Partition getCurrentPartition()
          Returns the current partition, if set.
 java.lang.String getDescription()
          Returns a description of this entity.
protected  EntityData getEntityData()
          Returns the EntityData object in case a subclass needs to manipulate it directly.
 java.io.Serializable getEntityObject()
          Returns the object encapsulated by this entity.
 java.lang.String getFrameString()
          Returns a string representation of this entity, including all relations from it.
 java.lang.Object getID()
          Returns the unique ID of this relation.
 Entity[] getImmediateSubclasses()
          Returns all the direct subclasses of this entity.
 java.util.Collection getImmediateSubclassesCollection()
           
 Entity[] getImmediateSuperclasses()
          Returns the direct superclass(es) of this entity.
 java.util.Collection getImmediateSuperclassesCollection()
           
 Constraint[] getInheritedConstraints()
          Returns all inherited constraints for this entity
 KnowledgeModel getKnowledgeModel()
          Returns the knowledgemodel this concept belongs to.
 Constraint[] getLocalConstraints()
          Returns all local constraints for this entity.
 Relation getLocalRelation(RelationType rcd)
          Returns the first relation of a given type (local relations only, no inherited relations).
 Relation getLocalRelation(RelationType[] rcd)
          Returns the first relation of a given set of types (local relations only, no inherited relations).
 Relation getLocalRelation(RelationType relationType, Entity value)
          Returns the first relation of the given type to the given value.
 Relation getLocalRelation(RelationType relationType, Entity value, double strength)
          Returns the first relation of the given type to the given value and explanation strength.
 Relation getLocalRelation(java.lang.String relationName)
          Returns the first relation of a given type (only local relations, no inherited relations).
 Relation getLocalRelation(java.lang.String[] relationName)
          Given an array of strings, this method retrieves the set of local relations where the name of the relation-type (the RelationType) match any of the given relation name, and returns the first from that set.
 Relation[] getLocalRelations()
          Returns all local relations from this entity.
 Relation[] getLocalRelations(RelationType relationClass)
          Returns all relations of the type relationClass that lead from or to this entity.
 Relation[] getLocalRelations(RelationType[] types)
          Returns all local relations from or to this entity with any of the specified relation types.
 Relation[] getLocalRelations(java.lang.String relationName)
          Returns all relations from or to this entity with the specified name.
 Relation[] getLocalRelations(java.lang.String[] relationName)
          Returns all relations from or to this entity with any of the specified names.
 java.lang.String getName()
          Returns the name of this entity.
 Relation getRelation(RelationType rcd)
          Returns the first relation of a given type.
 Relation getRelation(RelationType[] rcd)
          Returns the first relation in a set of given types.
 Relation getRelation(java.lang.String relationName)
          Returns the first relation of a given type.
 Relation getRelation(java.lang.String[] relationName)
          Given an array of strings, this method retrieves the set of relations where the name of the relation-type (the RelationType) match any of the given relation name, and returns the first from that set.
 java.lang.String[] getRelationNames()
          Return all the names of the relation types from this element.
 Relation[] getRelations()
          Returns all relations - local and inherited - for this entity.
 Relation[] getRelations(RelationType relationClass)
          Returns all relations - local and inherited - for this entity.
 Relation[] getRelations(RelationType[] relationClass)
          Returns all relations - local and inherited - for this entity.
 Relation[] getRelations(RelationType[] relationClass, InheritanceMethod method)
          The same as the getRelations(RelationType, InheritanceMethod) method, but it accepts a set of RelationTypes and will return relations with relation-types that match or are subclasses of any of the supplied RelationTypes.
 Relation[] getRelations(RelationType relationClass, InheritanceMethod method)
          Returns all relations - local and inherited - for this entity using the supplied inheritance method.
 Relation[] getRelations(java.lang.String relationName)
          Returns all relations from or to this entity with the specified name.
 Relation[] getRelations(java.lang.String[] relationName)
          Returns all relations from or to this entity with the specified names.
 RelationType[] getRelationTypes()
          Returns all the different relation types from or to the entity.
 java.lang.String getValueString()
          Alternative toString method that should construct a brief string of the entity.
 boolean hasEntityObject()
          Returns true if this Entity encapsulates a Java object.
 int hashCode()
          Overrides the hashCode() method to match the class' new equals() method.
 boolean isAssignableFrom(Entity subclassType)
          Returns true if this entity is a direct or indirect superclass of the given entity.
 void remove()
          Removes the entity.
 void removeConstraint(Constraint constraint)
          Removes a constraint from the entity
 void removeEntityData()
          Removes the EntityData-object encapsulated by this entity.
 void setDescription(java.lang.String description)
          Sets the description of this entity.
 void setEntityObject(java.io.Serializable data)
          Sets an object as beeing encapsulated by this entity.
 void setName(java.lang.String name)
          Attempts to set the name of this entity.
 java.lang.String toString()
          Constructs the string representation of the Object conatined in the value.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Entity

public Entity(KnowledgeModel knowledgeModel,
              java.lang.String name,
              java.lang.String description)
       throws NameAlreadyExistException
Create a new entity with the given name, description and creator object.

Parameters:
knowledgeModel - The KnowledgeModel this concept is a part of.
name - The name of the concept. This name must be unique in the KnowledgeModel unless the model is set to accept duplicates. If it is not, a ConceptAlreadyExistException is thrown.
description - An (optional) description of the entity.

Entity

public Entity(KnowledgeModel knowledgeModel,
              java.lang.String name,
              java.lang.String description,
              java.lang.Object user)
       throws NameAlreadyExistException
Added for compatibility reason. The User object is removed from the represetnation package since it was not used, so this constructor should be replaced by the Entity(KnowledgeModel, String, String) constructor.

Parameters:
knowledgeModel - The KnowledgeModel this concept is a part of.
name - The name of the concept. This name must be unique in the KnowledgeModel unless the model is set to accept duplicates. If it is not, a ConceptAlreadyExistException is thrown.
description - An (optional) description of the entity.
user - The user creating this object, now ignored.
Method Detail

remove

public void remove()
Removes the entity. This will also remove all the realtions from and to the entity. If this entity represents a relation type, all relations of this type will also be removed.


getEntityData

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


getID

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


addRelation

public Relation addRelation(RelationType relationType,
                            Entity value)
Adds a relation.

Parameters:
relationType - The RelationType of the new relation to create.

addRelation

public Relation addRelation(RelationType relationType,
                            Entity value,
                            double strength)
Adds a relation with the given strength.

Parameters:
relationType - The name of the relation type of the new relation to create.
strength - A double value between 0 and 1 representing the relation's strength.

addRelation

public Relation addRelation(java.lang.String relationType,
                            Entity value)
                     throws NoSuchRelationTypeException
Adds a relation.

Throws:
NoSuchRelationTypeException

addRelation

public Relation addRelation(java.lang.String relationType,
                            java.lang.String value)
                     throws NoSuchRelationTypeException,
                            NoSuchEntityException
Adds a relation with the default strength.

Parameters:
relationType - The name of the relation typeype of the new relation to create.
Throws:
NoSuchRelationTypeException
NoSuchEntityException

addRelation

public Relation addRelation(java.lang.String relationType,
                            Entity value,
                            double explanationStrength)
                     throws NoSuchRelationTypeException
Adds a relation with a given strength.

Parameters:
relationType - the name of relationtype.
value - the reference to entity to create relation to.
explanationStrength - the explanation strength for this relation
Throws:
NoSuchRelationTypeException

addRelation

public Relation addRelation(java.lang.String relationType,
                            java.lang.String value,
                            double explanationStrength)
                     throws NoSuchRelationTypeException,
                            NoSuchEntityException
Adds a relation with a given strength.

Parameters:
relationType - the name of relationtype.
value - the reference to entity to create relation to.
explanationStrength - the explanation strength for this relation
Throws:
NoSuchRelationTypeException
NoSuchEntityException

getRelationNames

public java.lang.String[] getRelationNames()
Return all the names of the relation types from this element. This function is different from getRelations in that it also seperates between inverse names and names of relations. Should maybe be replaced by getToRelations() and getFromRelations().


getRelationTypes

public RelationType[] getRelationTypes()
Returns all the different relation types from or to the entity.


getLocalRelations

public Relation[] getLocalRelations(RelationType relationClass)
Returns all relations of the type relationClass that lead from or to this entity.


getLocalRelations

public Relation[] getLocalRelations(java.lang.String relationName)
Returns all relations from or to this entity with the specified name.

Parameters:
relationName - The name of the relation type to return.

getLocalRelations

public Relation[] getLocalRelations(java.lang.String[] relationName)
Returns all relations from or to this entity with any of the specified names.

Parameters:
relationName - The name of the relation type to return.

getRelations

public Relation[] getRelations()
Returns all relations - local and inherited - for this entity. This method use plausible inheritance.


getRelations

public Relation[] getRelations(java.lang.String relationName)
Returns all relations from or to this entity with the specified name.

Parameters:
relationName - The name of the relation type to return.

getRelations

public Relation[] getRelations(java.lang.String[] relationName)
Returns all relations from or to this entity with the specified names.

Parameters:
relationName - The list of names of the relation types to return.

getRelations

public Relation[] getRelations(RelationType relationClass)
Returns all relations - local and inherited - for this entity. Only relations that are of the class specified, or direct or indirect subclasses of it will be returned. This method use plausible inheritance.

Parameters:
relationClass - The RelationType for the type of relations returned.

getRelations

public Relation[] getRelations(RelationType[] relationClass)
Returns all relations - local and inherited - for this entity. Only relations that are of the classes specified, or direct or indirect subclasses of it will be returned. This method use plausible inheritance.

Parameters:
relationClass - The set of RelationTypes for the type of relations returned.

getRelations

public Relation[] getRelations(RelationType relationClass,
                               InheritanceMethod method)
Returns all relations - local and inherited - for this entity using the supplied inheritance method. Only relations that are of the class specified, or direct or indirect subclasses of it will be returned.

Parameters:
relationClass - The RelationType for the type of relations returned. method The inheritance method used.

getRelations

public Relation[] getRelations(RelationType[] relationClass,
                               InheritanceMethod method)
The same as the getRelations(RelationType, InheritanceMethod) method, but it accepts a set of RelationTypes and will return relations with relation-types that match or are subclasses of any of the supplied RelationTypes.

Parameters:
relationClass - The set of RelationType for the type of relations returned. method The inheritance method used.

getRelation

public Relation getRelation(RelationType rcd)
                     throws NoSuchRelationException
Returns the first relation of a given type. If no relations exists of this type, a NoSuchRelationException is thrown.

Parameters:
rcd - The RelationType of the relation-type to find.
Throws:
NoSuchRelationException

getRelation

public Relation getRelation(RelationType[] rcd)
                     throws NoSuchRelationException
Returns the first relation in a set of given types. If no relations exists of any of these types, a NoSuchRelationException is thrown.

Parameters:
rcd - The set of RelationType of the relation-type to find.
Throws:
NoSuchRelationException

getLocalRelation

public Relation getLocalRelation(RelationType rcd)
                          throws NoSuchRelationException
Returns the first relation of a given type (local relations only, no inherited relations). If no relations exists of this type, a NoSuchRelationException is thrown.

Parameters:
rcd - The RelationType of the relation-type to find.
Throws:
NoSuchRelationException

getLocalRelation

public Relation getLocalRelation(RelationType[] rcd)
                          throws NoSuchRelationException
Returns the first relation of a given set of types (local relations only, no inherited relations). If no relations exists of this type, a NoSuchRelationException is thrown.

Parameters:
rcd - The RelationType of the relation-type to find.
Throws:
NoSuchRelationException

getRelation

public Relation getRelation(java.lang.String relationName)
                     throws NoSuchRelationException,
                            NoSuchRelationTypeException
Returns the first relation of a given type. If no relations exists of this type, a NoSuchRelationException is thrown.

Parameters:
relationName - The name of the relation-type to find.
Throws:
NoSuchRelationException
NoSuchRelationTypeException

getRelation

public Relation getRelation(java.lang.String[] relationName)
                     throws NoSuchRelationException,
                            NoSuchRelationTypeException
Given an array of strings, this method retrieves the set of relations where the name of the relation-type (the RelationType) match any of the given relation name, and returns the first from that set. If no such relations exisst, a NoSuchRelationException is thrown.

Throws:
NoSuchRelationException
NoSuchRelationTypeException

getLocalRelation

public Relation getLocalRelation(java.lang.String relationName)
                          throws NoSuchRelationException,
                                 NoSuchRelationTypeException
Returns the first relation of a given type (only local relations, no inherited relations). If no relations exists of this type, a NoSuchRelationException is thrown.

Parameters:
relationName - The name of the relation-type to find.
Throws:
NoSuchRelationException
NoSuchRelationTypeException

getLocalRelation

public Relation getLocalRelation(java.lang.String[] relationName)
                          throws NoSuchRelationException,
                                 NoSuchRelationTypeException
Given an array of strings, this method retrieves the set of local relations where the name of the relation-type (the RelationType) match any of the given relation name, and returns the first from that set. If no such relations exisst, a NoSuchRelationException is thrown.

Throws:
NoSuchRelationException
NoSuchRelationTypeException

getLocalRelation

public Relation getLocalRelation(RelationType relationType,
                                 Entity value)
                          throws NoSuchRelationException
Returns the first relation of the given type to the given value.

Parameters:
relationType - The relation type of the relation to return
value - The value of the relation
Returns:
The first relation matching the above criteria
Throws:
NoSuchRelationException

getLocalRelation

public Relation getLocalRelation(RelationType relationType,
                                 Entity value,
                                 double strength)
                          throws NoSuchRelationException
Returns the first relation of the given type to the given value and explanation strength.

Parameters:
relationType - The relation type of the relation to return
value - The value of the relation
strength - The explanation strength of the relation
Returns:
The first relation matching the above criteria
Throws:
NoSuchRelationException

getLocalRelations

public Relation[] getLocalRelations(RelationType[] types)
Returns all local relations from or to this entity with any of the specified relation types.

Parameters:
types - An array of the types of relations to return.

getLocalRelations

public Relation[] getLocalRelations()
Returns all local relations from this entity.


setName

public void setName(java.lang.String name)
             throws NameAlreadyExistException
Attempts to set the name of this entity. If another concept of this name already exists, a ConceptAlreadyExistException will be thrown. Names starting with "_" is reserverd for system use.

Parameters:
name - The (new) name to assign to this entity.
Throws:
NameAlreadyExistException

getName

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


getCurrentPartition

public Partition getCurrentPartition()
Returns the current partition, if set.


getValueString

public java.lang.String getValueString()
Alternative toString method that should construct a brief string of the entity.

Returns:
String representation of the value

toString

public java.lang.String toString()
Constructs the string representation of the Object conatined in the value. The default implementation should call the toString method of the contained object.

Returns:
String Representation of the object.

getFrameString

public java.lang.String getFrameString()
Returns a string representation of this entity, including all relations from it.


setEntityObject

public void setEntityObject(java.io.Serializable data)
Sets an object as beeing encapsulated by this entity.


removeEntityData

public void removeEntityData()
Removes the EntityData-object encapsulated by this entity. The object itself is not removed from memory, but removed from beeing encapsulated by the entity.


getEntityObject

public java.io.Serializable getEntityObject()
Returns the object encapsulated by this entity.


hasEntityObject

public boolean hasEntityObject()
Returns true if this Entity encapsulates a Java object.


compareTo

public int compareTo(java.lang.Object o)
Sorting function, sorts the entity according to name.

Specified by:
compareTo in interface java.lang.Comparable

equals

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


hashCode

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


getDescription

public java.lang.String getDescription()
Returns a description of this entity.


setDescription

public void setDescription(java.lang.String description)
Sets the description of this entity.


getKnowledgeModel

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


clone

public java.lang.Object clone()
Creates a clone of this Entity. This will not actually make a new node in the semantic network, but another pointer to the same node.


getCreationTime

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


getImmediateSuperclasses

public Entity[] getImmediateSuperclasses()
Returns the direct superclass(es) of this entity.


getImmediateSuperclassesCollection

public java.util.Collection getImmediateSuperclassesCollection()

getImmediateSubclasses

public Entity[] getImmediateSubclasses()
Returns all the direct subclasses of this entity.


getImmediateSubclassesCollection

public java.util.Collection getImmediateSubclassesCollection()

getAllSubclasses

public Entity[] getAllSubclasses()
Returns all direct and indirect subclasses of this entity. An indirect subclass is a entity that can be linked to this entity through several "has subclass" relations.


getAllSubclassesCollection

public java.util.Collection getAllSubclassesCollection()

getAllSuperclasses

public Entity[] getAllSuperclasses()
Returns all direct and indirect subclasses of this entity.


getAllSuperclassesCollection

public java.util.Collection getAllSuperclassesCollection()

isAssignableFrom

public boolean isAssignableFrom(Entity subclassType)
Returns true if this entity is a direct or indirect superclass of the given entity.

Parameters:
subclassType - A relation type to test.

addConstraint

public void addConstraint(Constraint constraint)
Adds a constrait to the entity.

Parameters:
constraint - The constraint to be added

getConstraints

public Constraint[] getConstraints()
Returns all local and inherited constraints for this entity.


getLocalConstraints

public Constraint[] getLocalConstraints()
Returns all local constraints for this entity.


getInheritedConstraints

public Constraint[] getInheritedConstraints()
Returns all inherited constraints for this entity


removeConstraint

public void removeConstraint(Constraint constraint)
Removes a constraint from the entity

Parameters:
constraint - the constraint to be removed


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