/** * Constructs a new SpellDictionaryASpell * @param phonetic The file to use for phonetic transformation of the * words list. If <code>phonetic</code> is null, the the transformation * uses {@link DoubleMeta} transformation. * @throws java.io.IOException indicates problems reading the phonetic * information */ public SpellDictionaryASpell(File phonetic) throws IOException { if (phonetic == null) tf = new DoubleMeta(); else tf = new GenericTransformator(phonetic); }
/** * Constructs the SpellChecker with a threshold * * @param dictionary the dictionary used for looking up words. * @param threshold the cost value above which any suggestions are * thrown away */ public SpellChecker(SpellDictionary dictionary, int threshold) { this(dictionary); config.setInteger(Configuration.SPELL_THRESHOLD, threshold); }
/** * Constructs the SpellChecker. */ public SpellChecker() { try { userdictionary = new SpellDictionaryHashMap(); } catch (IOException e) { throw new RuntimeException("this exception should never happen because we are using null phonetic file"); } }
public Word put(Word s) { for (Word w : al) { if (w.s.compareTo(s.getWord()) == 0) { w.setfrequency(); // found it, now stop searching return w; } } // didn't find it; insert al.add(s); return s; }
public static void main(String[] args) { List<Word> freq = histogram("a brown cat eats a white cat."); for (Word word : freq) { System.out.printf("%4d %s\n", word.getFrequency(), word.getWord()); } } }
/** * Construct a transformation table from the phonetic file * @param phonetic the phonetic file as specified in aspell. The file is * supplied as a reader. * @throws java.io.IOException indicates a problem while reading * the phonetic information */ public GenericTransformator(Reader phonetic) throws IOException { buildRules(new BufferedReader(phonetic)); alphabetString = washAlphabetIntoReplaceList(getReplaceList()); }
public void run() { try { buildNewDictionaryDatabase(); loadIndex(); ready = true; } catch (Exception e) { e.printStackTrace(); } } };
@Override protected void putWordUnique(String arg0) { super.putWord(arg0); } };
/** * Compares two words, mostly for the purpose of sorting words. * @param o1 the first word * @param o2 the second word * @return -1 if the first word is more similar to the misspelled word * <br>1 if the second word is more similar to the misspelled word * <br>0 if both words are equally similar * */ public int compare(Object o1, Object o2) { if (((Word) o1).getCost() < ((Word) o2).getCost()) return -1; if (((Word) o1).getCost() == ((Word) o2).getCost()) return 0; return 1; }
/** * Returns the phonetic code representing the word. * @param word The word we want the phonetic code. * @return The value of the phonetic code for the word. */ public String getCode(String word) { return tf.transform(word); }
/** * 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); }
/** * 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); }
/** * Dictionary Constructor. * @param wordList The file containing the words list for the dictionary * @throws java.io.IOException indicates problems reading the words list * file */ public SpellDictionaryHashMap(Reader wordList) throws IOException { super((File) null); createDictionary(new BufferedReader(wordList)); }
public boolean equals(Object o) { if (this == o) return true; if (o instanceof FileSize) { FileSize fs = (FileSize)o; return size==fs.size && fs.equals(fs.filename); } return false; }
public Word put(Word s) { if (al.contains(s)) { for (Word w : al) { if (w.s.compareTo(s.getWord()) == 0) { s.setfrequency(); }// else { //Remove this else, as you add element outside // al.add(s); //} } } else al.add(s); return s; }
public int compareTo(Word other) { return word.compareTo(other.getWord()); }
/** * Constructs a new SpellDictionaryASpell * @param phonetic The Reader to use for phonetic transformation of the * words list. If <code>phonetic</code> is null, the the transformation * uses {@link DoubleMeta} transformation. * @throws java.io.IOException indicates problems reading the phonetic * information */ public SpellDictionaryASpell(Reader phonetic) throws IOException { if (phonetic == null) tf = new DoubleMeta(); else tf = new GenericTransformator(phonetic); }
/** * Constructs a new SpellDictionaryASpell * @param phonetic The file to use for phonetic transformation of the * words list. If <code>phonetic</code> is null, the the transformation * uses {@link DoubleMeta} transformation. * @param encoding Uses the character set encoding specified * @throws java.io.IOException indicates problems reading the phonetic * information */ public SpellDictionaryASpell(File phonetic, String encoding) throws IOException { if (phonetic == null) tf = new DoubleMeta(); else tf = new GenericTransformator(phonetic, encoding); }