Class RatcliffObershelp

java.lang.Object
info.debatty.java.stringsimilarity.RatcliffObershelp
All Implemented Interfaces:
NormalizedStringDistance, NormalizedStringSimilarity, StringDistance, StringSimilarity, Serializable

@Immutable public class RatcliffObershelp extends Object implements NormalizedStringSimilarity, NormalizedStringDistance
Ratcliff/Obershelp pattern recognition The Ratcliff/Obershelp algorithm computes the similarity of two strings a the doubled number of matching characters divided by the total number of characters in the two strings. Matching characters are those in the longest common subsequence plus, recursively, matching characters in the unmatched region on either side of the longest common subsequence. The Ratcliff/Obershelp distance is computed as 1 - Ratcliff/Obershelp similarity.
See Also:
  • Constructor Details

    • RatcliffObershelp

      public RatcliffObershelp()
  • Method Details

    • similarity

      public final double similarity(String s1, String s2)
      Compute the Ratcliff-Obershelp similarity between strings.
      Specified by:
      similarity in interface StringSimilarity
      Parameters:
      s1 - The first string to compare.
      s2 - The second string to compare.
      Returns:
      The RatcliffObershelp similarity in the range [0, 1]
      Throws:
      NullPointerException - if s1 or s2 is null.
    • distance

      public final double distance(String s1, String s2)
      Return 1 - similarity.
      Specified by:
      distance in interface StringDistance
      Parameters:
      s1 - The first string to compare.
      s2 - The second string to compare.
      Returns:
      1 - similarity
      Throws:
      NullPointerException - if s1 or s2 is null.
    • getMatchList

      private static List<String> getMatchList(String s1, String s2)
    • frontMaxMatch

      private static String frontMaxMatch(String s1, String s2)