Java实现使用IK Analyzer实现中文分词
IKAnalyzer.cfg.xml
IKAnalyzer2012.jar
lucene-core-3.6.0.jar
stopword.dic
什么都不用改
[java] view plaincopy
package com.haha.test;
import java.io.IOException;
import java.io.StringReader;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
import org.wltea.analyzer.lucene.IKAnalyzer;
public class Test2 {
public static void main(String[] args) throws IOException {
String text="基于java语言开发的轻量级的中文分词工具包";
//创建分词对象
Analyzer anal=new IKAnalyzer(true);
StringReader reader=new StringReader(text);
//分词
TokenStream ts=anal.tokenStream("", reader);
CharTermAttribute term=ts.getAttribute(CharTermAttribute.class);
//遍历分词数据
while(ts.incrementToken()){
System.out.print(term.toString()+"|");
}
reader.close();
System.out.println();
}
}
posted on 2016-01-19 21:17 1130136248 阅读(3130) 评论(0) 编辑 收藏 举报