/** * Returns true if the word is correctly spelled against the current word list. */ public boolean isCorrect(String word) { List possible = getWords(getCode(word)); if (possible.contains(word)) return true; //JMH should we always try the lowercase version. If I don't then // capitalized words are always returned as incorrect. else if (possible.contains(word.toLowerCase())) return true; return false; } }
/** * Returns a list of Word objects that are the suggestions to an * incorrect word. * <p> * This method is only needed to provide backward compatibility. * @see #getSuggestions(String, int, int[][]) * @param word Suggestions for given misspelt word * @param threshold The lower boundary of similarity to misspelt word * @return Vector a List of suggestions */ public List getSuggestions(String word, int threshold) { return getSuggestions(word,threshold,null); }
String code = getCode(word); Vector phoneticList = getWordsFromCode(word, nearmisscodes); charArray[i] = b; charArray[i + 1] = a; String s = getCode(new String(charArray)); nearmisscodes.put(s, s); charArray[i] = a; for (j = 0; j < replacelist.length; j++) { charArray[i] = replacelist[j]; String s = getCode(new String(charArray)); nearmisscodes.put(s, s); for (j = 0; j < replacelist.length; j++) { charArray[iy] = replacelist[j]; String s = getCode(new String(charArray)); nearmisscodes.put(s, s); int ii = charArray2.length; while (true) { String s = getCode(new String(charArray)); nearmisscodes.put(s, s); if (ii == 0) Vector wordlist = getWordsFromCode(word, nearmisscodes); addBestGuess(word, phoneticList, matrix);
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; }