Search in sources :

Example 36 with Term

use of org.ansj.domain.Term in project ansj_seg by NLPchina.

the class Graph method getMaxTerm.

/**
	 * 得道最到本行最大term,也就是最右面的term
	 * 
	 * @param i
	 * @return
	 */
private Term getMaxTerm(int i) {
    Term maxTerm = terms[i];
    if (maxTerm == null) {
        return null;
    }
    Term term = maxTerm;
    while ((term = term.next()) != null) {
        maxTerm = term;
    }
    return maxTerm;
}
Also used : Term(org.ansj.domain.Term)

Example 37 with Term

use of org.ansj.domain.Term in project ansj_seg by NLPchina.

the class AsianPersonRecognition method recognition.

// 名称是否有歧异
// public int B = -1;//0 姓氏
// public int C = -1;//1 双名的首字
// public int D = -1;//2 双名的末字
// public int E = -1;//3 单名
// public int N = -1; //4任意字
// public int L = -1;//11 人名的下文
// public int M = -1;//12 两个中国人名之间的成分
// public int m = -1;//44 可拆分的姓名
// double[] factory = {"BC", "BCD", "BCDE"}
public void recognition(Term[] terms) {
    this.terms = terms;
    List<Term> termList = recogntion_();
    for (Term term2 : termList) {
        TermUtil.insertTerm(terms, term2, InsertTermType.SCORE_ADD_SORT);
    }
}
Also used : Term(org.ansj.domain.Term)

Example 38 with Term

use of org.ansj.domain.Term in project ansj_seg by NLPchina.

the class ForeignPersonRecognition method getNewWords.

public List<NewWord> getNewWords(Term[] terms) {
    this.terms = terms;
    List<NewWord> all = new ArrayList<NewWord>();
    String name = null;
    Term term = null;
    reset();
    for (int i = 0; i < terms.length; i++) {
        if (terms[i] == null) {
            continue;
        }
        term = terms[i];
        // 如果名字的开始是人名的前缀,或者后缀.那么忽略
        if (tempList.size() == 0) {
            if (term.termNatures().personAttr.end > 10) {
                continue;
            }
            if ((terms[i].getName().length() == 1 && ISNOTFIRST.contains(terms[i].getName().charAt(0)))) {
                continue;
            }
        }
        name = term.getName();
        if (term.termNatures() == TermNatures.NR || term.termNatures() == TermNatures.NW || name.length() == 1) {
            boolean flag = validate(name);
            if (flag) {
                tempList.add(term);
            }
        } else if (tempList.size() == 1) {
            reset();
        } else if (tempList.size() > 1) {
            StringBuilder sb = new StringBuilder();
            for (Term temp : tempList) {
                sb.append(temp.getName());
            }
            all.add(new NewWord(sb.toString(), Nature.NRF));
            reset();
        }
    }
    return all;
}
Also used : ArrayList(java.util.ArrayList) Term(org.ansj.domain.Term) NewWord(org.ansj.domain.NewWord)

Example 39 with Term

use of org.ansj.domain.Term in project ansj_seg by NLPchina.

the class ForeignPersonRecognition method makeNewTerm.

public Term makeNewTerm() {
    StringBuilder sb = new StringBuilder();
    int offe = tempList.get(0).getOffe();
    for (Term term : tempList) {
        sb.append(term.getName());
    }
    return new Term(sb.toString(), offe, TermNatures.NR);
}
Also used : Term(org.ansj.domain.Term)

Example 40 with Term

use of org.ansj.domain.Term in project ansj_seg by NLPchina.

the class NewWordRecognition method recognition.

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();
    }
}
Also used : Term(org.ansj.domain.Term)

Aggregations

Term (org.ansj.domain.Term)55 ArrayList (java.util.ArrayList)10 Result (org.ansj.domain.Result)8 Test (org.junit.Test)8 TermNatures (org.ansj.domain.TermNatures)5 AsianPersonRecognition (org.ansj.recognition.arrimpl.AsianPersonRecognition)4 ForeignPersonRecognition (org.ansj.recognition.arrimpl.ForeignPersonRecognition)4 NumRecognition (org.ansj.recognition.arrimpl.NumRecognition)4 Graph (org.ansj.util.Graph)4 Forest (org.nlpcn.commons.lang.tire.domain.Forest)4 LinkedList (java.util.LinkedList)3 NewWord (org.ansj.domain.NewWord)3 UserDefineRecognition (org.ansj.recognition.arrimpl.UserDefineRecognition)3 NatureRecognition (org.ansj.recognition.impl.NatureRecognition)3 GetWord (org.nlpcn.commons.lang.tire.GetWord)3 BufferedReader (java.io.BufferedReader)2 HashMap (java.util.HashMap)2 TermNature (org.ansj.domain.TermNature)2 ToAnalysis (org.ansj.splitWord.analysis.ToAnalysis)2 Analyzer (org.apache.lucene.analysis.Analyzer)2