예제 #1
0
  /*
   * 修正词性
   */
  public static List<Term> updateNature(List<Term> all, Forest... forests) {

    if (forests == null) {
      if (UserDefineLibrary.FOREST != null) {
        forests = new Forest[] {UserDefineLibrary.FOREST};
      } else {
        return all;
      }
    }

    List<Term> result = new ArrayList<Term>();

    for (Term term : all) {

      // 添加对正则停用词的支持
      if ((stopwordPattern != null) && stopwordPattern.matcher(term.getName()).matches()) {
        continue;
      }
      for (Forest forest : forests) {
        String[] params = UserDefineLibrary.getParams(forest, term.getName());
        if (params != null) {
          term.setNature(new Nature(params[0]));
        }
      }
      result.add(term);
    }

    return result;
  }
예제 #2
0
 /*
  * 停用词过滤并且修正词性
  */
 public static List<Term> modifResult(List<Term> all) {
   List<Term> result = new ArrayList<Term>();
   try {
     for (Term term : all) {
       if (FILTER.size() > 0
           && (FILTER.contains(term.getName())
               || (isTag && FILTER.contains(TAG + term.natrue().natureStr)))) {
         continue;
       }
       // 添加对正则停用词的支持
       if ((stopwordPattern != null) && stopwordPattern.matcher(term.getName()).matches()) {
         continue;
       }
       String[] params = UserDefineLibrary.getParams(term.getName());
       if (params != null) {
         term.setNature(new Nature(params[0]));
       }
       result.add(term);
     }
   } catch (Exception e) {
     MyStaticValue.LIBRARYLOG.warn(
         "FilterStopWord.updateDic can not be null , "
             + "you must use set FilterStopWord.setUpdateDic(map) or use method set map");
   }
   return result;
 }
 private void makeNewTerm() {
   Term term = new Term(sb.toString(), offe, tempNature.natureStr, 1);
   term.selfScore = score;
   term.setNature(tempNature);
   if (sb.length() > 3) {
     term.setSubTerm(TermUtil.getSubTerm(from, to));
   }
   TermUtil.termLink(from, term);
   TermUtil.termLink(term, to);
   TermUtil.insertTerm(terms, term);
   TermUtil.parseNature(term);
 }
예제 #4
0
  public void recognition(Result result) {
    List<Term> terms = result.getTerms();
    String end = null;
    String name;

    LinkedList<Term> mergeList = null;

    List<Term> list = new LinkedList<Term>();

    for (Term term : terms) {
      name = term.getName();
      if (end == null) {
        if ((end = ruleMap.get(name)) != null) {
          mergeList = new LinkedList<Term>();
          mergeList.add(term);
        } else {
          list.add(term);
        }
      } else {
        mergeList.add(term);
        if (end.equals(name)) {

          Term ft = mergeList.pollFirst();
          for (Term sub : mergeList) {
            ft.merage(sub);
          }
          ft.setNature(nature);
          list.add(ft);
          mergeList = null;
          end = null;
        }
      }
    }

    if (mergeList != null) {
      for (Term term : list) {
        list.add(term);
      }
    }

    result.setTerms(list);
  }
 /*
  * 停用词过滤并且修正词性
  */
 public static List<Term> modifResult(List<Term> all) {
   List<Term> result = new ArrayList<Term>();
   try {
     for (Term term : all) {
       if (FILTER.size() > 0
           && (FILTER.contains(term.getName())
               || FILTER.contains(TAG + term.getNatrue().natureStr))) {
         continue;
       }
       String[] params = UserDefineLibrary.getParams(term.getName());
       if (params != null) {
         term.setNature(new Nature(params[0]));
       }
       result.add(term);
     }
   } catch (Exception e) {
     System.err.println(
         "FilterStopWord.updateDic can not be null , "
             + "you must use set FilterStopWord.setUpdateDic(map) or use method set map");
   }
   return result;
 }