Class NormalizedLevenshtein
java.lang.Object
info.debatty.java.stringsimilarity.NormalizedLevenshtein
- All Implemented Interfaces:
NormalizedStringDistance
,NormalizedStringSimilarity
,StringDistance
,StringSimilarity
,Serializable
@Immutable
public class NormalizedLevenshtein
extends Object
implements NormalizedStringDistance, NormalizedStringSimilarity
This distance is computed as levenshtein distance divided by the length of
the longest string. The resulting value is always in the interval [0.0 1.0]
but it is not a metric anymore! The similarity is computed as 1 - normalized
distance.
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
-
Field Details
-
l
-
-
Constructor Details
-
NormalizedLevenshtein
public NormalizedLevenshtein()
-
-
Method Details
-
distance
Compute distance as Levenshtein(s1, s2) / max(|s1|, |s2|).- Specified by:
distance
in interfaceStringDistance
- Parameters:
s1
- The first string to compare.s2
- The second string to compare.- Returns:
- The computed distance in the range [0, 1]
- Throws:
NullPointerException
- if s1 or s2 is null.
-
similarity
Return 1 - distance.- Specified by:
similarity
in interfaceStringSimilarity
- Parameters:
s1
- The first string to compare.s2
- The second string to compare.- Returns:
- 1.0 - the computed distance
- Throws:
NullPointerException
- if s1 or s2 is null.
-