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;
}
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);
}
}
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;
}
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);
}
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();
}
}
Aggregations