04-IK中文分词器

1 环境准备

IK分词器下载地址: https://github.com/medcl/elasticsearch-analysis-ik/releases
在这里插入图片描述
注:IK分词器版本一定要和Elasticsearch服务版本号一致,否则服务启动不了

2 将插件拷贝到Elasticsearch的plugins目录

在这里插入图片描述
注:在plugins目录下新建ik插件目录,将插件内容拷贝到此文件夹下。并且在拷贝之前先停掉Elasticsearch服务。

3 重启elasticsearch服务

在这里插入图片描述
注:发现ik中文分词插件被加载。可在elasticsearch的安装目录下bin目录中,通过命令来查看加载的插件
在这里插入图片描述
注:命令”elasticsearch-plugin list“查看加载的插件列表。

4 使用kibana测试分词插件

IK分词器提供两种分词算法:ik_smart(最小切分)ik_max_word(最细粒度划分)
在这里插入图片描述

4.1 ik_smart(最小切分)

//请求
GET _analyze
{
  "analyzer": "ik_smart",
  "text": "中国共产党"
}

//响应结果
{
  "tokens" : [
    {
      "token" : "中国共产党",
      "start_offset" : 0,
      "end_offset" : 5,
      "type" : "CN_WORD",
      "position" : 0
    }
  ]
}

注:可以发现只分了一个词。start_offset(起始下标)、end_offset(结束下标)

4.2 ik_max_word(最细粒度划分)

//请求
GET _analyze
{
  "analyzer": "ik_max_word",
  "text": "中国共产党"
}

//响应结果
{
  "tokens" : [
    {
      "token" : "中国共产党",
      "start_offset" : 0,
      "end_offset" : 5,
      "type" : "CN_WORD",
      "position" : 0
    },
    {
      "token" : "中国",
      "start_offset" : 0,
      "end_offset" : 2,
      "type" : "CN_WORD",
      "position" : 1
    },
    {
      "token" : "国共",
      "start_offset" : 1,
      "end_offset" : 3,
      "type" : "CN_WORD",
      "position" : 2
    },
    {
      "token" : "共产党",
      "start_offset" : 2,
      "end_offset" : 5,
      "type" : "CN_WORD",
      "position" : 3
    },
    {
      "token" : "共产",
      "start_offset" : 2,
      "end_offset" : 4,
      "type" : "CN_WORD",
      "position" : 4
    },
    {
      "token" : "党",
      "start_offset" : 4,
      "end_offset" : 5,
      "type" : "CN_CHAR",
      "position" : 5
    }
  ]
}

注:此分词器会分成6个词,会将词分成最细的组合。

5 IK分词器扩展自己的词库

配置自己的词库
在这里插入图片描述
注:在ik分词器插件的config目录下的IKAnalyzer.cfg.xml文件中配置自己需要的词库字典。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值