/** * Returns the candidate string with the closest Levenshtein distance * to the given string. * * @see #getClosestLevenshteinDistance(String,Collection,int) */ public static String getClosestLevenshteinDistance(String str, Collection candidates) { return getClosestLevenshteinDistance(str, candidates, Integer.MAX_VALUE); }
/** * Returns the candidate string with the closest Levenshtein distance * to the given string. * * @param str the string to check * @param candidates the list of strings to test against * @param threshold the threshold distance a candidate must meet * @see #getLevenshteinDistance */ public static String getClosestLevenshteinDistance(String str, Collection<String> candidates, int threshold) { if (candidates == null || candidates.isEmpty()) return null; String minString = null; int minValue = Integer.MAX_VALUE; for(String candidate : candidates) { int distance = getLevenshteinDistance(str, candidate); if (distance < minValue) { minValue = distance; minString = candidate; } } // return the lowest close string only if we surpass the threshhold if (minValue <= threshold) return minString; else return null; }
cost = 1; matrix[i][j] = min(matrix[i - 1][j] + 1, matrix[i][j - 1] + 1, matrix[i - 1][j - 1] + cost);
/** * Returns the candidate string with the closest Levenshtein distance * to the given string. * * @see #getClosestLevenshteinDistance(String,Collection,int) */ public static String getClosestLevenshteinDistance(String str, Collection candidates) { return getClosestLevenshteinDistance(str, candidates, Integer.MAX_VALUE); }
/** * Returns the candidate string with the closest Levenshtein distance * to the given string. * * @param str the string to check * @param candidates the list of strings to test against * @param threshold the threshold distance a candidate must meet * @see #getLevenshteinDistance */ public static String getClosestLevenshteinDistance(String str, Collection<String> candidates, int threshold) { if (candidates == null || candidates.isEmpty()) return null; String minString = null; int minValue = Integer.MAX_VALUE; for(String candidate : candidates) { int distance = getLevenshteinDistance(str, candidate); if (distance < minValue) { minValue = distance; minString = candidate; } } // return the lowest close string only if we surpass the threshhold if (minValue <= threshold) return minString; else return null; }
cost = 1; matrix[i][j] = min(matrix[i - 1][j] + 1, matrix[i][j - 1] + 1, matrix[i - 1][j - 1] + cost);
/** * Returns the candidate string with the closest Levenshtein distance * to the given string. * * @see #getClosestLevenshteinDistance(String,Collection,int) */ public static String getClosestLevenshteinDistance(String str, Collection candidates) { return getClosestLevenshteinDistance(str, candidates, Integer.MAX_VALUE); }
/** * Returns the candidate string with the closest Levenshtein distance * to the given string. * * @param str the string to check * @param candidates the list of strings to test against * @param threshold the threshold distance a candidate must meet * @see #getLevenshteinDistance */ public static String getClosestLevenshteinDistance(String str, Collection<String> candidates, int threshold) { if (candidates == null || candidates.isEmpty()) return null; String minString = null; int minValue = Integer.MAX_VALUE; for(String candidate : candidates) { int distance = getLevenshteinDistance(str, candidate); if (distance < minValue) { minValue = distance; minString = candidate; } } // return the lowest close string only if we surpass the threshhold if (minValue <= threshold) return minString; else return null; }
cost = 1; matrix[i][j] = min(matrix[i - 1][j] + 1, matrix[i][j - 1] + 1, matrix[i - 1][j - 1] + cost);
/** * Returns the candidate string with the closest Levenshtein distance * to the given string. * * @see #getClosestLevenshteinDistance(String,Collection,int) */ public static String getClosestLevenshteinDistance(String str, Collection candidates) { return getClosestLevenshteinDistance(str, candidates, Integer.MAX_VALUE); }
/** * Returns the candidate string with the closest Levenshtein distance * to the given string. * * @param str the string to check * @param candidates the list of strings to test against * @param threshold the threshold distance a candidate must meet * @see #getLevenshteinDistance */ public static String getClosestLevenshteinDistance(String str, Collection candidates, int threshold) { if (candidates == null || candidates.isEmpty()) return null; String minString = null; int minValue = Integer.MAX_VALUE; for (Iterator i = candidates.iterator(); i.hasNext();) { String candidate = (String) i.next(); int distance = getLevenshteinDistance(str, candidate); if (distance < minValue) { minValue = distance; minString = candidate; } } // return the lowest close string only if we surpass the threshhold if (minValue <= threshold) return minString; else return null; }
cost = 1; matrix[i][j] = min(matrix[i - 1][j] + 1, matrix[i][j - 1] + 1, matrix[i - 1][j - 1] + cost);
/** * Returns the candidate string with the closest Levenshtein distance * to the given string. * * @see #getClosestLevenshteinDistance(String,Collection,int) */ public static String getClosestLevenshteinDistance(String str, String[] candidates) { if (candidates == null) return null; return getClosestLevenshteinDistance(str, Arrays.asList(candidates)); }
/** * Returns the candidate string with the closest Levenshtein distance * to the given string. * * @see #getClosestLevenshteinDistance(String,Collection,int) */ public static String getClosestLevenshteinDistance(String str, String[] candidates) { if (candidates == null) return null; return getClosestLevenshteinDistance(str, Arrays.asList(candidates)); }
/** * Returns the candidate string with the closest Levenshtein distance * to the given string. * * @see #getClosestLevenshteinDistance(String,Collection,int) */ public static String getClosestLevenshteinDistance(String str, String[] candidates) { if (candidates == null) return null; return getClosestLevenshteinDistance(str, Arrays.asList(candidates)); }
/** * Returns the candidate string with the closest Levenshtein distance * to the given string. * * @see #getClosestLevenshteinDistance(String,Collection,int) */ public static String getClosestLevenshteinDistance(String str, String[] candidates) { if (candidates == null) return null; return getClosestLevenshteinDistance(str, Arrays.asList(candidates)); }
/** * Returns the candidate string with the closest Levenshtein distance * to the given string. * * @see #getClosestLevenshteinDistance(String,Collection,int) */ public static String getClosestLevenshteinDistance(String str, String[] candidates, int threshold) { if (candidates == null) return null; return getClosestLevenshteinDistance(str, Arrays.asList(candidates), threshold); }
/** * Returns the candidate string with the closest Levenshtein distance * to the given string. * * @see #getClosestLevenshteinDistance(String,Collection,int) */ public static String getClosestLevenshteinDistance(String str, String[] candidates, int threshold) { if (candidates == null) return null; return getClosestLevenshteinDistance(str, Arrays.asList(candidates), threshold); }
/** * Returns the candidate string with the closest Levenshtein distance * to the given string. * * @see #getClosestLevenshteinDistance(String,Collection,int) */ public static String getClosestLevenshteinDistance(String str, String[] candidates, int threshold) { if (candidates == null) return null; return getClosestLevenshteinDistance(str, Arrays.asList(candidates), threshold); }
/** * Returns the candidate string with the closest Levenshtein distance * to the given string and using the threshold as the specified * percentage of the length of the candidate string(0.0f-1.0f). * * @see #getClosestLevenshteinDistance(String,Collection,int) */ public static String getClosestLevenshteinDistance(String str, String[] candidates, float thresholdPercentage) { if (candidates == null) return null; return getClosestLevenshteinDistance(str, Arrays.asList(candidates), thresholdPercentage); }