예제 #1
0
  /** 人名消歧,比如.邓颖超生前->邓颖 超生 前 fix to 丁颖超 生 前! 规则的方式增加如果两个人名之间连接是- , ·,•则连接 */
  public static void nameAmbiguity(Term[] terms) {
    Term from = null;
    Term term = null;
    Term next = null;
    for (int i = 0; i < terms.length - 1; i++) {
      term = terms[i];
      if (term != null && term.termNatures() == TermNatures.NR && term.getName().length() == 2) {
        next = terms[i + 2];
        if (next.termNatures().personAttr.split > 0) {
          term.setName(term.getName() + next.getName().charAt(0));
          terms[i + 2] = null;
          terms[i + 3] = new Term(next.getName().substring(1), next.getOffe(), TermNatures.NW);
          TermUtil.termLink(term, terms[i + 3]);
          TermUtil.termLink(terms[i + 3], next.to());
        }
      }
    }

    // 外国人名修正
    for (int i = 0; i < terms.length; i++) {
      term = terms[i];
      if (term != null
          && term.getName().length() == 1
          && i > 0
          && WordAlert.CharCover(term.getName().charAt(0)) == '·') {
        from = term.from();
        next = term.to();

        if (from.natrue().natureStr.startsWith("nr") && next.natrue().natureStr.startsWith("nr")) {
          from.setName(from.getName() + term.getName() + next.getName());
          TermUtil.termLink(from, next.to());
          terms[i] = null;
          terms[i + 1] = null;
        }
      }
    }
  }
  /**
   * 数字+数字合并,zheng
   *
   * @param terms
   */
  public static void recognition(Term[] terms) {
    int length = terms.length - 1;
    Term from = null;
    Term to = null;
    Term temp = null;
    for (int i = 0; i < length; i++) {
      if (terms[i] == null) {
        continue;
      } else if (".".equals(terms[i].getName())) {
        // 如果是.前后都为数字进行特殊处理
        to = terms[i].getTo();
        from = terms[i].getFrom();
        if (from.getTermNatures().numAttr.flag && to.getTermNatures().numAttr.flag) {
          from.setName(from.getName() + "." + to.getName());
          TermUtil.termLink(from, to.getTo());
          terms[to.getOffe()] = null;
          terms[i] = null;
          i = from.getOffe() - 1;
        }
        continue;
      } else if (!terms[i].getTermNatures().numAttr.flag) {
        continue;
      }

      temp = terms[i];
      // 将所有的数字合并
      while ((temp = temp.getTo()).getTermNatures().numAttr.flag) {
        terms[i].setName(terms[i].getName() + temp.getName());
      }
      // 如果是数字结尾
      if (temp.getTermNatures().numAttr.numEndFreq > 0) {
        terms[i].setName(terms[i].getName() + temp.getName());
        temp = temp.getTo();
      }

      // 如果不等,说明terms[i]发生了改变
      if (terms[i].getTo() != temp) {
        TermUtil.termLink(terms[i], temp);
        // 将中间无用元素设置为null
        for (int j = i + 1; j < temp.getOffe(); j++) {
          terms[j] = null;
        }
        i = temp.getOffe() - 1;
      }
    }
  }