private String addWord(String word) { if (null != word && !"".equals(word.trim())) { String key = word.trim().toLowerCase(Locale.getDefault()); _dict.fillSegment(key.toCharArray()); return key; } else return null; }
private void loadPrepDict() { _PrepDict = new DictSegment((char) 0); File file = new File(environment.configFile(), Dictionary.PATH_DIC_PREP); InputStream is = null; try { is = new FileInputStream(file); } catch (FileNotFoundException e) { e.printStackTrace(); } if (is == null) { throw new RuntimeException("Preposition Dictionary not found!!!"); } try { BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8"), 512); String theWord; do { theWord = br.readLine(); if (theWord != null && !"".equals(theWord.trim())) { _PrepDict.fillSegment(theWord.trim().toCharArray()); } } while (theWord != null); logger.info("[Dict Loading] {},PrepDict Size:{}", file.toString(), _PrepDict.getDicNum()); } catch (IOException ioe) { System.err.println("Preposition Dictionary loading exception."); ioe.printStackTrace(); } finally { try { if (is != null) { is.close(); is = null; } } catch (IOException e) { e.printStackTrace(); } } }
private void loadMainDict() { _MainDict = new DictSegment((char) 0); File file = new File(environment.configFile(), Dictionary.PATH_DIC_MAIN); InputStream is = null; try { is = new FileInputStream(file); } catch (FileNotFoundException e) { e.printStackTrace(); } if (is == null) { throw new RuntimeException("Main Dictionary not found!!!"); } try { BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8"), 512); String theWord; do { theWord = br.readLine(); if (theWord != null && !"".equals(theWord.trim())) { _MainDict.fillSegment(theWord.trim().toCharArray()); } } while (theWord != null); logger.info("[Dict Loading] {},MainDict Size:{}", file.toString(), _MainDict.getDicNum()); } catch (IOException ioe) { System.err.println("Main Dictionary loading exception."); ioe.printStackTrace(); } finally { try { if (is != null) { is.close(); is = null; } } catch (IOException e) { e.printStackTrace(); } } List<String> extDictFiles = configuration.getExtDictionarys(); if (extDictFiles != null) { for (String extDictName : extDictFiles) { File tempFile = new File(environment.configFile(), extDictName); try { is = new FileInputStream(tempFile); } catch (FileNotFoundException e) { e.printStackTrace(); } if (is == null) { continue; } try { BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8"), 512); String theWord; do { theWord = br.readLine(); if (theWord != null && !"".equals(theWord.trim())) { _MainDict.fillSegment(theWord.trim().toCharArray()); } } while (theWord != null); logger.info("[Dict Loading] {},MainDict Size:{}", file.toString(), _MainDict.getDicNum()); } catch (IOException ioe) { System.err.println("Extension Dictionary loading exception."); ioe.printStackTrace(); } finally { try { if (is != null) { is.close(); is = null; } } catch (IOException e) { e.printStackTrace(); } } } } }
public static Hit matchInMainDictWithHit(char[] charArray, int currentIndex, Hit matchedHit) { DictSegment ds = matchedHit.getMatchedDictSegment(); return ds.match(charArray, currentIndex, 1, matchedHit); }