List of utility methods to do String Levenshtein Distance
int | levenshtein(final String s1, final String s2) https://github.com/tdebatty/java-string-similarity/blob/master/src/main/java/info/debatty/java/stringsimilarity/Levenshtein.java The Levenshtein distance, or edit distance, between two words is the minimum number of single-character edits (insertions, deletions or substitutions) required to change one word into the other. if (s1 == null) { throw new NullPointerException("s1 must not be null"); if (s2 == null) { throw new NullPointerException("s2 must not be null"); if (s1.equals(s2)) { return 0; ... |
int | levenshtein(String s, String t) levenshtein if (s.length() == 0) return t.length(); if (t.length() == 0) return s.length(); if (s.charAt(0) == t.charAt(0)) return levenshtein(s.substring(1), t.substring(1)); int a = levenshtein(s.substring(1), t.substring(1)); int b = levenshtein(s, t.substring(1)); ... |
double | levenshtein(String str1, String str2) levenshtein byte[] bstr1 = str1.toLowerCase().getBytes(); byte[] bstr2 = str2.toLowerCase().getBytes(); int sizeI = bstr1.length + 1; int sizeJ = bstr2.length + 1; int align[][] = new int[sizeI][sizeJ]; int i, j, cost, ins, upd, del, greaterLen; if (sizeI > sizeJ) { greaterLen = sizeI - 1; ... |
int | levenshteinDistance(CharSequence lhs, CharSequence rhs) levenshtein Distance int[][] distance = new int[lhs.length() + 1][rhs.length() + 1]; for (int i = 0; i <= lhs.length(); i++) distance[i][0] = i; for (int j = 1; j <= rhs.length(); j++) distance[0][j] = j; for (int i = 1; i <= lhs.length(); i++) for (int j = 1; j <= rhs.length(); j++) distance[i][j] = Math.min(Math.min(distance[i - 1][j] + 1, distance[i][j - 1] + 1), ... |
int | levenshteinDistance(CharSequence lhs, CharSequence rhs) Shamelessly copied from this website with only a tiny modification: https://en.wikibooks.org/wiki/Algorithm_Implementation/Strings/Levenshtein_distance#Java if (lhs.equals(rhs)) { return 0; int len0 = lhs.length() + 1; int len1 = rhs.length() + 1; int[] cost = new int[len0]; int[] newcost = new int[len0]; for (int i = 0; i < len0; i++) ... |
int | levenshteinDistance(CharSequence s, CharSequence t) Find the Levenshtein distance between two Strings. if (s == null || t == null) throw new IllegalArgumentException("Strings must not be null"); int n = s.length(); int m = t.length(); if (n == 0) return m; else if (m == 0) return n; ... |
int | levenshteinDistance(CharSequence str1, CharSequence str2) NOT CREATED BY ME Shamelessly taken from Wikipedia. int[][] distance = new int[str1.length() + 1][str2.length() + 1]; for (int i = 0; i <= str1.length(); i++) distance[i][0] = i; for (int j = 1; j <= str2.length(); j++) distance[0][j] = j; for (int i = 1; i <= str1.length(); i++) for (int j = 1; j <= str2.length(); j++) distance[i][j] = minimum(distance[i - 1][j] + 1, distance[i][j - 1] + 1, ... |
int | levenshteinDistance(final String string1, final String string2, int swap, int substitution, int insertion, int deletion) levenshtein Distance int i, j; int[] row0 = new int[(string2.length() + 1)]; int[] row1 = new int[(string2.length() + 1)]; int[] row2 = new int[(string2.length() + 1)]; int[] dummy; final byte[] str1 = string1.getBytes(); final byte[] str2 = string2.getBytes(); for (j = 0; j < str2.length; j++) { ... |
int | LevenshteinDistance(String actual, String expected) Levenshtein Distance String s[] = actual.split("\\s+"); String t[] = expected.split("\\s+"); int[][] d = new int[s.length + 1][t.length + 1]; for (int i = 0; i <= s.length; i++) { d[i][0] = i; for (int j = 0; j <= t.length; j++) { d[0][j] = j; ... |
int | levenshteinDistance(String s, String t) levenshtein Distance int n = s.length(); int m = t.length(); if (n == 0) return m; if (m == 0) return n; int[][] d = new int[n + 1][m + 1]; for (int i = 0; i <= n; d[i][0] = i++) ... |