public class StringUtils extends Object
Constructor and Description |
---|
StringUtils() |
Modifier and Type | Method and Description |
---|---|
static int |
getOptimalStringAlignmentDistance(String s,
String t)
Finds the Optimal
string alignment distance – also referred to as the Damerau-Levenshtein distance – between
two strings.
|
public static int getOptimalStringAlignmentDistance(String s, String t)
This is the number of changes needed to change one string into another (insertions, deletions or substitutions of a single character, or transpositions of two adjacent characters).
This implementation is based on the Apache Commons Lang implementation of the Levenshtein distance, only adding support for transpositions.
Note that this is the distance used in Lucene for FuzzyTermsEnum
. Lucene itself has
an implementation of this algorithm, but it is much less efficient in terms of space (also note
that Lucene's implementation does not return the distance, but a similarity score based on it).
s
- the first string, must not be null
.t
- the second string, must not be null
.IllegalArgumentException
- if either String input is null
.StringUtils.getLevenshteinDistance(String, String)
,
LuceneLevenshteinDistance
Copyright © 2012–2018. All rights reserved.