use of org.nlpcn.commons.lang.tire.domain.Forest in project ansj_seg by NLPchina.
the class DicLibrary method insert.
/**
* 关键词增加
*
* @param keyword 所要增加的关键词
* @param nature 关键词的词性
* @param freq 关键词的词频
*/
public static void insert(String key, String keyword, String nature, int freq) {
Forest dic = get(key);
String[] paramers = new String[2];
paramers[0] = nature;
paramers[1] = String.valueOf(freq);
Value value = new Value(keyword, paramers);
Library.insertWord(dic, value);
}
use of org.nlpcn.commons.lang.tire.domain.Forest in project ansj_seg by NLPchina.
the class DicLibrary method get.
/**
* 根据模型名称获取crf模型
*
* @param modelName
* @return
*/
public static Forest get(String key) {
KV<String, Forest> kv = DIC.get(key);
if (kv == null) {
if (MyStaticValue.ENV.containsKey(key)) {
putIfAbsent(key, MyStaticValue.ENV.get(key));
return get(key);
}
LOG.warn("dic " + key + " not found in config ");
return null;
}
Forest forest = kv.getV();
if (forest == null) {
forest = init(key, kv);
}
return forest;
}
use of org.nlpcn.commons.lang.tire.domain.Forest in project ansj_seg by NLPchina.
the class ReloadAmbiguityLibrary method loadFormStr.
private static void loadFormStr() {
Forest forest = AmbiguityLibrary.get();
//方法1
Value value = new Value("三个和尚", "三个", "m", "和尚", "n");
Library.insertWord(forest, value);
//方法2
AmbiguityLibrary.insert(AmbiguityLibrary.DEFAULT, "三个", "m", "和尚", "n");
// 将新构建的辞典树替换掉旧的。
AmbiguityLibrary.put(AmbiguityLibrary.DEFAULT, AmbiguityLibrary.DEFAULT, forest);
}
use of org.nlpcn.commons.lang.tire.domain.Forest in project ansj_seg by NLPchina.
the class ManyDicTest method test.
@Test
public void test() {
Forest f1 = new Forest();
f1.addBranch("ansj你好", new String[] { "f1", "1000" });
Forest f2 = new Forest();
f2.addBranch("ansj你不好", new String[] { "f2", "1000" });
Forest f3 = new Forest();
f3.addBranch("ansj你很好", new String[] { "f3", "1000" });
String content = "ansj你好ansj你不好ansj你很好";
System.out.println(ToAnalysis.parse(content, DicLibrary.get(), f1, f2));
System.out.println(ToAnalysis.parse(content, f3, f2));
}
use of org.nlpcn.commons.lang.tire.domain.Forest in project ansj_seg by NLPchina.
the class ReloadUserLibrary method loadFormStr.
private static void loadFormStr() {
Forest forest = new Forest();
Library.insertWord(forest, "中国 nature 1000");
// 将新构建的辞典树替换掉旧的。
DicLibrary.put(DicLibrary.DEFAULT, DicLibrary.DEFAULT, forest);
}
Aggregations