editSimilarity method

double editSimilarity(
  1. String other
)

A normalized measure of editDistance on a scale of 0.0 to 1.0.

The editSimilarity is defined as the difference between the maximum edit distance (sum of the length of the two terms) and the computed editDistance, divided by the maximum edit distance:

  • identical terms with an edit distance of 0 equates to an edit similarity of 1.0; and
  • terms with no shared characters (edit distance equal to sum of the term lengths) have an edit similarity of 0.0.

Not case-sensitive.

Implementation

double editSimilarity(String other) {
  other = other.trim().toLowerCase();
  final term = trim().toLowerCase();
  final similarity = (term.length + other.length - editDistance(other)) /
      (term.length + other.length);
  if (similarity > 1.0) {
    return 1.0;
  }
  return similarity;
}