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

The following examples show how to use org.ansj.domain.Term#selfScore() . 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: UserDefineRecognition.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
private void makeNewTerm() {
    StringBuilder sb = new StringBuilder();
    for (int j = offe; j <= endOffe; j++) {
        if (terms[j] == null) {
            continue;
        } else {
            sb.append(terms[j].getName());
        }
    }
    TermNatures termNatures = new TermNatures(new TermNature(tempNature, tempFreq));
    Term term = new Term(sb.toString(), offe, termNatures);
    term.selfScore(-1 * tempFreq);
    TermUtil.insertTerm(terms, term, type);
}
 
Example 2
Source File: NewWordRecognition.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
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, InsertTermType.SCORE_ADD_SORT);
    TermUtil.parseNature(term);
}
 
Example 3
Source File: NewWordRecognition.java    From deeplearning4j with Apache License 2.0 4 votes vote down vote up
public void recognition(Term[] terms) {
    this.terms = terms;
    if (branch == null) {
        return;
    }
    int length = terms.length - 1;

    Term term = null;
    for (int i = 0; i < length; i++) {
        if (terms[i] == null) {
            continue;
        } else {
            from = terms[i].from();
            terms[i].score(0);
            terms[i].selfScore(0);
        }

        branch = branch.getBranch(terms[i].getName());

        if (branch == null || branch.getStatus() == 3) {
            reset();
            continue;
        }

        offe = i;

        // 循环查找添加
        term = terms[i];
        sb.append(term.getName());
        if (branch.getStatus() == 2) {
            term.selfScore(branch.getParam().getScore());
        }
        boolean flag = true;
        while (flag) {
            term = term.to();
            branch = branch.getBranch(term.getName());
            // 如果没有找到跳出
            if (branch == null) {
                break;
            }

            switch (branch.getStatus()) {
                case 1:
                    sb.append(term.getName());
                    continue;
                case 2:
                    sb.append(term.getName());
                    score = branch.getParam().getScore();
                    tempNature = branch.getParam().getNature();
                    to = term.to();
                    makeNewTerm();
                    continue;
                case 3:
                    sb.append(term.getName());
                    score = branch.getParam().getScore();
                    tempNature = branch.getParam().getNature();
                    to = term.to();
                    makeNewTerm();
                    flag = false;
                    break;
                default:
                    System.out.println("怎么能出现0呢?");
                    break;
            }
        }
        reset();
    }
}