This is the number of changes needed to change one sequence into another, where each change is a single character modification (deletion, insertion or substitution).
This code has been adapted from Apache Commons Lang 3.3.
| Modifier and Type | Field and Description |
|---|---|
| private static final LevenshteinDistance | INSTANCE
The singleton instance. |
| private final Integer | threshold
Threshold. |
| Access | Constructor and Description |
|---|---|
| public | LevenshteinDistance()
Deprecated
Use
getDefaultInstance().
Constructs a default instance that uses a version of the algorithm that does not use a threshold parameter. |
| public | LevenshteinDistance(final Integer
If this is null then distances calculations will not be limited. This may not be negative. threshold)Constructs a new instance. |
| Modifier and Type | Method and Description |
|---|---|
| public Integer | Returns: result distance, or -1.the first input, must not be null. left, final CharSequence the second input, must not be null. right)Implements org. Computes the Levenshtein distance between two Strings. |
| public < The type of similarity score unit. E> Integer | Returns: result distance, or -1.the first input, must not be null. left, final SimilarityInput<E> the second input, must not be null. right)Implements org. Computes the Levenshtein distance between two inputs. |
| public static LevenshteinDistance | |
| public Integer | |
| private static <E> int | Returns: result distance, or -1the first SimilarityInput, must not be null. left, SimilarityInput<E> the second SimilarityInput, must not be null. right, final int the target threshold, must not be negative. threshold)Finds the Levenshtein distance between two CharSequences if it's less than or equal to a given threshold. |
| private static <E> int | Returns: result distance, or -1.the first CharSequence, must not be null. left, SimilarityInput<E> the second CharSequence, must not be null. right)Finds the Levenshtein distance between two Strings. |
| INSTANCE | back to summary |
|---|---|
| private static final LevenshteinDistance INSTANCE The singleton instance. | |
| threshold | back to summary |
|---|---|
| private final Integer threshold Threshold. | |
| LevenshteinDistance | back to summary |
|---|---|
| public LevenshteinDistance()
Deprecated Use Constructs a default instance that uses a version of the algorithm that does not use a threshold parameter.
| |
| LevenshteinDistance | back to summary |
|---|---|
| public LevenshteinDistance(final Integer threshold) Constructs a new instance. If the threshold is not null, distance calculations will be limited to a maximum length. If the threshold is null, the unlimited version of the algorithm will be used.
| |
| apply | back to summary |
|---|---|
| public Integer apply(final CharSequence left, final CharSequence right) Implements org. Computes the Levenshtein distance between two Strings. A higher score indicates a greater distance. The previous implementation of the Levenshtein distance algorithm was from http://www.merriampark.com/ld.htm
Chas Emerick has written an implementation in Java, which avoids an OutOfMemoryError which can occur when my Java implementation is used with very large
strings. distance.apply(null, *) = Throws
| |
| apply | back to summary |
|---|---|
| public <E> Integer apply(final SimilarityInput<E> left, final SimilarityInput<E> right) Implements org. Computes the Levenshtein distance between two inputs. A higher score indicates a greater distance. distance.apply(null, *) = Throws
| |
| getDefaultInstance | back to summary |
|---|---|
| public static LevenshteinDistance getDefaultInstance() Gets the default instance.
| |
| getThreshold | back to summary |
|---|---|
| public Integer getThreshold() Gets the distance threshold.
| |
| limitedCompare | back to summary |
|---|---|
| private static <E> int limitedCompare(SimilarityInput<E> left, SimilarityInput<E> right, final int threshold) Finds the Levenshtein distance between two CharSequences if it's less than or equal to a given threshold. This implementation follows from Algorithms on Strings, Trees and Sequences by Dan Gusfield and Chas Emerick's implementation of the Levenshtein distance algorithm from http://www.merriampark.com/ld.htm limitedCompare(null, *, *) = Throws
| |
| unlimitedCompare | back to summary |
|---|---|
| private static <E> int unlimitedCompare(SimilarityInput<E> left, SimilarityInput<E> right) Finds the Levenshtein distance between two Strings. A higher score indicates a greater distance. The previous implementation of the Levenshtein distance algorithm was from https://web.archive.org/web/20120526085419/http://www.merriampark.com/ldjava.htm This implementation only need one single-dimensional arrays of length s.length() + 1 unlimitedCompare(null, *) = Throws
| |