de.dfki.mycbr.core.similarity
Class StringFct

java.lang.Object
  extended by java.util.Observable
      extended by de.dfki.mycbr.core.similarity.StringFct
All Implemented Interfaces:
ISimFct, java.util.Observer

public class StringFct
extends java.util.Observable
implements ISimFct

Calculates the similarity of two strings for a given description. At the moment only syntactic equality is supported.

Author:
myCBR Team

Constructor Summary
StringFct(Project prj, StringConfig config, StringDesc desc, java.lang.String name)
          Initializes this with the given description.
 
Method Summary
 Similarity calculateSimilarity(Attribute value1, Attribute value2)
          Calculates the similarity of the given attributes.
 void clone(AttributeDesc descNEW, boolean active)
          Creates a new function which is the same function as this but with a different description, namely descNEW.
 StringConfig getConfig()
          Returns the configuration of this function.
 AttributeDesc getDesc()
          Returns the description of the attributes which can be compared using this function
 MultipleConfig getMultipleConfig()
           
 int getN()
          Returns the parameter n for computing NGRAM similarity.
 java.lang.String getName()
          Returns the name of this function
 Project getProject()
           
 boolean isCaseSensitive()
          Returns whether this function is case sensitive.
 boolean isSymmetric()
          Returns whether this function is symmetric.
 void setCaseSensitive(boolean caseSensitive)
          Specifies whether this function is case sensitive.
 void setMultipleConfig(MultipleConfig mc)
           
 void setN(int n)
          Sets the parameter n for computing NGRAM similarity.
 void setName(java.lang.String name)
          Sets the name of this function to name
 void setSymmetric(boolean symmetric)
          Specifies whether this function is symmetric or not.
 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

StringFct

public StringFct(Project prj,
                 StringConfig config,
                 StringDesc desc,
                 java.lang.String name)
Initializes this with the given description.

Parameters:
desc - the description of the
Method Detail

calculateSimilarity

public Similarity calculateSimilarity(Attribute value1,
                                      Attribute value2)
                               throws java.lang.Exception
Calculates the similarity of the given attributes. Returns null if an error occurs.

Specified by:
calculateSimilarity in interface ISimFct
Parameters:
value1 - the first value
value2 - the second value
Returns:
1.00 if the given attributes are equal, invalid similarity if an error occurs, else 0.00
Throws:
java.lang.Exception

isSymmetric

public boolean isSymmetric()
Returns whether this function is symmetric. Equality and NGRAM similarity is always symmetric.

Specified by:
isSymmetric in interface ISimFct
Returns:
true

setSymmetric

public void setSymmetric(boolean symmetric)
Description copied from interface: ISimFct
Specifies whether this function is symmetric or not. If a function sim is symmetric, sim(q,c) = sim(c,q) should hold for all queries q and cases c this function is defined on. Else the function is asymmetric.

Specified by:
setSymmetric in interface ISimFct
Parameters:
symmetric - specifies whether this function is symmetric or not.

getConfig

public StringConfig getConfig()
Returns the configuration of this function.

Returns:
the configuration describing how to compute similarity

getN

public int getN()
Returns the parameter n for computing NGRAM similarity. N specifies the length of the substrings to be compared.

Returns:
the parameter n

setN

public void setN(int n)
Sets the parameter n for computing NGRAM similarity. N specifies the length of the substrings to be compared.

Parameters:
n - the new parameter n

isCaseSensitive

public boolean isCaseSensitive()
Returns whether this function is case sensitive.

Returns:
true, if function is case sensitive, false otherwise

setCaseSensitive

public void setCaseSensitive(boolean caseSensitive)
Specifies whether this function is case sensitive.

Parameters:
caseSensitive - true, if function is case sensitive, false otherwise

getName

public java.lang.String getName()
Description copied from interface: ISimFct
Returns the name of this function

Specified by:
getName in interface ISimFct
Returns:
the name of this function

setName

public void setName(java.lang.String name)
Description copied from interface: ISimFct
Sets the name of this function to name

Specified by:
setName in interface ISimFct
Parameters:
name - the new name of this function

getDesc

public AttributeDesc getDesc()
Description copied from interface: ISimFct
Returns the description of the attributes which can be compared using this function

Specified by:
getDesc in interface ISimFct
Returns:
the description this function belongs to

getProject

public Project getProject()
Specified by:
getProject in interface ISimFct

getMultipleConfig

public MultipleConfig getMultipleConfig()
Specified by:
getMultipleConfig in interface ISimFct

setMultipleConfig

public void setMultipleConfig(MultipleConfig mc)
Specified by:
setMultipleConfig in interface ISimFct

clone

public void clone(AttributeDesc descNEW,
                  boolean active)
Description copied from interface: ISimFct
Creates a new function which is the same function as this but with a different description, namely descNEW. Assumption: this function fits the description of descNEW.

Specified by:
clone in interface ISimFct

update

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