JAVA实现智能分词(通过文章标题生成tag标签)

 

导入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 源词汇
     * @return 分词词组(,拼接)
     */
    public static String getKeywords(String keyword) {
        if (StringUtils.isBlank(keyword)) {
            return null;
        }
        StringReader reader = new StringReader(keyword);
        IKSegmenter iks = new IKSegmenter(reader, true);
        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();
    }

 

posted @ 2020-01-03 17:51  yvioo  阅读(2301)  评论(0编辑  收藏  举报