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

The following examples show how to use org.ansj.domain.Term#from() . 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: 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 2
Source File: Graph.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
/**
 * 干涉性增加相对权重
 * 
 * @param relationMap
 */
public void walkPath(Map<String, Double> relationMap) {
    Term term = null;
    // BEGIN先行打分
    merger(root, 0, relationMap);
    // 从第一个词开始往后打分
    for (int i = 0; i < terms.length; i++) {
        term = terms[i];
        while (term != null && term.from() != null && term != end) {
            int to = term.toValue();
            merger(term, to, relationMap);
            term = term.next();
        }
    }
    optimalRoot();
}
 
Example 3
Source File: Graph.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
public void walkPathByScore() {
    Term term = null;
    // BEGIN先行打分
    mergerByScore(root, 0);
    // 从第一个词开始往后打分
    for (int i = 0; i < terms.length; i++) {
        term = terms[i];
        while (term != null && term.from() != null && term != end) {
            int to = term.toValue();
            mergerByScore(term, to);
            term = term.next();
        }
    }
    optimalRoot();
}
 
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;
            }
        }
    }

}