导入jar包
IKAnalyzer2012_u6.jar下载链接:https://pan.xunlew.com/s86789
maven
<dependency> <groupId>com.janeluo</groupId> <artifactId>ikanalyzer</artifactId> <version>2012_u6</version> </dependency>
/** * * @param keyword 源词汇 * @param smart 是否智能分词 这里输入true * @return 分词词组(,拼接) */ public static String getKeywords(String keyword, boolean smart) { StringReader reader = new StringReader(keyword); IKSegmenter iks = new IKSegmenter(reader, smart); StringBuilder buffer = new StringBuilder(); try { Lexeme lexeme; while ((lexeme = iks.next()) != null) { buffer.append(lexeme.getLexemeText()).append(','); } } catch (IOException e) { } //去除最后一个, if (buffer.length() > 0) { buffer.setLength(buffer.length() - 1); } return buffer.toString(); }