com.aliasi.spell
Class FixedWeightEditDistance

java.lang.Object
  extended by com.aliasi.spell.WeightedEditDistance
      extended by com.aliasi.spell.FixedWeightEditDistance
All Implemented Interfaces:
Compilable, Distance<CharSequence>, Proximity<CharSequence>, Serializable

public class FixedWeightEditDistance
extends WeightedEditDistance
implements Compilable, Serializable

A FixedWeightEditDistance sets constant weights for the edit operations for weighted edit distance.

Subclasses of this class may override any of the weight implementations.

Serialization and Compilation

Serialization and compilation both do the same thing, namely store the fixed weight edit distance for reading in later.

Since:
LingPipe2.0
Version:
3.8
Author:
Bob Carpenter
See Also:
Serialized Form

Constructor Summary
FixedWeightEditDistance()
          Constructs an edit distance where the match weight is zero and all other weights are positive infinity.
FixedWeightEditDistance(double matchWeight, double deleteWeight, double insertWeight, double substituteWeight, double transposeWeight)
          Construct a weighted edit distance with the specified constant weights for edits.
 
Method Summary
 void compileTo(ObjectOutput objOut)
          Writes a compiled version of this edit distance to the specified object output.
 double deleteWeight(char cDeleted)
          Returns the constant weight of deleting the specified character.
 double insertWeight(char cInserted)
          Returns the constant weight of inserting the specified character.
 double matchWeight(char cMatched)
          Returns the constant weight of matching the specified character.
 double substituteWeight(char cDeleted, char cInserted)
          Returns the constant weight of substituting the inserted character for the deleted character.
 String toString()
          Returns a string-based representation of this fixed-weight edit distance's parameters.
 double transposeWeight(char cFirst, char cSecond)
          Returns the constant weight of transposing the specified characters.
 
Methods inherited from class com.aliasi.spell.WeightedEditDistance
distance, proximity
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FixedWeightEditDistance

public FixedWeightEditDistance(double matchWeight,
                               double deleteWeight,
                               double insertWeight,
                               double substituteWeight,
                               double transposeWeight)
Construct a weighted edit distance with the specified constant weights for edits.

See the WeightedEditDistance class documewntation for more information on similarity versus dissimialrity measures.

Parameters:
matchWeight - Weight for matching.
deleteWeight - Weight for deleting.
insertWeight - Weight for inserting.
substituteWeight - Weight for substituting.
transposeWeight - Weight for transposing.

FixedWeightEditDistance

public FixedWeightEditDistance()
Constructs an edit distance where the match weight is zero and all other weights are positive infinity. If none of the weight methods are overridden in a sublcass, the result is a string distance that is zero between identical strings and negative infinity otherwise.

Method Detail

toString

public String toString()
Returns a string-based representation of this fixed-weight edit distance's parameters.

Overrides:
toString in class Object
Returns:
String-based representation of this distance.

compileTo

public void compileTo(ObjectOutput objOut)
               throws IOException
Writes a compiled version of this edit distance to the specified object output. If this method is called on an instance of a subclass, only the fixed weight component is compiled. Thus subclasses should either override this method or throw an UnsupportedOperationException.

Specified by:
compileTo in interface Compilable
Parameters:
objOut - The object output to which this fixed weight edit distance is written.
Throws:
IOException - If there is an I/O error while writing.

matchWeight

public double matchWeight(char cMatched)
Returns the constant weight of matching the specified character.

Specified by:
matchWeight in class WeightedEditDistance
Parameters:
cMatched - Character matched.
Returns:
Weight of matching character.

deleteWeight

public double deleteWeight(char cDeleted)
Returns the constant weight of deleting the specified character.

Specified by:
deleteWeight in class WeightedEditDistance
Parameters:
cDeleted - Character deleted.
Returns:
Weight of deleting character.

insertWeight

public double insertWeight(char cInserted)
Returns the constant weight of inserting the specified character.

Specified by:
insertWeight in class WeightedEditDistance
Parameters:
cInserted - Character inserted.
Returns:
Weight of inserting character.

substituteWeight

public double substituteWeight(char cDeleted,
                               char cInserted)
Returns the constant weight of substituting the inserted character for the deleted character.

Specified by:
substituteWeight in class WeightedEditDistance
Parameters:
cDeleted - Deleted character.
cInserted - Inserted character.
Returns:
The weight of substituting the inserted character for the deleted character.

transposeWeight

public double transposeWeight(char cFirst,
                              char cSecond)
Returns the constant weight of transposing the specified characters. Note that the order of arguments follows that of the input.

Specified by:
transposeWeight in class WeightedEditDistance
Parameters:
cFirst - First character in input.
cSecond - Second character in input.
Returns:
The weight of transposing the specified characters.