Java Code Examples for org.nlpcn.commons.lang.tire.domain.Forest#getWord()

The following examples show how to use org.nlpcn.commons.lang.tire.domain.Forest#getWord() . 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: GetWordTest.java    From nlp-lang with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
	/**
	 * 词典的构造.一行一个词后面是参数.可以从文件读取.可以是read流.
	 */
	long start = System.currentTimeMillis();
	String dic = "android\t10\t孙健\nc\t100\nC++\t10\nc++\t5\nc#\t100\nVC++\t100".toLowerCase();
	System.out.println(dic);
	Forest forest = Library.makeForest(new BufferedReader(new StringReader(dic)));
	/**
	 * 删除一个单词
	 */
	Library.removeWord(forest, "中国");
	/**
	 * 增加一个新词
	 */
	Library.insertWord(forest, "中国人");
	String content = "Android--中国人";
	content = StringUtil.rmHtmlTag(content);

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

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