// 批量将新词加入到词典中 private void addListToTerm(List<NewWord> newWords) { if (newWords.size() == 0) return; for (NewWord newWord : newWords) { newWord.setScore(-1); addTerm(newWord); } }
/** * 增加一个新词到树中 * * @param newWord */ public void addTerm(NewWord newWord) { NewWord temp = null; SmartForest<NewWord> smartForest = null; if ((smartForest = sf.getBranch(newWord.getName())) != null && smartForest.getParam() != null) { temp = smartForest.getParam(); temp.update(newWord.getScore(), newWord.getNature(), newWord.getAllFreq()); } else { count++; // 设置名字为空,节省内存空间 synchronized (sf) { sf.add(newWord.getName(), newWord); } } }
private void valueResult( SmartForest<NewWord> smartForest, HashMap<String, Double> hm, TermNatures nature) { // TODO Auto-generated method stub if (smartForest == null || smartForest.branches == null) { return; } for (int i = 0; i < smartForest.branches.length; i++) { NewWord param = smartForest.branches[i].getParam(); if (smartForest.branches[i].getStatus() == 3) { if (nature == null || param.getNature().equals(nature)) { hm.put(param.getName(), param.getScore()); } } else if (smartForest.branches[i].getStatus() == 2) { if (nature == null || param.getNature().equals(nature)) { hm.put(param.getName(), param.getScore()); } valueResult(smartForest.branches[i], hm, nature); } else { valueResult(smartForest.branches[i], hm, nature); } } }