Class RatcliffObershelp

  • All Implemented Interfaces:
    NormalizedStringDistance, NormalizedStringSimilarity, StringDistance, StringSimilarity, java.io.Serializable

    @Immutable
    public class RatcliffObershelp
    extends java.lang.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:
    Serialized Form
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      double distance​(java.lang.String s1, java.lang.String s2)
      Return 1 - similarity.
      private static java.lang.String frontMaxMatch​(java.lang.String s1, java.lang.String s2)  
      private static java.util.List<java.lang.String> getMatchList​(java.lang.String s1, java.lang.String s2)  
      double similarity​(java.lang.String s1, java.lang.String s2)
      Compute the Ratcliff-Obershelp similarity between strings.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • RatcliffObershelp

        public RatcliffObershelp()
    • Method Detail

      • similarity

        public final double similarity​(java.lang.String s1,
                                       java.lang.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:
        java.lang.NullPointerException - if s1 or s2 is null.
      • distance

        public final double distance​(java.lang.String s1,
                                     java.lang.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:
        java.lang.NullPointerException - if s1 or s2 is null.
      • getMatchList

        private static java.util.List<java.lang.String> getMatchList​(java.lang.String s1,
                                                                     java.lang.String s2)
      • frontMaxMatch

        private static java.lang.String frontMaxMatch​(java.lang.String s1,
                                                      java.lang.String s2)