Java Code Examples for org.ansj.domain.Term#getOffe()

The following examples show how to use org.ansj.domain.Term#getOffe() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KeyWordComputer.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
private double getWeight(Term term, int length, int titleLength) {
    if (term.getName().trim().length() < 2) {
        return 0;
    }

    String pos = term.natrue().natureStr;

    Double posScore = POS_SCORE.get(pos);

    if (posScore == null) {
        posScore = 1.0;
    } else if (posScore == 0) {
        return 0;
    }

    if (titleLength > term.getOffe()) {
        return 5 * posScore;
    }
    return (length - term.getOffe()) * posScore / length;
}
 
Example 2
Source File: Graph.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
/**
 * 取得最优路径的root Term
 * 
 * @return
 */
protected Term optimalRoot() {
    Term to = end;
    to.clearScore();
    Term from = null;
    while ((from = to.from()) != null) {
        for (int i = from.getOffe() + 1; i < to.getOffe(); i++) {
            terms[i] = null;
        }
        if (from.getOffe() > -1) {
            terms[from.getOffe()] = from;
        }
        // 断开横向链表.节省内存
        from.setNext(null);
        from.setTo(to);
        from.clearScore();
        to = from;
    }
    return root;
}
 
Example 3
Source File: TermUtil.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
/**
 * 将两个term合并为一个全新的term
 * 
 * @param termNatures
 * @return
 */
public static Term makeNewTermNum(Term from, Term to, TermNatures termNatures) {
    Term term = new Term(from.getName() + to.getName(), from.getOffe(), termNatures);
    term.termNatures().numAttr = from.termNatures().numAttr;
    TermUtil.termLink(term, to.to());
    TermUtil.termLink(term.from(), term);
    return term;
}
 
Example 4
Source File: NameFix.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
/**
 * 人名消歧,比如.邓颖超生前->邓颖 超生 前 fix to 丁颖超 生 前! 规则的方式增加如果两个人名之间连接是- , ·,•则连接
 */
public static void nameAmbiguity(Term[] terms, Forest... forests) {
    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;

                String name = next.getName().substring(1);
                terms[i + 3] = new Term(name, next.getOffe() + 1,
                                new NatureRecognition(forests).getTermNatures(name));
                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;
            }
        }
    }

}
 
Example 5
Source File: NumRecognition.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
/**
 * 数字+数字合并,zheng
 * 
 * @param terms
 */
@Override
public 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()) || ".".equals(terms[i].getName())) {
            // 如果是.前后都为数字进行特殊处理
            to = terms[i].to();
            from = terms[i].from();
            if (from.termNatures().numAttr.flag && to.termNatures().numAttr.flag) {
                from.setName(from.getName() + "." + to.getName());
                TermUtil.termLink(from, to.to());
                terms[to.getOffe()] = null;
                terms[i] = null;
                i = from.getOffe() - 1;
            }
            continue;
        } else if (!terms[i].termNatures().numAttr.flag) {
            continue;
        }

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

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

}
 
Example 6
Source File: TermUtil.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
public static void insertTermNum(Term[] terms, Term term) {
    terms[term.getOffe()] = term;
}