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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal double
Return 1 - similarity.private static String
frontMaxMatch
(String s1, String s2) getMatchList
(String s1, String s2) final double
similarity
(String s1, String s2) Compute the Ratcliff-Obershelp similarity between strings.
-
Constructor Details
-
RatcliffObershelp
public RatcliffObershelp()
-
-
Method Details
-
similarity
Compute the Ratcliff-Obershelp similarity between strings.- Specified by:
similarity
in interfaceStringSimilarity
- 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
Return 1 - similarity.- Specified by:
distance
in interfaceStringDistance
- 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
-
frontMaxMatch
-