Search in sources :

Example 1 with TermNature

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

the class NatureRecognition method getTermNatures.

/**
	 * 传入一次词语获得相关的词性
	 * 
	 * @param word
	 * @return
	 */
public TermNatures getTermNatures(String word) {
    String[] params = null;
    // 获得词性 , 先从系统辞典。在从用户自定义辞典
    AnsjItem ansjItem = DATDictionary.getItem(word);
    TermNatures tn = null;
    if (ansjItem != AnsjItem.NULL) {
        tn = ansjItem.termNatures;
    } else if ((params = getParams(word)) != null) {
        tn = new TermNatures(new TermNature(params[0], 1));
    } else if (WordAlert.isEnglish(word)) {
        tn = TermNatures.EN;
    } else if (WordAlert.isNumber(word)) {
        tn = TermNatures.M;
    } else {
        tn = TermNatures.NULL;
    }
    return tn;
}
Also used : TermNatures(org.ansj.domain.TermNatures) AnsjItem(org.ansj.domain.AnsjItem) TermNature(org.ansj.domain.TermNature)

Example 2 with TermNature

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

the class Analysis method analysisStr.

/**
	 * 一整句话分词,用户设置的歧异优先
	 * 
	 * @param temp
	 * @return
	 */
private List<Term> analysisStr(String temp) {
    Graph gp = new Graph(temp);
    int startOffe = 0;
    if (this.ambiguityForest != null) {
        GetWord gw = new GetWord(this.ambiguityForest, gp.chars);
        String[] params = null;
        while ((gw.getFrontWords()) != null) {
            if (gw.offe > startOffe) {
                analysis(gp, startOffe, gw.offe);
            }
            params = gw.getParams();
            startOffe = gw.offe;
            for (int i = 0; i < params.length; i += 2) {
                gp.addTerm(new Term(params[i], startOffe, new TermNatures(new TermNature(params[i + 1], 1))));
                startOffe += params[i].length();
            }
        }
    }
    if (startOffe < gp.chars.length) {
        analysis(gp, startOffe, gp.chars.length);
    }
    List<Term> result = this.getResult(gp);
    return result;
}
Also used : Graph(org.ansj.util.Graph) TermNatures(org.ansj.domain.TermNatures) Term(org.ansj.domain.Term) TermNature(org.ansj.domain.TermNature) GetWord(org.nlpcn.commons.lang.tire.GetWord)

Example 3 with TermNature

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

the class UserDefineRecognition method makeNewTerm.

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

Aggregations

TermNature (org.ansj.domain.TermNature)3 TermNatures (org.ansj.domain.TermNatures)3 Term (org.ansj.domain.Term)2 AnsjItem (org.ansj.domain.AnsjItem)1 Graph (org.ansj.util.Graph)1 GetWord (org.nlpcn.commons.lang.tire.GetWord)1