美文网首页SpringBoot
SpringBoot整合IKAnalyzer中文分词

SpringBoot整合IKAnalyzer中文分词

作者: WebGiser | 来源:发表于2021-01-29 14:45 被阅读0次

参考:https://cloud.tencent.com/developer/article/1529953

项目结构

image.png

pom.xml引入IK分析器依赖

<dependency>
      <groupId>com.janeluo</groupId>
      <artifactId>ikanalyzer</artifactId>
      <version>2012_u6</version>
</dependency>

IK配置文件

IKAnalyzer.cfg.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
    <comment>IK Analyzer 扩展配置</comment>
    <!--用户可以在这里配置自己的扩展字典 -->
    <entry key="ext_dict">local.dic;</entry>
    <!--用户可以在这里配置自己的扩展停止词字典 -->
    <entry key="ext_stopwords">stop.dic;</entry>
</properties>

local.dic

慕课
慕课网

stop.dic

的
好
了
是

测试程序

package com.hello.demo;

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.wltea.analyzer.core.IKSegmenter;
import org.wltea.analyzer.core.Lexeme;

import java.io.IOException;
import java.io.StringReader;

@SpringBootTest
class IkApplicationTests {

    @Test
    void test() throws IOException {
        String text = "慕课网是一个网站,我在西安火车站和咸阳飞机场游玩";
        StringReader sr = new StringReader(text);
        IKSegmenter ik = new IKSegmenter(sr, true);
        Lexeme lex = null;
        while((lex = ik.next()) != null){
            System.out.println(lex.getLexemeText());
        }
    }
}
image.png

相关文章

网友评论

    本文标题:SpringBoot整合IKAnalyzer中文分词

    本文链接:https://www.haomeiwen.com/subject/umvqtltx.html