Package Services.Dependencies
Class LevenshteinDistance
java.lang.Object
Services.Dependencies.LevenshteinDistance
Utility class to calculate the Levenshtein distance between two strings.
The Levenshtein distance is a measure of the minimum number of single-character edits (insertions, deletions, or substitutions) required to change one string into another.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intdist(char[] s1, char[] s2) Computes the Levenshtein distance between two character arrays.static intlevenshteinDistance(String s1, String s2) Computes the Levenshtein distance between two strings.
-
Constructor Details
-
LevenshteinDistance
public LevenshteinDistance()
-
-
Method Details
-
levenshteinDistance
Computes the Levenshtein distance between two strings.- Parameters:
s1- the first strings2- the second string- Returns:
- the number of edits required to convert s1 into s2
-
dist
public static int dist(char[] s1, char[] s2) Computes the Levenshtein distance between two character arrays.This implementation uses a memory-efficient approach by storing only the previous row of the distance matrix.
- Parameters:
s1- the first character arrays2- the second character array- Returns:
- the number of edits required to convert s1 into s2
-