Beispiel #1
0
  // 批量将新词加入到词典中
  private void addListToTerm(List<NewWord> newWords) {
    if (newWords.size() == 0) return;

    for (NewWord newWord : newWords) {
      newWord.setScore(-1);
      addTerm(newWord);
    }
  }
Beispiel #2
0
 /**
  * 增加一个新词到树中
  *
  * @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);
     }
   }
 }
Beispiel #3
0
 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);
     }
   }
 }