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

The following examples show how to use org.ansj.domain.Term#toValue() . 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
/**
 * 删除无意义的节点,防止viterbi太多
 */
public void rmLittleSinglePath() {
    int maxTo = -1;
    Term temp = null;
    for (int i = 0; i < terms.length; i++) {
        if (terms[i] == null)
            continue;
        maxTo = terms[i].toValue();
        if (maxTo - i == 1 || i + 1 == terms.length)
            continue;
        for (int j = i; j < maxTo; j++) {
            temp = terms[j];
            if (temp != null && temp.toValue() <= maxTo && temp.getName().length() == 1) {
                terms[j] = null;
            }
        }
    }
}
 
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: Graph.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
/**
 * 删除最短的节点
 */
public void rmLittlePath() {
    int maxTo = -1;
    Term temp = null;
    Term maxTerm = null;
    // 是否有交叉
    boolean flag = false;
    final int length = terms.length - 1;
    for (int i = 0; i < length; i++) {
        maxTerm = getMaxTerm(i);
        if (maxTerm == null)
            continue;

        maxTo = maxTerm.toValue();

        /**
         * 对字数进行优化.如果一个字.就跳过..两个字.且第二个为null则.也跳过.从第二个后开始
         */
        switch (maxTerm.getName().length()) {
            case 1:
                continue;
            case 2:
                if (terms[i + 1] == null) {
                    i = i + 1;
                    continue;
                }
        }

        /**
         * 判断是否有交叉
         */
        for (int j = i + 1; j < maxTo; j++) {
            temp = getMaxTerm(j);
            if (temp == null) {
                continue;
            }
            if (maxTo < temp.toValue()) {
                maxTo = temp.toValue();
                flag = true;
            }
        }

        if (flag) {
            i = maxTo - 1;
            flag = false;
        } else {
            maxTerm.setNext(null);
            terms[i] = maxTerm;
            for (int j = i + 1; j < maxTo; j++) {
                terms[j] = null;
            }
            // FIXME: 这里理论上得设置。但是跑了这么久,还不发生错误。应该是不依赖于双向链接。需要确认下。这段代码是否有用
            // //将下面的to的from设置回来
            // temp = terms[i+maxTerm.getName().length()] ;
            // do{
            // temp.setFrom(maxTerm) ;
            // }while((temp=temp.next())!=null) ;

        }
    }
}
 
Example 5
Source File: Graph.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
/**
 * 删除小节点。保证被删除的小节点的单个分数小于等于大节点的分数
 */
public void rmLittlePathByScore() {
    int maxTo = -1;
    Term temp = null;
    for (int i = 0; i < terms.length; i++) {
        if (terms[i] == null) {
            continue;
        }
        Term maxTerm = null;
        double maxScore = 0;
        Term term = terms[i];
        // 找到自身分数对大最长的

        do {
            if (maxTerm == null || maxScore > term.score()) {
                maxTerm = term;
            } else if (maxScore == term.score() && maxTerm.getName().length() < term.getName().length()) {
                maxTerm = term;
            }

        } while ((term = term.next()) != null);
        term = maxTerm;
        do {
            maxTo = term.toValue();
            maxScore = term.score();
            if (maxTo - i == 1 || i + 1 == terms.length)
                continue;
            boolean flag = true;// 可以删除
            out: for (int j = i; j < maxTo; j++) {
                temp = terms[j];
                if (temp == null) {
                    continue;
                }
                do {
                    if (temp.toValue() > maxTo || temp.score() < maxScore) {
                        flag = false;
                        break out;
                    }
                } while ((temp = temp.next()) != null);
            }
            // 验证通过可以删除了
            if (flag) {
                for (int j = i + 1; j < maxTo; j++) {
                    terms[j] = null;
                }
            }
        } while ((term = term.next()) != null);
    }
}