use of org.ansj.domain.Term in project ansj_seg by NLPchina.
the class NumRecognition method recognition.
/**
* 数字+数字合并,zheng
*
* @param terms
*/
public void recognition(Term[] terms) {
int length = terms.length - 1;
Term from = null;
Term to = null;
Term temp = null;
for (int i = 0; i < length; i++) {
if (terms[i] == null) {
continue;
} else if (".".equals(terms[i].getName()) || ".".equals(terms[i].getName())) {
// 如果是.前后都为数字进行特殊处理
to = terms[i].to();
from = terms[i].from();
if (from.termNatures().numAttr.flag && to.termNatures().numAttr.flag) {
from.setName(from.getName() + "." + to.getName());
TermUtil.termLink(from, to.to());
terms[to.getOffe()] = null;
terms[i] = null;
i = from.getOffe() - 1;
}
continue;
} else if (!terms[i].termNatures().numAttr.flag) {
continue;
}
temp = terms[i];
// 将所有的数字合并
while ((temp = temp.to()).termNatures().numAttr.flag) {
terms[i].setName(terms[i].getName() + temp.getName());
}
// 如果是数字结尾
if (MyStaticValue.isQuantifierRecognition && temp.termNatures().numAttr.numEndFreq > 0) {
terms[i].setName(terms[i].getName() + temp.getName());
temp = temp.to();
}
// 如果不等,说明terms[i]发生了改变
if (terms[i].to() != temp) {
TermUtil.termLink(terms[i], temp);
// 将中间无用元素设置为null
for (int j = i + 1; j < temp.getOffe(); j++) {
terms[j] = null;
}
i = temp.getOffe() - 1;
}
}
}
use of org.ansj.domain.Term 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);
}
use of org.ansj.domain.Term in project ansj_seg by NLPchina.
the class Graph method mergerByScore.
/**
* 根据分数
*
* @param i 起始位置
* @param j 起始属性
* @param to
*/
private void mergerByScore(Term fromTerm, int to) {
Term term = null;
if (terms[to] != null) {
term = terms[to];
while (term != null) {
// 关系式to.set(from)
term.setPathSelfScore(fromTerm);
term = term.next();
}
}
}
use of org.ansj.domain.Term in project ansj_seg by NLPchina.
the class Graph method rmLittleSinglePath.
/**
* 删除无意义的节点,防止viterbi太多
*/
public void rmLittleSinglePath() {
int maxTo = -1;
Term temp = null;
for (int i = 0; i < terms.length; i++) {
if (terms[i] == null)
continue;
maxTo = terms[i].toValue();
if (maxTo - i == 1 || i + 1 == terms.length)
continue;
for (int j = i; j < maxTo; j++) {
temp = terms[j];
if (temp != null && temp.toValue() <= maxTo && temp.getName().length() == 1) {
terms[j] = null;
}
}
}
}
use of org.ansj.domain.Term in project ansj_seg by NLPchina.
the class Graph method walkPathByScore.
public void walkPathByScore() {
Term term = null;
// BEGIN先行打分
mergerByScore(root, 0);
// 从第一个词开始往后打分
for (int i = 0; i < terms.length; i++) {
term = terms[i];
while (term != null && term.from() != null && term != end) {
int to = term.toValue();
mergerByScore(term, to);
term = term.next();
}
}
optimalRoot();
}
Aggregations