/** * 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"); } }
@Override protected void putWordUnique(String arg0) { super.putWord(arg0); } };
public void load(File f) { try { dictionary.addDictionary(new FileReader(f)); } catch (IOException e) { e.printStackTrace(); } }
/** * 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)); }
/** * Add words from a Reader to existing dictionary hashmap. * This function can be called as many times as needed to * build the internal word list. Duplicates are not added. * <p> * Note that adding a dictionary does not affect the target * dictionary file for the addWord method. That is, addWord() continues * to make additions to the dictionary file specified in createDictionary() * <P> * @param wordList a Reader object that contains the words, on word per line. * @throws IOException */ public void addDictionary(Reader wordList) throws IOException { addDictionaryHelper(new BufferedReader(wordList)); }
/** * Dictionary constructor that uses an aspell phonetic file to * build the transformation table. * @param wordList The file containing the words list for the dictionary * @param phonetic The reader to use for phonetic transformation of the * wordlist. * @throws java.io.IOException indicates problems reading the words list * or phonetic information */ public SpellDictionaryHashMap(Reader wordList, Reader phonetic) throws IOException { super(phonetic); dictFile = null; createDictionary(new BufferedReader(wordList)); }
/** * Add words from a file to existing dictionary hashmap. * This function can be called as many times as needed to * build the internal word list. Duplicates are not added. * <p> * Note that adding a dictionary does not affect the target * dictionary file for the addWord method. That is, addWord() continues * to make additions to the dictionary file specified in createDictionary() * <P> * @param wordList a File object that contains the words, on word per line. * @throws FileNotFoundException * @throws IOException */ public void addDictionary(File wordList) throws FileNotFoundException, IOException { addDictionaryHelper(new BufferedReader(new FileReader(wordList))); }
/** * Construct spell checker resource. */ public JazzySpellChecker() { // todo load dict file from jazzy.jar archive. InputStream inputStream = getClass().getClassLoader().getResourceAsStream(dictFile); InputStreamReader reader = new InputStreamReader(inputStream); try { dict = new SpellDictionaryHashMap(reader); } catch (IOException e) { throw new RuntimeException(e); } finally { try { reader.close(); } catch (IOException e) { throw new RuntimeException(e); } } resourceStream = new StringBufferResourceStream(contentType); }
/** * Constructs the dictionary from a word list file. * <p> * Each word in the reader should be on a separate line. * <p> * This is a very slow function. On my machine it takes quite a while to * load the data in. I suspect that we could speed this up quite allot. */ protected void createDictionary(BufferedReader in) throws IOException { // robert: Optimized ever-so-slightly String line; while ((line=in.readLine())!=null) { if (line.length() > 0) { putWord(line); } } }
/** * Dictionary constructor that uses an aspell phonetic file to * build the transformation table. * @param wordList The file containing the words list for the dictionary * @param phonetic The file to use for phonetic transformation of the * wordlist. * @throws java.io.FileNotFoundException indicates problems locating the * file on the system * @throws java.io.IOException indicates problems reading the words list * file */ public SpellDictionaryHashMap(File wordList, File phonetic) throws FileNotFoundException, IOException { super(phonetic); dictFile = wordList; createDictionary(new BufferedReader(new FileReader(wordList))); }
public boolean load(String file) { try { ClarionRandomAccessFile craf = ClarionFileFactory.getInstance().getRandomAccessFile(file); dictionary.addDictionary(new InputStreamReader(new InputStreamWrapper(craf))); return true; } catch (IOException e) { e.printStackTrace(); return false; } }
public SpellCheck(String dictFile) { super(); SpellDictionary dictionary = null; try { dictionary = new SpellDictionaryHashMap(new File(dictFile), null); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } spellChecker = new SpellChecker(dictionary); spellChecker.addSpellCheckListener(this); _correctionType = SpellCorrectionType.Add; }
/** * Add a word permanently to the dictionary (and the dictionary file). * <p>This needs to be made thread safe (synchronized)</p> */ public boolean addWord(String word) { putWord(word); if (dictFile!=null) { try { // Append new word to user's word file BufferedWriter w = new BufferedWriter(new FileWriter(dictFile, true)); w.write(word); w.write("\n"); w.close(); return true; } catch (IOException ex) { System.out.println("Error writing to dictionary file"); ex.printStackTrace(); } } // Only return true if added to dictionary file. return false; }
/** * Dictionary constructor that uses an aspell phonetic file to * build the transformation table. Encoding is used for phonetic file only; * default encoding is used for wordList * @param wordList The file containing the words list for the dictionary * @param phonetic The file to use for phonetic transformation of the * wordlist. * @param phoneticEncoding Uses the character set encoding specified * @throws java.io.FileNotFoundException indicates problems locating the * file on the system * @throws java.io.IOException indicates problems reading the words list * or phonetic information */ public SpellDictionaryHashMap(File wordList, File phonetic, String phoneticEncoding) throws FileNotFoundException, IOException { super(phonetic, phoneticEncoding); dictFile = wordList; createDictionary(new BufferedReader(new FileReader(wordList))); }
/** * Construct spell checker resource. */ public JazzySpellChecker() { // todo load dict file from jazzy.jar archive. InputStream inputStream = getClass().getClassLoader().getResourceAsStream(dictFile); InputStreamReader reader = new InputStreamReader(inputStream); try { dict = new SpellDictionaryHashMap(reader); } catch (IOException e) { throw new RuntimeException(e); } finally { try { reader.close(); } catch (IOException e) { throw new RuntimeException(e); } } resourceStream = new StringBufferResourceStream(contentType); }
/** * Construct spell checker resource. */ public JazzySpellChecker() { // todo load dict file from jazzy.jar archive. InputStream inputStream = getClass().getClassLoader().getResourceAsStream(dictFile); InputStreamReader reader = new InputStreamReader(inputStream); try { dict = new SpellDictionaryHashMap(reader); } catch (IOException e) { throw new RuntimeException(e); } finally { try { reader.close(); } catch (IOException e) { throw new RuntimeException(e); } } resourceStream = new StringBufferResourceStream(contentType); }
/** * Construct spell checker resource. */ public JazzySpellChecker() { // todo load dict file from jazzy.jar archive. InputStream inputStream = getClass().getClassLoader().getResourceAsStream(dictFile); InputStreamReader reader = new InputStreamReader(inputStream); try { dict = new SpellDictionaryHashMap(reader); } catch (IOException e) { throw new RuntimeException(e); } finally { try { reader.close(); } catch (IOException e) { throw new RuntimeException(e); } } resourceStream = new StringBufferResourceStream(contentType); }
@Override public void initialize(final UimaContext context) throws ResourceInitializationException { super.initialize(context); InputStream is = null; try { URL url = ResourceUtils.resolveLocation(dictPath, this, context); this.getLogger().debug("Loading dictionary from " + url); is = url.openStream(); dict = new SpellDictionaryHashMap(new InputStreamReader(is, dictEncoding)); } catch (IOException e) { throw new ResourceInitializationException(e); } finally { closeQuietly(is); } }
@Override public void initialize(final UimaContext context) throws ResourceInitializationException { super.initialize(context); InputStream is = null; try { URL url = ResourceUtils.resolveLocation(dictPath, this, context); this.getLogger().debug("Loading dictionary from " + url); is = url.openStream(); dict = new SpellDictionaryHashMap(new InputStreamReader(is, dictEncoding)); } catch (IOException e) { throw new ResourceInitializationException(e); } finally { closeQuietly(is); } }