http://blog.csdn.net/yeruby/article/details/42241915 1、简介:IKAnalyzer是一个开源的,基于Java语言开发的轻量级的中文分词工具包。这里使用的是IKAnalyzer2012。
2、IK Analyzer 2012特性:
(1)采用了特有的“正向迭代最细粒度切分算法“,支持细粒度和智能分词两种切分模式;
(2)在系统环境:Core2 i7 3.4G双核,4G内存,window 7 64位, Sun JDK 1.6_29 64位 普通pc环境测试,IK2012具有160万字/秒(3000KB/S)的高速处理能力。
(3)2012版本的智能分词模式支持简单的分词排歧义处理和数量词合并输出。
(4)采用了多子处理器分析模式,支持:英文字母、数字、中文词汇等分词处理,兼容韩文、日文字符。
(5)优化的词典存储,更小的内存占用。支持用户词典扩展定义。特别的,在2012版本,词典支持中文,英文,数字混合词语。
3、测试与使用:
- public class Demo {
-
- //停用词词表
- public static final String stopWordTable = "StopWordTable.txt";
-
- public static void main(String[] args) throws IOException {
-
- //读入停用词文件
- BufferedReader StopWordFileBr = new BufferedReader(new InputStreamReader(new FileInputStream(new File(stopWordTable))));
- //用来存放停用词的集合
- Set<String> stopWordSet = new HashSet<String>();
- //初如化停用词集
- String stopWord = null;
- for(; (stopWord = StopWordFileBr.readLine()) != null;){
- stopWordSet.add(stopWord);
- }
- //测试文本
- String text="不同于计算机,人类一睁眼就能迅速看到和看明白一个场景,因为人的大脑皮层至少有一半以上海量神经元参与了视觉任务的完成。";
- //创建分词对象
- StringReader sr=new StringReader(text);
- IKSegmenter ik=new IKSegmenter(sr, false);
- Lexeme lex=null;
- //分词
- while((lex=ik.next())!=null){
- //去除停用词
- if(stopWordSet.contains(lex.getLexemeText())) {
- continue;
- }
- System.out.print(lex.getLexemeText()+"|");
- }
- //关闭流
- StopWordFileBr.close();
- }
- }
相关文章推荐
|