IKAnalyzer
IKAnalyzer是一个开源的,基于java语言开发的轻量级的中文分词工具包。切词Demo代码如下:
public static void ikSeg() throws Throwable {
String content = "Java编程思想(第4版)";
IKSegmentation ikSeg = new IKSegmentation(new StringReader(content), true);
Lexeme l = null;
while ((l = ikSeg.next()) != null) {
String word = l.getLexemeText();
int wordType = l.getLexemeType();
System.out.println(wordType + "->" + word);
}
}
Ansj:
Ansj中文分词这是一个ictclas的java实现.基本上重写了所有的数据结构和算法.词典是用的开源版的ictclas所提供的.切词Demo代码如下:
public static void ansjSeg() throws Throwable {
String content = "Java编程思想(第4版)";
Analysis udf = new ToAnalysis(new StringReader(content));
Term term = null;
while ((term = udf.next()) != null) {
TermNature[] termNatures = term.getTermNatures().termNatures;
String wordType = termNatures[0].nature.natureStr;
String word = term.getName();
System.out.println(wordType + "->" + word);
}
}