本文整理汇总了Java中org.ansj.domain.Term.setNature方法的典型用法代码示例。如果您正苦于以下问题:Java Term.setNature方法的具体用法?Java Term.setNature怎么用?Java Term.setNature使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.ansj.domain.Term
的用法示例。
在下文中一共展示了Term.setNature方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: modifResult
import org.ansj.domain.Term; //导入方法依赖的package包/类
public static List<Term> modifResult(List<Term> all) {
List<Term> result = new ArrayList<Term>();
try {
for (Term term : all) {
if (FILTER.size() > 0 && (FILTER.contains(term.getName()) || (isTag && FILTER.contains(TAG + term.natrue().natureStr)))) {
continue;
}
String[] params = UserDefineLibrary.getParams(term.getName());
if (params != null) {
term.setNature(new Nature(params[0]));
}
result.add(term);
}
} catch (Exception e) {
// TODO Auto-generated catch block
System.err.println("FilterStopWord.updateDic can not be null , " + "you must use set FilterStopWord.setUpdateDic(map) or use method set map");
}
return result;
}
示例2: parseNature
import org.ansj.domain.Term; //导入方法依赖的package包/类
/**
* 得到细颗粒度的分词,并且确定词性
*
* @return 返回是null说明已经是最细颗粒度
*/
public static void parseNature(Term term) {
if (!Nature.NW.equals(term.natrue())) {
return;
}
String name = term.getName();
if (name.length() <= 3) {
return;
}
// 是否是外国人名
if (ForeignPersonRecognition.isFName(name)) {
term.setNature(NatureLibrary.getNature("nrf"));
return;
}
List<Term> subTerm = term.getSubTerm();
// 判断是否是机构名
term.setSubTerm(subTerm);
Term first = subTerm.get(0);
Term last = subTerm.get(subTerm.size() - 1);
int[] is = companyMap.get(first.getName());
int all = 0;
is = companyMap.get(last.getName());
if (is != null) {
all += is[1];
}
if (all > 1000) {
term.setNature(NatureLibrary.getNature("nt"));
return;
}
}
示例3: makeNewTerm
import org.ansj.domain.Term; //导入方法依赖的package包/类
private void makeNewTerm() {
Term term = new Term(sb.toString(), offe, tempNature.natureStr, 1);
term.selfScore(score);
term.setNature(tempNature);
if (sb.length() > 3) {
term.setSubTerm(TermUtil.getSubTerm(from, to));
}
TermUtil.termLink(from, term);
TermUtil.termLink(term, to);
TermUtil.insertTerm(terms, term, InsertTermType.SCORE_ADD_SORT);
TermUtil.parseNature(term);
}
示例4: recognition
import org.ansj.domain.Term; //导入方法依赖的package包/类
@Override
public void recognition(Result result) {
for (Term term : result) {
for (int i = forests.length - 1; i > -1; i--) {
String[] params = getParams(forests[i], term.getName());
if (params != null) {
term.setNature(new Nature(params[0]));
break;
}
}
}
}
示例5: parseNature
import org.ansj.domain.Term; //导入方法依赖的package包/类
/**
* 得到细颗粒度的分词,并且确定词性
*
* @return 返回是null说明已经是最细颗粒度
*/
public static void parseNature(Term term) {
if (!Nature.NW.equals(term.natrue())) {
return;
}
String name = term.getName();
if (name.length() <= 3) {
return;
}
// 是否是外国人名
if (ForeignPersonRecognition.isFName(name)) {
term.setNature(NatureLibrary.getNature("nrf"));
return;
}
List<Term> subTerm = term.getSubTerm();
// 判断是否是机构名
term.setSubTerm(subTerm);
Term first = subTerm.get(0);
Term last = subTerm.get(subTerm.size() - 1);
int[] is = companyMap.get(first.getName());
int all = 0;
is = companyMap.get(last.getName());
if (is != null) {
all += is[1];
}
if (all > 1000) {
term.setNature(NatureLibrary.getNature("nt"));
return;
}
}
示例6: recognition
import org.ansj.domain.Term; //导入方法依赖的package包/类
@Override
public void recognition(Result result) {
String name = "";
String timeWord = "";
List<Term> terms = result.getTerms();
LinkedList<Term> mergeList = new LinkedList<Term>();
List<Term> list = new LinkedList<Term>();
Pattern pattern =
Pattern.compile("((\\d|[0123456789]){1,4}年(\\d|[0123456789]){1,2}月(\\d|[0123456789]){1,2}[日|号](上午|下午|中午|晚)?(\\s)*((\\d|[0123456789]){1,2}([点|时|點|時])?((:)?(\\d|[0123456789]){1,2}(分)?((:)?(\\d|[0123456789]){1,2}(秒)?)?)?)?(\\s)*(PM|AM)?|(\\d|[0123456789]){1,2}(月|月份)(\\d|[0123456789]){1,2}([日|号])?(上午|下午|中午|晚)?(\\s)*((\\d|[0123456789]){1,2}([点|时|點|時])?((:)?(\\d|[0123456789]){1,2}(分)?((:)?(\\d|[0123456789]){1,2}(秒)?)?)?)?(\\s)*(PM|AM)?|(\\d|[0123456789]){1,2}日(上午|下午|中午|晚)?(\\s)*((\\d|[0123456789]){1,2}([点|时|點|時])?((:)?(\\d|[0123456789]){1,2}(分)?((:)?(\\d|[0123456789]){1,2}(秒)?)?)?)?(\\s)*(PM|AM)?|(昨天|昨日|昨日上午|昨日下午|昨日晚上|昨天早上|昨天上午|昨天中午|昨天下午|昨晚|昨夜|昨天晚上|今天早上|今天上午|今天下午|今晚|今天晚上|今日上午|今日下午|今日|今天|前天|今年|去年|当日|当日上午|上午|下午|中午|清晨|前晚|早上|凌晨|今晨|近日|日前|不久前)((\\d|[0123456789]){1,2}[点|时|點|時])?((:)?(\\d|[0123456789]){1,2}(分)?((:)?(\\d|[0123456789]){1,2}(秒)?)?)?(\\s)*(PM|AM)?|[\\“|\"](1|2|3|4|5|6|7|8|9|10|11|12)[·|.| |-](\\d|[0123456789]){1,2}[\\”|\"]|星期[一|二|三|四|五|六|天|日]|(\\d|[0123456789]){1,2}[点|时|點|時]((:)?(\\d|[0123456789]){1,2}(分)?((:)?(\\d|[0123456789]){1,2}(秒)?)?)?(\\s)*(PM|AM)?|(\\d|[0123456789]){4}年((\\d|[0123456789]){1,2}月)?|(\\d|[0123456789]){1,2}月|(正|一|二|三|四|五|六|七|八|九|十|十一|十二|腊)月((初|十|二十|三十)[ 一二三四五六七八九十])?(上午|下午|中午|晚)?|((\\d|[0123456789]){4}-(\\d|[0123456789]){2}-(\\d|[0123456789]){2})?(\\s)*(\\d|[0123456789]){2}:(\\d|[0123456789]){2}:(\\d|[0123456789]){2}|(\\d|[0123456789]){4}-(\\d|[0123456789]){2}-(\\d|[0123456789]){2}(\\s)*((\\d|[0123456789]){2}:(\\d|[0123456789]){2}:(\\d|[0123456789]){2})?)",
Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
for (int i = 0; i < terms.size(); i++) {
boolean isTime = false;
Term termBase = terms.get(i);
int timeTermsLength = 1;
int matchLength = 0; //匹配长度
for (int j = i; j < terms.size() && matchLength < 11; j++) { //向后最大找14个词匹配是否是时间词
Term term = terms.get(j);
name = term.getName();
timeWord += name;
Matcher matcher = pattern.matcher(timeWord);
mergeList.add(term);
if (matcher.matches()) {
isTime = true;
timeTermsLength += (j - i);
i = j;
}
matchLength++;
}
if (isTime) {
Term ft = mergeList.pollFirst();
for (int k = 0; k < timeTermsLength - 1; k++) {
ft.merageWithBlank(mergeList.get(k));
}
ft.setNature(nature);
list.add(ft);
} else {
list.add(termBase);
}
mergeList.clear();
timeWord = "";
}
result.setTerms(list);
}