zhouu 发表于 2016-12-17 06:16:56

IKAnalyzer分词测试DEMO,非Lucene,Solr整合。

  最近项目里要用到分词,将一个文章标题进行分词,存为TAG。然后利用这个TAG来寻找相关度的文章。想法挺不错的。那么开始动手吧。
  使用版本3.2.8 地址 http://code.google.com/p/ik-analyzer/downloads/list
  将IKAnalyzer3.2.8.jar放置在WEB-INF/lib下,配置文件IKAnalyzer.cfg.xml和ext_stopword.dic方在classpath下。
  写个测试类试试呗。

package com.cartoon.util;
import java.io.IOException;
import java.io.StringReader;
import org.wltea.analyzer.IKSegmentation;
import org.wltea.analyzer.Lexeme;
public class Test {
public static void main(String[] args) throws IOException {
String str = "火影忍者漫画";
StringReader reader = new StringReader(str);
IKSegmentation ik = new IKSegmentation(reader, true);// 当为true时,分词器进行最大词长切分
Lexeme lexeme = null;
while ((lexeme = ik.next()) != null){
System.out.println(lexeme.getLexemeText());
}
}
}

  打印结果:火影忍者                       漫画




看来词库还挺丰富的,速度非常快。以后分词就用IK了,简单好用。




就讲到这里了,顺便AD下,大家多多支持本人新站:礼品网
页: [1]
查看完整版本: IKAnalyzer分词测试DEMO,非Lucene,Solr整合。