<dependency>
<groupId>com.janeluo</groupId>
<artifactId>ikanalyzer</artifactId>
<version>2012_u6</version>
</dependency>
public class KeywordUtil {
public static List<String> analyze(String text){
ArrayList<String> result = new ArrayList<>();
StringReader stringReader = new StringReader(text);
IKSegmenter ikSegmenter = new IKSegmenter(stringReader, true);
Lexeme next = null;
try {
while ( (next= ikSegmenter.next())!=null){
String word= next.getLexemeText();
result.add(word);
}
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
public static void main(String[] args) {
System.out.println(analyze("分词器在以后用上的时候在写文章进行详细介绍"));
}
}
输出结果
[分词器, 在, 以后, 用上, 的, 时候, 在, 写文章, 进行, 详细, 介绍]
IK分词器测试代码
最新推荐文章于 2024-07-15 10:07:05 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)