de.dfki.mycbr.core.model
Class Concept

java.lang.Object
  extended by java.util.Observable
      extended by de.dfki.mycbr.core.model.Concept
All Implemented Interfaces:
IExplainable, java.util.Observer
Direct Known Subclasses:
Project

public class Concept
extends java.util.Observable
implements IExplainable, java.util.Observer

Concepts define the entities in the model. You can build up inheritance hierarchies. Concepts have a set of attribute descriptions and a set of amalgamation functions. The active amalgamation function defines how to calculate the overall similarity of two instances of this concept. There is a set of instances associated with each concept (via a concept range). These instances are used to build up the case base.

Since:
myCBR v3.0.0
Author:
myCBR Team

Constructor Summary
Concept(java.lang.String ID, Project project, Concept superConcept)
          Initializes this with the given name.
 
Method Summary
 AmalgamationFct addAmalgamationFct(AmalgamationConfig amalgam, java.lang.String name, boolean active)
          Creates a new AmalgamationFct for the given description.
 void addAttributeDesc(AttributeDesc desc)
          Adds given description as attribute description to current c description.
 boolean addInstance(Instance i)
          Adds the given instance to this concept's range.
 Instance addInstance(java.lang.String name)
          Adds a new instance to this concept's range.
 void addPartOfRelation(ConceptDesc desc)
          Adds desc as a part of relation of this concept.
 boolean addSubConcept(Concept c, boolean isNew)
          Adds the given concept as sub concept of this.
 boolean canOverride(Concept c)
           
 Instance copyInstance(Instance original, java.lang.String newName)
           
 void delete()
          Deletes the concept with the given ID from this model
 void deleteAmalgamFct(AmalgamationFct f)
          Deletes the given function from the list of known functions for the given description.
 void deletePartOfRelation(ConceptDesc desc)
          Removes the given description as part-of relation.
 AmalgamationFct getActiveAmalgamFct()
          Get the value of activeSimFcts
 java.util.HashMap<java.lang.String,AttributeDesc> getAllAttributeDescs()
          Gets the attribute descriptions of this c including inherited attributes.
 java.util.Collection<Instance> getAllInstances()
          Get all instances known for this concept including instances of sub concepts.
 java.util.HashMap<java.lang.String,Concept> getAllSubConcepts()
          Gets all sub c descriptions by inheritance.
 AttributeDesc getAttributeDesc(java.lang.String name)
          Returns the attribute description with the given name visible in this concept.
 java.util.HashMap<java.lang.String,AttributeDesc> getAttributeDescs()
          Gets the attribute descriptions of this c Be aware that the inherited attribute descriptions are not returned by this method.
 java.util.Vector<AttributeDesc> getAttributesOfSubDescsForName(java.lang.String name)
          Searches for an attribute with the given name.
 java.util.List<AmalgamationFct> getAvailableAmalgamFcts()
          Returns the available similarity functions for the specified description
 java.util.Collection<Instance> getDirectInstances()
          Returns the instances of this concept.
 Explainable getExpType()
           
 AmalgamationFct getFct(java.lang.String name)
           
 Instance getInstance(java.lang.String name)
          Returns the instance of this with name name and null if there is none.
 java.lang.String getName()
           
 java.util.Vector<ConceptDesc> getPartOfRelations()
          Returns all part-of relation known for this concept.
 Project getProject()
          Returns the current project.
 Instance getQueryInstance()
          Returns a new instance that can be used as a query object for retrieval.
 java.util.HashMap<java.lang.String,Concept> getSubConcepts()
          Gets the sub c descriptions by inheritance.
 Concept getSuperConcept()
           
 boolean hasAttributeDesc(java.lang.String name)
           
 boolean hasDirectAttributeDesc(java.lang.String name)
           
 boolean removeAttributeDesc(java.lang.String name)
          Removes the attribute given by name from the attributes of this c.
 void removeInstance(java.lang.String name)
           
 Concept removeSubConcept(java.lang.String name)
          Removes the sub concept with name name.
 void renameAmalgamationFct(java.lang.String nameOLD, java.lang.String nameNEW)
          Should be called when name of an sub concept changes.
 void renameAttDesc(java.lang.String name, java.lang.String name2)
          Sets the name of the attribute description given by name to name2.
 void renameInstance(java.lang.String name, java.lang.String name2)
          Renames the instance with name name.
 void renameSubConcept(java.lang.String nameOLD, java.lang.String nameNEW)
          Should be called when name of an sub concept changes.
 void setActiveAmalgamFct(AmalgamationFct amalgam)
          Set the active amalgamation function for this.
 void setAllInstancesMultiple(AttributeDesc desc)
           
 void setAllInstancesSingle(AttributeDesc desc)
           
 void setName(java.lang.String id)
          Rename this c if possible.
 void setSuperConcept(Concept c, boolean isNew)
          Moves this concept in the inheritance hierarchy.
 void update(java.util.Observable o, java.lang.Object arg)
           
 
Methods inherited from class java.util.Observable
addObserver, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Concept

public Concept(java.lang.String ID,
               Project project,
               Concept superConcept)
        throws java.lang.Exception
Initializes this with the given name. The name should be unique within the whole inheritance hierarchy (model) and within the attributes used for c descriptions. Creates a new range for this description.

Parameters:
ID - the ID to be used for this description.
Throws:
java.lang.Exception
Method Detail

getSubConcepts

public java.util.HashMap<java.lang.String,Concept> getSubConcepts()
Gets the sub c descriptions by inheritance. Empty list if this c does not have sub concepts in inheritance hierarchy.

Returns:
sub c descriptions of this c description

getAllSubConcepts

public java.util.HashMap<java.lang.String,Concept> getAllSubConcepts()
Gets all sub c descriptions by inheritance. Empty list if this c does not have sub concepts in inheritance hierarchy.

Returns:
all sub c descriptions of this c description

getFct

public AmalgamationFct getFct(java.lang.String name)

removeSubConcept

public Concept removeSubConcept(java.lang.String name)
Removes the sub concept with name name. Does nothing if there is no such sub concept and returns null. Adapts instances and cases.

Parameters:
name - the name of the sub concept to be removed
Returns:
the Concept which has been deleted.

renameSubConcept

public void renameSubConcept(java.lang.String nameOLD,
                             java.lang.String nameNEW)
Should be called when name of an sub concept changes. Renames the concept given by nameOLD to nameNEW. Does nothing if there is no sub concept with name nameOLD

Parameters:
nameOLD - the name of the sub concept to be renamed
nameNEW - the new name

getSuperConcept

public Concept getSuperConcept()

removeInstance

public void removeInstance(java.lang.String name)

setSuperConcept

public void setSuperConcept(Concept c,
                            boolean isNew)
Moves this concept in the inheritance hierarchy. After this operation, the this concept will be a sub concept of c. Does nothing if c is null or c is already the super concept of this.

Parameters:
c - the new super concept of this

addSubConcept

public boolean addSubConcept(Concept c,
                             boolean isNew)
Adds the given concept as sub concept of this. If c is null or this does nothing. Returns false, if the action of adding c as a sub concept would lead to a cycle in the inheritance hierarchy.

Parameters:
c - the concept to be added as sub concept
Returns:
true if successfully added, false otherwise

setName

public void setName(java.lang.String id)
             throws java.lang.Exception
Rename this c if possible. Sets the ID to ID if there is no other c with this ID.

Parameters:
id - the new ID for this concept
Throws:
java.lang.Exception

getAttributeDescs

public java.util.HashMap<java.lang.String,AttributeDesc> getAttributeDescs()
Gets the attribute descriptions of this c Be aware that the inherited attribute descriptions are not returned by this method. For all attribute descriptions belonging to this description (including inherited ones) call getAllAttributeDescs()

Returns:
the attribute descriptions that directly belong to this description

getAllAttributeDescs

public java.util.HashMap<java.lang.String,AttributeDesc> getAllAttributeDescs()
Gets the attribute descriptions of this c including inherited attributes. Inherited attributes can be overridden if there is an attribute with the same name in this c and in one of the super concepts.

Returns:
all attribute descriptions that belong to this description

addAttributeDesc

public void addAttributeDesc(AttributeDesc desc)
                      throws java.lang.Exception
Adds given description as attribute description to current c description. Do not add one attribute description to several c descriptions, but create a new one for each.

Parameters:
desc - the attribute description to be added to this description
Throws:
java.lang.Exception

hasDirectAttributeDesc

public boolean hasDirectAttributeDesc(java.lang.String name)

hasAttributeDesc

public boolean hasAttributeDesc(java.lang.String name)

getAttributesOfSubDescsForName

public java.util.Vector<AttributeDesc> getAttributesOfSubDescsForName(java.lang.String name)
Searches for an attribute with the given name. Adds for each subtree the first description appearing in this tree.

Returns:
list of descriptions with given name (only first appearance)

removeAttributeDesc

public boolean removeAttributeDesc(java.lang.String name)
Removes the attribute given by name from the attributes of this c. Does nothing if there is no attribute with this name

Parameters:
name -
Returns:
the attribute description deleted, null if none has been deleted

canOverride

public boolean canOverride(Concept c)

getProject

public Project getProject()
Returns the current project.

Returns:
the project

getDirectInstances

public java.util.Collection<Instance> getDirectInstances()
Returns the instances of this concept. Mark that cases are also instances.

Returns:
all instances of this concept

getAllInstances

public java.util.Collection<Instance> getAllInstances()
Get all instances known for this concept including instances of sub concepts.

Returns:
collection of all instances known for this

addPartOfRelation

public void addPartOfRelation(ConceptDesc desc)
Adds desc as a part of relation of this concept. This means that desc is a concept description which concept equals this.

Parameters:
desc - the description which has a part-of relation to this

getPartOfRelations

public java.util.Vector<ConceptDesc> getPartOfRelations()
Returns all part-of relation known for this concept.

Returns:
all part-of relation known for this concept.

deletePartOfRelation

public void deletePartOfRelation(ConceptDesc desc)
Removes the given description as part-of relation. This function should either be called if the concept of desc changes or if desc is deleted.

Parameters:
desc - the part-of relation to be removed

delete

public void delete()
Deletes the concept with the given ID from this model


getInstance

public Instance getInstance(java.lang.String name)
Returns the instance of this with name name and null if there is none.

Parameters:
name -
Returns:
instance of this with name name

getQueryInstance

public Instance getQueryInstance()
Returns a new instance that can be used as a query object for retrieval.

Returns:
query instance

addInstance

public Instance addInstance(java.lang.String name)
                     throws java.lang.Exception
Adds a new instance to this concept's range. Returns the new instance. If there is an instance with the given name, returns this and does nothing.

Parameters:
name - the name of the new instance
Returns:
the instance with name name
Throws:
java.lang.Exception - if name is null or empty

copyInstance

public Instance copyInstance(Instance original,
                             java.lang.String newName)
                      throws java.lang.Exception
Throws:
java.lang.Exception

addInstance

public boolean addInstance(Instance i)
Adds the given instance to this concept's range.

Parameters:
i - the new instance
Returns:
true if i is added successfully, false otherwise.

renameInstance

public void renameInstance(java.lang.String name,
                           java.lang.String name2)
Renames the instance with name name. Does nothing if there is no such instance.

Parameters:
name - name of the instance to be renamed
name2 - new name of the instance

deleteAmalgamFct

public void deleteAmalgamFct(AmalgamationFct f)
Deletes the given function from the list of known functions for the given description.

Parameters:
f - the function to be deleted

addAmalgamationFct

public AmalgamationFct addAmalgamationFct(AmalgamationConfig amalgam,
                                          java.lang.String name,
                                          boolean active)
Creates a new AmalgamationFct for the given description.

Parameters:
name - the description for which a new function should be created
Returns:
the new AmalgamationFct for description desc

getActiveAmalgamFct

public AmalgamationFct getActiveAmalgamFct()
Get the value of activeSimFcts

Returns:
the value of activeSimFcts

setActiveAmalgamFct

public void setActiveAmalgamFct(AmalgamationFct amalgam)
Set the active amalgamation function for this.

Parameters:
amalgam - the new amalgamation function

getAvailableAmalgamFcts

public java.util.List<AmalgamationFct> getAvailableAmalgamFcts()
Returns the available similarity functions for the specified description

Returns:
the available similarity functions for this

renameAmalgamationFct

public void renameAmalgamationFct(java.lang.String nameOLD,
                                  java.lang.String nameNEW)
Should be called when name of an sub concept changes. Renames the concept given by nameOLD to nameNEW. Does nothing if there is no sub concept with name nameOLD

Parameters:
nameOLD - the name of the sub concept to be renamed
nameNEW - the new name

getAttributeDesc

public AttributeDesc getAttributeDesc(java.lang.String name)
Returns the attribute description with the given name visible in this concept. There might be several descriptions with the given name, but the attribute description returned either belong directly to this concept, or is inherited from a super concept.

Parameters:
name - the name of the attribute description to be returned
Returns:
the attribute with name name, null if there is none.

renameAttDesc

public void renameAttDesc(java.lang.String name,
                          java.lang.String name2)
Sets the name of the attribute description given by name to name2. Does nothing if there is no attribute description with name name

Parameters:
name -
name2 -

getName

public java.lang.String getName()
Specified by:
getName in interface IExplainable
Returns:
the name of this

getExpType

public Explainable getExpType()
Specified by:
getExpType in interface IExplainable
Returns:
the type of this

update

public void update(java.util.Observable o,
                   java.lang.Object arg)
Specified by:
update in interface java.util.Observer

setAllInstancesMultiple

public void setAllInstancesMultiple(AttributeDesc desc)
Parameters:
desc - the description that now uses multiple attributes as values

setAllInstancesSingle

public void setAllInstancesSingle(AttributeDesc desc)
Parameters:
desc - the description that now uses single attributes as values