package org.ansj.library;

import org.ansj.domain.Result;
import org.ansj.domain.Term;
import org.ansj.splitWord.analysis.DicAnalysis;
import org.junit.Assert;
import org.junit.Test;

public class DicLibraryTest {

	/**
	 * 关键词增加
	 *
	 * @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);

	}

	/**
	 * 增加关键词
	 *
	 * @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);
	}

	/**
	 * 删除关键词
	 */
	@Test
	public void delete() {
		insertTest();
		DicLibrary.delete(DicLibrary.DEFAULT, "增加新词");
		Result parse = DicAnalysis.parse("这是用户自定义词典增加新词的例子");
		System.out.println(parse);
		boolean flag = false;
		for (Term term : parse) {
			flag = flag || "增加新词".equals(term.getName());
		}
		Assert.assertFalse(flag);
	}

}

@@ -175,16 +175,66 @@
 it.Test;
+%0Aimport org.nlpcn.commons.lang.tire.domain.Forest;
 %0A%0Apublic
@@ -1365,10 +1365,422 @@
 g);%0A%09%7D%0A%0A
+%09/**%0A%09 * %E8%87%AA%E5%AE%9A%E4%B9%89key%0A%09 */%0A%09@Test%0A%09public void keyTest()%7B%0A%09%09String key = %22dic_mykey%22 ;%0A%09%09DicLibrary.put(key, key, new Forest());%0A%09%09DicLibrary.insert(key, %22%E5%A2%9E%E5%8A%A0%E6%96%B0%E8%AF%8D%22, %22%E6%88%91%E6%98%AF%E8%AF%8D%E6%80%A7%22, 1000);%0A%09%09Result parse = DicAnalysis.parse(%22%E8%BF%99%E6%98%AF%E7%94%A8%E6%88%B7%E8%87%AA%E5%AE%9A%E4%B9%89%E8%AF%8D%E5%85%B8%E5%A2%9E%E5%8A%A0%E6%96%B0%E8%AF%8D%E7%9A%84%E4%BE%8B%E5%AD%90%22,DicLibrary.gets(key));%0A%09%09System.out.println(parse);%0A%09%09boolean flag = false;%0A%09%09for (Term term : parse) %7B%0A%09%09%09flag = flag %7C%7C %22%E5%A2%9E%E5%8A%A0%E6%96%B0%E8%AF%8D%22.equals(term.getName());%0A%09%09%7D%0A%09%09Assert.assertTrue(flag);%0A%09%7D%0A
 %7D%0A

add definekey test