Java Code Examples for org.nlpcn.commons.lang.tire.domain.SmartForest#remove()

The following examples show how to use org.nlpcn.commons.lang.tire.domain.SmartForest#remove() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SynonymsLibrary.java    From deeplearning4j with Apache License 2.0 6 votes vote down vote up
/**
 * 从同义词组中删除掉一个词 [中国, 中华, 我国] -> remove(我国) -> [中国, 中华]
 * 
 * @param words
 */
public static void remove(String key, String word) {

    SmartForest<List<String>> synonyms = get(key);

    SmartForest<List<String>> branch = synonyms.getBranch(word);

    if (branch == null || branch.getStatus() < 2) {
        return;
    }

    List<String> params = branch.getParam();

    synonyms.remove(word);
    branch.setParam(null);
    params.remove(word);

    if (params.size() == 1) { //如果是1 个也删除
        synonyms.remove(params.get(0));
        params.remove(0);
    } else {
        params.remove(word);
    }
}
 
Example 2
Source File: SmartGetWordTest.java    From nlp-lang with Apache License 2.0 5 votes vote down vote up
@Test
public void test() {
	/**
	 * 词典的构造.一行一个词后面是参数.可以从文件读取.可以是read流.
	 */
	long start = System.currentTimeMillis();
	SmartForest<Integer> forest = new SmartForest<Integer>();

	forest.add("中国", 3);

	forest.add("android", 3);

	forest.add("java", 3);

	forest.add("中国人", 3);

	String content = " Android-java-中国人";
	
	
	forest.remove("中国人") ;
	
	content = StringUtil.rmHtmlTag(content);

	for (int i = 0; i < 1; i++) {
		SmartGetWord<Integer> udg = forest.getWord(content.toLowerCase().toCharArray());

		String temp;
		while ((temp = udg.getFrontWords()) != null) {
			System.out.println(temp + "\t" + udg.getParam());
		}
	}
	System.out.println(System.currentTimeMillis() - start);
}