Search in sources :

Example 11 with Term

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

the class Graph method walkPath.

/**
	 * 干涉性增加相对权重
	 * 
	 * @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();
}
Also used : Term(org.ansj.domain.Term)

Example 12 with Term

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

the class Graph method printGraph.

/**
	 * 对graph进行调试用的
	 */
public void printGraph() {
    for (Term term : terms) {
        if (term == null) {
            continue;
        }
        System.out.print(term.getName() + "\t" + term.score() + " ,");
        while ((term = term.next()) != null) {
            System.out.print(term + "\t" + term.score() + " ,");
        }
        System.out.println();
    }
}
Also used : Term(org.ansj.domain.Term)

Example 13 with Term

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

the class NameFix method nameAmbiguity.

/**
	 * 人名消歧,比如.邓颖超生前->邓颖 超生 前 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;
            }
        }
    }
}
Also used : NatureRecognition(org.ansj.recognition.impl.NatureRecognition) Term(org.ansj.domain.Term)

Example 14 with Term

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

the class TermUtil method insertTerm.

public static void insertTerm(Term[] terms, List<Term> tempList, TermNatures nr) {
    StringBuilder sb = new StringBuilder();
    int offe = tempList.get(0).getOffe();
    for (Term term : tempList) {
        sb.append(term.getName());
        terms[term.getOffe()] = null;
    }
    Term term = new Term(sb.toString(), offe, TermNatures.NR);
    insertTermNum(terms, term);
}
Also used : Term(org.ansj.domain.Term)

Example 15 with Term

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

the class ForeignPersonRecognition method getNewTerms.

public List<Term> getNewTerms() {
    LinkedList<Term> result = new LinkedList<Term>();
    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) {
            result.add(makeNewTerm());
            reset();
        }
    }
    return result;
}
Also used : Term(org.ansj.domain.Term) LinkedList(java.util.LinkedList)

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