Search in sources :

Example 16 with Forest

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);
}
Also used : MyStaticValue(org.ansj.util.MyStaticValue) Value(org.nlpcn.commons.lang.tire.domain.Value) Forest(org.nlpcn.commons.lang.tire.domain.Forest)

Example 17 with Forest

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;
}
Also used : Forest(org.nlpcn.commons.lang.tire.domain.Forest)

Example 18 with 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);
}
Also used : Value(org.nlpcn.commons.lang.tire.domain.Value) Forest(org.nlpcn.commons.lang.tire.domain.Forest)

Example 19 with 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));
}
Also used : Forest(org.nlpcn.commons.lang.tire.domain.Forest) Test(org.junit.Test)

Example 20 with Forest

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);
}
Also used : Forest(org.nlpcn.commons.lang.tire.domain.Forest)

Aggregations

Forest (org.nlpcn.commons.lang.tire.domain.Forest)20 ArrayList (java.util.ArrayList)4 Term (org.ansj.domain.Term)4 Value (org.nlpcn.commons.lang.tire.domain.Value)4 AsianPersonRecognition (org.ansj.recognition.arrimpl.AsianPersonRecognition)3 ForeignPersonRecognition (org.ansj.recognition.arrimpl.ForeignPersonRecognition)3 NumRecognition (org.ansj.recognition.arrimpl.NumRecognition)3 NlpAnalysis (org.ansj.splitWord.analysis.NlpAnalysis)3 Graph (org.ansj.util.Graph)3 SmartForest (org.nlpcn.commons.lang.tire.domain.SmartForest)3 BufferedReader (java.io.BufferedReader)2 List (java.util.List)2 AnsjTokenizer (org.ansj.lucene.util.AnsjTokenizer)2 UserDefineRecognition (org.ansj.recognition.arrimpl.UserDefineRecognition)2 StopRecognition (org.ansj.recognition.impl.StopRecognition)2 SynonymsRecgnition (org.ansj.recognition.impl.SynonymsRecgnition)2 Analysis (org.ansj.splitWord.Analysis)2 BaseAnalysis (org.ansj.splitWord.analysis.BaseAnalysis)2 DicAnalysis (org.ansj.splitWord.analysis.DicAnalysis)2 IndexAnalysis (org.ansj.splitWord.analysis.IndexAnalysis)2