/** * Evaluates the distance between two words. * * @param word One word to evaluates * @param similar The other word to evaluates * @return a number representing how easy or complex it is to transform on * word into a similar one. */ public static final int getDistance(String word, String similar) { return getDistance(word,similar,null); }
/** * For testing edit distances * @param args an array of two strings we want to evaluate their distances. * @throws java.lang.Exception when problems occurs during reading args. */ public static void main(String[] args) throws Exception { BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); int[][] matrix = new int[0][0]; while (true) { String input1 = stdin.readLine(); if (input1 == null || input1.length() == 0) break; String input2 = stdin.readLine(); if (input2 == null || input2.length() == 0) break; System.out.println(EditDistance.getDistance(input1, input2,matrix)); } System.out.println("done"); } }
private Vector getWordsFromCode(String word, Hashtable codes) { Configuration config = Configuration.getConfiguration(); Vector result = new Vector(); int[][] matrix = new int[0][0]; final int configDistance = config.getInteger(Configuration.SPELL_THRESHOLD); for (Enumeration i = codes.keys(); i.hasMoreElements();) { String code = (String) i.nextElement(); List simwordlist = getWords(code); for (Iterator iter = simwordlist.iterator(); iter.hasNext();) { String similar = (String) iter.next(); int distance = EditDistance.getDistance(word, similar, matrix); if (distance < configDistance) { Word w = new Word(similar, distance); result.addElement(w); } } } return result; }
int distance = EditDistance.getDistance(word, similar, matrix); if (distance <= bestScore) { bestScore = distance;