Class LevenshteinEditDistance

java.lang.Object
com.google.errorprone.names.LevenshteinEditDistance

public class LevenshteinEditDistance
extends Object
A utility class for finding the Levenshtein edit distance between strings. The edit distance between two strings is the number of deletions, insertions, and substitutions required to transform the source to the target. See https://en.wikipedia.org/wiki/Levenshtein_distance.
Author:
eaftan@google.com (Eddie Aftandilian)
  • Method Details

    • getEditDistance

      public static int getEditDistance​(String source, String target)
      Returns the edit distance between two strings.
      Parameters:
      source - The source string.
      target - The target distance.
      Returns:
      The edit distance between the source and target string.
      See Also:
      getEditDistance(String, String, boolean)
    • getEditDistance

      public static int getEditDistance​(String source, String target, boolean caseSensitive)
      Returns the edit distance between two strings. The algorithm used to calculate this distance has space requirements of len(source)*len(target).
      Parameters:
      source - The source string.
      target - The target string
      caseSensitive - If true, case is used in comparisons and 'a' != 'A'.
      Returns:
      The edit distance between the source and target strings.
      See Also:
      getEditDistance(String, String)
    • getNormalizedEditDistance

      public static double getNormalizedEditDistance​(String source, String target, boolean caseSensitive)
      Returns a normalized edit distance between 0 and 1. This is useful if you are comparing or aggregating distances of different pairs of strings
    • getWorstCaseEditDistance

      public static int getWorstCaseEditDistance​(int sourceLength, int targetLength)
      Calculate the worst case distance between two strings with the given lengths