`
NumbCoder
  • 浏览: 24194 次
  • 性别: Icon_minigender_1
  • 来自: 苏州
最近访客 更多访客>>
社区版块
存档分类
最新评论

IK Analyzer 中文分词器---小试牛刀

阅读更多
   最近在跟着导师做一个有关短信过滤的大学生实践项目,之中用到了导师已经发表的关于中文语义分词的算法。一直听说Java开源社区的Lucene搜索很强大,很想研究一下。没想到意外收获到了IK Analyzer,中国人自己也的开源分词器,自己用了下,真的是很好很强大呀。对作者是由衷的钦佩啊!

     看了他提供的API,写了个小例子试了,切词的精准度还是蛮高的。强力推荐。

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;

import org.wltea.analyzer.IKSegmentation;
import org.wltea.analyzer.Lexeme;

public class SearchDemo {
	public static void main(String []args){
		Reader read= null;
		try {
			 read =new FileReader("D:/wz/workspace/SearchDemo/src/test.txt");
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		IKSegmentation iks = new IKSegmentation(read);
		
		while(true){
			Lexeme lex=null;
			try {
				lex = iks.next();
				if(lex != null)
				System.out.print(lex.getLexemeText()+"|");
				if(lex == null)
					return;
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}

}

IK Analyzer作者:linliangyi2007 (林良益)  博客: http://linliangyi2007.iteye.com/
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics