com.wcohen.ss
Class MultiStringDistance

java.lang.Object
  extended by com.wcohen.ss.MultiStringDistance
All Implemented Interfaces:
StringDistance
Direct Known Subclasses:
MultiStringAvgDistance

public abstract class MultiStringDistance
extends java.lang.Object
implements StringDistance

Abstract class StringDistance defined over Strings that are broken into fields. This could actually be used in several ways:

  1. To merge together scores from a single StringDistance d applied to several different subfields f1,.., fk of a string.
  2. To merge together scores from a multiple StringDistances d1, ..., dk, where di applied to the corresponding fi.

  3. With a little extra coding, this could also be used to merge together scores from a multiple StringDistances applied a single string. This would require using a new MultiStringWrapper constructor that makes k copies of a single string, rather than splitting a string into k disjoint parts.


Constructor Summary
MultiStringDistance(java.lang.String delim)
           
 
Method Summary
protected  MultiStringWrapper asMultiStringWrapper(StringWrapper w)
          Lazily prepare a string.
protected static void doMain(StringDistance d, java.lang.String[] argv)
          Default main routine for testing
 java.lang.String explainScore(java.lang.String s, java.lang.String t)
          Scores are explained by converting Strings to StringWrappers with the prepare function.
 java.lang.String explainScore(StringWrapper s, StringWrapper t)
          Explain how the distance was computed.
protected abstract  java.lang.String explainScoreCombination(double[] multiScore)
          Explain how to combine the scores for each primitive distance function on each field.
protected abstract  StringDistance getDistance(int i)
          Get the distance used for the i-th pair of fields
protected  boolean isLegalMultiStringWrapperSize(int n)
          Check if a string has a valid number of fields.
 StringWrapper prepare(java.lang.String s)
          Prepare a string.
 double score(java.lang.String s, java.lang.String t)
          Strings are scored by converting them to StringWrappers with the prepare function.
 double score(StringWrapper s, StringWrapper t)
          Find the distance between s and t.
protected abstract  double scoreCombination(double[] multiScore)
          Combine the scores for each primitive distance function on each field.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MultiStringDistance

public MultiStringDistance(java.lang.String delim)
Method Detail

score

public final double score(StringWrapper s,
                          StringWrapper t)
Description copied from interface: StringDistance
Find the distance between s and t. Larger values indicate more similar strings.

Specified by:
score in interface StringDistance

scoreCombination

protected abstract double scoreCombination(double[] multiScore)
Combine the scores for each primitive distance function on each field.


explainScore

public final java.lang.String explainScore(StringWrapper s,
                                           StringWrapper t)
Description copied from interface: StringDistance
Explain how the distance was computed.

Specified by:
explainScore in interface StringDistance

explainScoreCombination

protected abstract java.lang.String explainScoreCombination(double[] multiScore)
Explain how to combine the scores for each primitive distance function on each field.


score

public final double score(java.lang.String s,
                          java.lang.String t)
Strings are scored by converting them to StringWrappers with the prepare function.

Specified by:
score in interface StringDistance

explainScore

public final java.lang.String explainScore(java.lang.String s,
                                           java.lang.String t)
Scores are explained by converting Strings to StringWrappers with the prepare function.

Specified by:
explainScore in interface StringDistance

prepare

public final StringWrapper prepare(java.lang.String s)
Prepare a string.

Specified by:
prepare in interface StringDistance

asMultiStringWrapper

protected MultiStringWrapper asMultiStringWrapper(StringWrapper w)
Lazily prepare a string. Ie, if it's already a MultiStringWrapper, do nothing, otherwise use prepare() to convert to a MultiStringWrapper.


getDistance

protected abstract StringDistance getDistance(int i)
Get the distance used for the i-th pair of fields


isLegalMultiStringWrapperSize

protected boolean isLegalMultiStringWrapperSize(int n)
Check if a string has a valid number of fields. Override this method if some assumption is made about the number of fields.


doMain

protected static final void doMain(StringDistance d,
                                   java.lang.String[] argv)
Default main routine for testing