use of org.ansj.domain.Term in project ansj_seg by NLPchina.
the class TermUtil method parseNature.
/**
* 得到细颗粒度的分词,并且确定词性
*
* @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;
}
}
use of org.ansj.domain.Term in project ansj_seg by NLPchina.
the class AsianPersonRecognition method getNewWords.
public List<NewWord> getNewWords(Term[] terms) {
this.terms = terms;
List<NewWord> all = new ArrayList<NewWord>();
List<Term> termList = recogntion_();
for (Term term2 : termList) {
all.add(new NewWord(term2.getName(), Nature.NR));
}
return all;
}
use of org.ansj.domain.Term in project ansj_seg by NLPchina.
the class RealWordDemo method main.
public static void main(String[] args) {
// 默认方式
Result parse = ToAnalysis.parse("Hello word是每个程序员必经之路");
System.out.println(parse);
// 保证方式
MyStaticValue.isRealName = true;
parse = ToAnalysis.parse("Hello word是每个程序员必经之路");
for (Term term : parse) {
System.out.print(term.getRealName() + " ");
}
}
use of org.ansj.domain.Term in project ansj_seg by NLPchina.
the class DicLibraryTest method insertTest2.
/**
* 增加关键词
*
* @param keyword
*/
@Test
public void insertTest2() {
DicLibrary.insert(DicLibrary.DEFAULT, "增加新词");
Result parse = DicAnalysis.parse("这是用户自定义词典增加新词的例子");
System.out.println(parse);
boolean flag = false;
for (Term term : parse) {
flag = flag || "增加新词".equals(term.getName());
}
Assert.assertTrue(flag);
}
use of org.ansj.domain.Term in project ansj_seg by NLPchina.
the class DicLibraryTest method insertTest.
/**
* 关键词增加
*
* @param keyword 所要增加的关键词
* @param nature 关键词的词性
* @param freq 关键词的词频
*/
@Test
public void insertTest() {
DicLibrary.insert(DicLibrary.DEFAULT, "增加新词", "我是词性", 1000);
Result parse = DicAnalysis.parse("这是用户自定义词典增加新词的例子");
System.out.println(parse);
boolean flag = false;
for (Term term : parse) {
flag = flag || "增加新词".equals(term.getName());
}
Assert.assertTrue(flag);
}
Aggregations