com.emarsys.ecommon.collections.fuzzy
Interface FuzzyComparator<T>

All Known Implementing Classes:
AlphabeticalTable, AlphaNumericTriageTable, FuzzyFingerPrint, PrefixTable, TableBasedFingerprint, TextFingerprint, WordTable

public interface FuzzyComparator<T>

A comparison function to measure the similarity between objects that imposes a NO ordering on them.

For the mathematically inclined, the relation:

{(x, y) such that c.compare((Object)x, (Object)y) == 1}.
defined by a given Comparator c and a given set of objects S should be a pseudo equivalence relation, that is the relation imposed by c on S should be consistent with equals in the almost all cases (neglectable number of exceptions).

Be aware of this fuzzyness! An #equals(Object) method based on a FuzzyComparator will never be 100% reliable.

Author:
Michael "kULO" Kulovits
See Also:
FuzzyComparable, Comparator, Comparable, Object.equals(Object)

Method Summary
 float compare(T o1, T o2)
          Compares its two arguments for similarity.
 

Method Detail

compare

float compare(T o1,
              T o2)
              throws FuzzyException
Compares its two arguments for similarity. Returns a floating point number between zero and one representing the degree of similarity.

The implementor should strive for ensuring that the following properties:

  • Pseudo reflexivity: compare(x, x) >= 1-E
  • Pseudo symetry: abs(compare(x, y) - compare(y, x)) <= E
  • Pseudo transitivity: compare(x,y) <= 1-E and compare(y,z) <= 1-E implies compare(x,z) < 1-E with E as small as possible for all x, y, z >= 0.

    Furthermore compare(x, y) must throw an exception iff compare(y, x) throws an exception.

    It is strongly recommended (though not required) that the comparison is consistent with equals. So it is generally the case, but not strictly required that (compare(x, y)==1) == (x.equals(y)). Generally speaking, any comparator that violates this condition should clearly indicate this fact.

    Parameters:
    o1 - the first object to be compared.
    o2 - the second object to be compared.
    Returns:
    a float between 0 and 1 where the latter means "very similar" and the first "not similar".
    Throws:
    FuzzyComparisonException - -
    FuzzyException


  • Copyright © 2010 emarsys AG. All Rights Reserved.