安装IK分词器;IK分词器配置扩展词库:配置扩展字典-扩展词,配置扩展停止词字典-停用词

news2025/5/10 22:59:19

安装IK分词器;IK分词器配置扩展词库:配置扩展字典-扩展词,配置扩展停止词字典-停用词

  • 安装IK分词器
  • IK分词配置扩展词库
    • 配置扩展字典-扩展词
    • 配置停止词字典-停用词
    • 测试
      • 配置字典前
      • 配置字典后

本文 ElasticSearch 版本为:7.17.9,为了对应 spring-boot-starter-parent2.7.9 版本

安装IK分词器

官网资源:IK Analyzer GitHub 页面
在这里插入图片描述
IK分词器 下载地址:https://release.infinilabs.com/analysis-ik/stable/,下载与 ES 对应的 IK分词器 版本
在这里插入图片描述

然后解压下载的 zip 文件,不要直接解压到本文件夹下,里面直接就是所有文件,选择解压到 XXX 文件夹即可。
在这里插入图片描述
解压好的文件放在 ElasticSearch 目录下的 plugins 文件夹下重启 ES 即可使用(Windows和Linux同理)
在这里插入图片描述

IK分词配置扩展词库

IK分词器 不是 ElasticSearch 自带的分词器,需要用户自己全装。一般是安装在 ElasticSearchplugins 文件夹中的,要扩展 IK分词器 的词库,只需要修改 IK分词器 目录中的 config 目录中的 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"></entry>
	 <!--用户可以在这里配置自己的扩展停止词字典-->
	<entry key="ext_stopwords"></entry>
	<!--用户可以在这里配置远程扩展字典 -->
	<!-- <entry key="remote_ext_dict">words_location</entry> -->
	<!--用户可以在这里配置远程扩展停止词字典-->
	<!-- <entry key="remote_ext_stopwords">words_location</entry> -->
</properties>

需要我们指定自己的字典文件名去进行扩展,如:

<?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">dict.dic</entry>
	 <!--用户可以在这里配置自己的扩展停止词字典-->
	<entry key="ext_stopwords">stopwords.dic</entry>
	<!--用户可以在这里配置远程扩展字典 -->
	<!-- <entry key="remote_ext_dict">words_location</entry> -->
	<!--用户可以在这里配置远程扩展停止词字典-->
	<!-- <entry key="remote_ext_stopwords">words_location</entry> -->
</properties>

修改配置之后,这两个配置的文件也要去对应的新建,与 IKAnalyzer.cfg.xml 文件平级即可
在这里插入图片描述
配置好之后,重启 ElasticSearch 即可生效。

配置扩展字典-扩展词

新增 dict.dic 文件,配置如下:

搬砖
画大饼
已读不回
舔狗
摆烂

配置停止词字典-停用词

在已有的 stopword.dic 文件配置停用词,配置之后,这些词不会被解析出来:
在这里插入图片描述

测试

配置字典前

使用 ElasticSearch 的可视化界面 Kibana 的调试工具 Dev Tools 调用解析接口测试:

# `IK Analyzer` 扩展字典。
POST /_analyze
{
  "analyzer": "ik_smart",
  "text": "小明是一个Java程序员,白天摸鱼学习ElasticSearch,晚上加班到九点,搬砖完之后,去找他的女神画大饼,女神却已读不回,小明认清自己是个舔狗,直接摆烂,吸食海洛因"
}

解析结果:

#! Elasticsearch built-in security features are not enabled. Without authentication, your cluster could be accessible to anyone. See https://www.elastic.co/guide/en/elasticsearch/reference/7.17/security-minimal-setup.html to enable security.
{
  "tokens" : [
    {
      "token" : "小明",
      "start_offset" : 0,
      "end_offset" : 2,
      "type" : "CN_WORD",
      "position" : 0
    },
    {
      "token" : "是",
      "start_offset" : 2,
      "end_offset" : 3,
      "type" : "CN_CHAR",
      "position" : 1
    },
    {
      "token" : "一个",
      "start_offset" : 3,
      "end_offset" : 5,
      "type" : "CN_WORD",
      "position" : 2
    },
    {
      "token" : "java",
      "start_offset" : 5,
      "end_offset" : 9,
      "type" : "ENGLISH",
      "position" : 3
    },
    {
      "token" : "程序员",
      "start_offset" : 9,
      "end_offset" : 12,
      "type" : "CN_WORD",
      "position" : 4
    },
    {
      "token" : "白天",
      "start_offset" : 13,
      "end_offset" : 15,
      "type" : "CN_WORD",
      "position" : 5
    },
    {
      "token" : "摸鱼",
      "start_offset" : 15,
      "end_offset" : 17,
      "type" : "CN_WORD",
      "position" : 6
    },
    {
      "token" : "学习",
      "start_offset" : 17,
      "end_offset" : 19,
      "type" : "CN_WORD",
      "position" : 7
    },
    {
      "token" : "elasticsearch",
      "start_offset" : 19,
      "end_offset" : 32,
      "type" : "ENGLISH",
      "position" : 8
    },
    {
      "token" : "晚上",
      "start_offset" : 33,
      "end_offset" : 35,
      "type" : "CN_WORD",
      "position" : 9
    },
    {
      "token" : "加班",
      "start_offset" : 35,
      "end_offset" : 37,
      "type" : "CN_WORD",
      "position" : 10
    },
    {
      "token" : "到",
      "start_offset" : 37,
      "end_offset" : 38,
      "type" : "CN_CHAR",
      "position" : 11
    },
    {
      "token" : "九点",
      "start_offset" : 38,
      "end_offset" : 40,
      "type" : "TYPE_CQUAN",
      "position" : 12
    },
    {
      "token" : "搬",
      "start_offset" : 41,
      "end_offset" : 42,
      "type" : "CN_CHAR",
      "position" : 13
    },
    {
      "token" : "砖",
      "start_offset" : 42,
      "end_offset" : 43,
      "type" : "CN_CHAR",
      "position" : 14
    },
    {
      "token" : "完",
      "start_offset" : 43,
      "end_offset" : 44,
      "type" : "CN_CHAR",
      "position" : 15
    },
    {
      "token" : "之后",
      "start_offset" : 44,
      "end_offset" : 46,
      "type" : "CN_WORD",
      "position" : 16
    },
    {
      "token" : "去",
      "start_offset" : 47,
      "end_offset" : 48,
      "type" : "CN_CHAR",
      "position" : 17
    },
    {
      "token" : "找他",
      "start_offset" : 48,
      "end_offset" : 50,
      "type" : "CN_WORD",
      "position" : 18
    },
    {
      "token" : "的",
      "start_offset" : 50,
      "end_offset" : 51,
      "type" : "CN_CHAR",
      "position" : 19
    },
    {
      "token" : "女神",
      "start_offset" : 51,
      "end_offset" : 53,
      "type" : "CN_WORD",
      "position" : 20
    },
    {
      "token" : "画",
      "start_offset" : 53,
      "end_offset" : 54,
      "type" : "CN_CHAR",
      "position" : 21
    },
    {
      "token" : "大饼",
      "start_offset" : 54,
      "end_offset" : 56,
      "type" : "CN_WORD",
      "position" : 22
    },
    {
      "token" : "女神",
      "start_offset" : 57,
      "end_offset" : 59,
      "type" : "CN_WORD",
      "position" : 23
    },
    {
      "token" : "却已",
      "start_offset" : 59,
      "end_offset" : 61,
      "type" : "CN_WORD",
      "position" : 24
    },
    {
      "token" : "读",
      "start_offset" : 61,
      "end_offset" : 62,
      "type" : "CN_CHAR",
      "position" : 25
    },
    {
      "token" : "不回",
      "start_offset" : 62,
      "end_offset" : 64,
      "type" : "CN_WORD",
      "position" : 26
    },
    {
      "token" : "小明",
      "start_offset" : 65,
      "end_offset" : 67,
      "type" : "CN_WORD",
      "position" : 27
    },
    {
      "token" : "认清",
      "start_offset" : 67,
      "end_offset" : 69,
      "type" : "CN_WORD",
      "position" : 28
    },
    {
      "token" : "自己",
      "start_offset" : 69,
      "end_offset" : 71,
      "type" : "CN_WORD",
      "position" : 29
    },
    {
      "token" : "是",
      "start_offset" : 71,
      "end_offset" : 72,
      "type" : "CN_CHAR",
      "position" : 30
    },
    {
      "token" : "个",
      "start_offset" : 72,
      "end_offset" : 73,
      "type" : "CN_CHAR",
      "position" : 31
    },
    {
      "token" : "舔",
      "start_offset" : 73,
      "end_offset" : 74,
      "type" : "CN_CHAR",
      "position" : 32
    },
    {
      "token" : "狗",
      "start_offset" : 74,
      "end_offset" : 75,
      "type" : "CN_CHAR",
      "position" : 33
    },
    {
      "token" : "直接",
      "start_offset" : 76,
      "end_offset" : 78,
      "type" : "CN_WORD",
      "position" : 34
    },
    {
      "token" : "摆",
      "start_offset" : 78,
      "end_offset" : 79,
      "type" : "CN_CHAR",
      "position" : 35
    },
    {
      "token" : "烂",
      "start_offset" : 79,
      "end_offset" : 80,
      "type" : "CN_CHAR",
      "position" : 36
    },
    {
      "token" : "吸食",
      "start_offset" : 81,
      "end_offset" : 83,
      "type" : "CN_WORD",
      "position" : 37
    },
    {
      "token" : "海洛因",
      "start_offset" : 83,
      "end_offset" : 86,
      "type" : "CN_WORD",
      "position" : 38
    }
  ]
}

配置字典后

使用 ElasticSearch 的可视化界面 Kibana 的调试工具 Dev Tools 调用解析接口测试:

# `IK Analyzer` 扩展字典。
POST /_analyze
{
  "analyzer": "ik_smart",
  "text": "小明是一个Java程序员,白天摸鱼学习ElasticSearch,晚上加班到九点,搬砖完之后,去找他的女神画大饼,女神却已读不回,小明认清自己是个舔狗,直接摆烂,吸食海洛因"
}

解析结果:

#! Elasticsearch built-in security features are not enabled. Without authentication, your cluster could be accessible to anyone. See https://www.elastic.co/guide/en/elasticsearch/reference/7.17/security-minimal-setup.html to enable security.
{
  "tokens" : [
    {
      "token" : "小明",
      "start_offset" : 0,
      "end_offset" : 2,
      "type" : "CN_WORD",
      "position" : 0
    },
    {
      "token" : "是",
      "start_offset" : 2,
      "end_offset" : 3,
      "type" : "CN_CHAR",
      "position" : 1
    },
    {
      "token" : "一个",
      "start_offset" : 3,
      "end_offset" : 5,
      "type" : "CN_WORD",
      "position" : 2
    },
    {
      "token" : "java",
      "start_offset" : 5,
      "end_offset" : 9,
      "type" : "ENGLISH",
      "position" : 3
    },
    {
      "token" : "程序员",
      "start_offset" : 9,
      "end_offset" : 12,
      "type" : "CN_WORD",
      "position" : 4
    },
    {
      "token" : "白天",
      "start_offset" : 13,
      "end_offset" : 15,
      "type" : "CN_WORD",
      "position" : 5
    },
    {
      "token" : "摸鱼",
      "start_offset" : 15,
      "end_offset" : 17,
      "type" : "CN_WORD",
      "position" : 6
    },
    {
      "token" : "学习",
      "start_offset" : 17,
      "end_offset" : 19,
      "type" : "CN_WORD",
      "position" : 7
    },
    {
      "token" : "elasticsearch",
      "start_offset" : 19,
      "end_offset" : 32,
      "type" : "ENGLISH",
      "position" : 8
    },
    {
      "token" : "晚上",
      "start_offset" : 33,
      "end_offset" : 35,
      "type" : "CN_WORD",
      "position" : 9
    },
    {
      "token" : "加班",
      "start_offset" : 35,
      "end_offset" : 37,
      "type" : "CN_WORD",
      "position" : 10
    },
    {
      "token" : "到",
      "start_offset" : 37,
      "end_offset" : 38,
      "type" : "CN_CHAR",
      "position" : 11
    },
    {
      "token" : "九点",
      "start_offset" : 38,
      "end_offset" : 40,
      "type" : "TYPE_CQUAN",
      "position" : 12
    },
    {
      "token" : "搬砖",
      "start_offset" : 41,
      "end_offset" : 43,
      "type" : "CN_WORD",
      "position" : 13
    },
    {
      "token" : "完",
      "start_offset" : 43,
      "end_offset" : 44,
      "type" : "CN_CHAR",
      "position" : 14
    },
    {
      "token" : "之后",
      "start_offset" : 44,
      "end_offset" : 46,
      "type" : "CN_WORD",
      "position" : 15
    },
    {
      "token" : "去",
      "start_offset" : 47,
      "end_offset" : 48,
      "type" : "CN_CHAR",
      "position" : 16
    },
    {
      "token" : "找他",
      "start_offset" : 48,
      "end_offset" : 50,
      "type" : "CN_WORD",
      "position" : 17
    },
    {
      "token" : "女神",
      "start_offset" : 51,
      "end_offset" : 53,
      "type" : "CN_WORD",
      "position" : 18
    },
    {
      "token" : "画大饼",
      "start_offset" : 53,
      "end_offset" : 56,
      "type" : "CN_WORD",
      "position" : 19
    },
    {
      "token" : "女神",
      "start_offset" : 57,
      "end_offset" : 59,
      "type" : "CN_WORD",
      "position" : 20
    },
    {
      "token" : "却",
      "start_offset" : 59,
      "end_offset" : 60,
      "type" : "CN_CHAR",
      "position" : 21
    },
    {
      "token" : "已读不回",
      "start_offset" : 60,
      "end_offset" : 64,
      "type" : "CN_WORD",
      "position" : 22
    },
    {
      "token" : "小明",
      "start_offset" : 65,
      "end_offset" : 67,
      "type" : "CN_WORD",
      "position" : 23
    },
    {
      "token" : "认清",
      "start_offset" : 67,
      "end_offset" : 69,
      "type" : "CN_WORD",
      "position" : 24
    },
    {
      "token" : "自己",
      "start_offset" : 69,
      "end_offset" : 71,
      "type" : "CN_WORD",
      "position" : 25
    },
    {
      "token" : "是",
      "start_offset" : 71,
      "end_offset" : 72,
      "type" : "CN_CHAR",
      "position" : 26
    },
    {
      "token" : "个",
      "start_offset" : 72,
      "end_offset" : 73,
      "type" : "CN_CHAR",
      "position" : 27
    },
    {
      "token" : "舔狗",
      "start_offset" : 73,
      "end_offset" : 75,
      "type" : "CN_WORD",
      "position" : 28
    },
    {
      "token" : "直接",
      "start_offset" : 76,
      "end_offset" : 78,
      "type" : "CN_WORD",
      "position" : 29
    },
    {
      "token" : "摆烂",
      "start_offset" : 78,
      "end_offset" : 80,
      "type" : "CN_WORD",
      "position" : 30
    },
    {
      "token" : "吸食",
      "start_offset" : 81,
      "end_offset" : 83,
      "type" : "CN_WORD",
      "position" : 31
    }
  ]
}

可以看到网络热词 “搬砖”、“画大饼”、“已读不回”、“舔狗”、“摆烂” 均可以正确识别,敏感词 “海洛因” 没有解析。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2311404.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

pgsql行列转换

目录 一、造测试数据 二、行转列 1.函数定义 2.语法 3.示例 三、列转行 1.函数定义 2.语法 3.示例 一、造测试数据 create table test ( id int, json1 varchar, json2 varchar );insert into test values(1,111,{111}); insert into test values(2,111,222,{111,22…

Nginx 开启Baise认证

开启Baise认证 需要再站点Server配置中添加一下配置&#xff0c;添加htpasswd文件 server{auth_basic "HTTP Basic Authentication";auth_basic_user_file /etc/nginx/htpasswd;# 其他配置信息... }如果你的 Linux 服务器没有安装 htpasswd 工具&#xff0c;可以通…

基于python实现的疫情数据可视化分析系统

基于python实现的疫情数据可视化分析系统 开发语言:Python 数据库&#xff1a;MySQL所用到的知识&#xff1a;Django框架工具&#xff1a;pycharm、Navicat 系统功能实现 总体设计 系统实现 系统功能模块 系统首页可以查看首页、疫情信息、核酸检测、新闻资讯、个人中心、后…

计算机毕业设计SpringBoot+Vue.js陕西民俗网(源码+文档+PPT+讲解)

温馨提示&#xff1a;文末有 CSDN 平台官方提供的学长联系方式的名片&#xff01; 温馨提示&#xff1a;文末有 CSDN 平台官方提供的学长联系方式的名片&#xff01; 温馨提示&#xff1a;文末有 CSDN 平台官方提供的学长联系方式的名片&#xff01; 作者简介&#xff1a;Java领…

Win7重装不翻车!ISO镜像安全下载渠道+BIOS设置避雷手册

一、写在前面&#xff1a;为什么你需要这份教程&#xff1f; 当电脑频繁蓝屏、系统崩溃甚至无法开机时&#xff0c;重装系统可能是最后的救命稻草。但市面上的教程往往存在三大痛点&#xff1a; ⚠️ 镜像来源不明导致系统被植入后门 ⚠️ 启动盘制作失败反复折腾 ⚠️ 操作失…

[项目]基于FreeRTOS的STM32四轴飞行器: 四.LED控制

基于FreeRTOS的STM32四轴飞行器: 四.LED控制 一.配置Com层二.编写驱动 一.配置Com层 先在Com_Config.h中定义灯位置的枚举类型&#xff1a; 之后定义Led的结构体&#xff1a; 定义飞行器状态&#xff1a; 在Com_Config.c中初始化四个灯&#xff1a; 在Com_Config.h外部声明…

计算机毕业设计SpringBoot+Vue.js青年公寓服务平台(源码+文档+PPT+讲解)

温馨提示&#xff1a;文末有 CSDN 平台官方提供的学长联系方式的名片&#xff01; 温馨提示&#xff1a;文末有 CSDN 平台官方提供的学长联系方式的名片&#xff01; 温馨提示&#xff1a;文末有 CSDN 平台官方提供的学长联系方式的名片&#xff01; 作者简介&#xff1a;Java领…

VScode 中文符号出现黄色方框的解决方法

VScode 中文符号出现黄色方框的解决方法 我的vscode的python多行注释中会将中文字符用黄色方框框处&#xff1a; 只需要打开设置搜索unicode&#xff0c;然后将这一项的勾选取消掉就可以了&#xff1a; 取消之后的效果如下&#xff1a; 另一种情况&#xff1a;中文显示出现黄色…

JCRQ1河马算法+四模型对比!HO-CNN-GRU-Attention系列四模型多变量时序预测

JCRQ1河马算法四模型对比&#xff01;HO-CNN-GRU-Attention系列四模型多变量时序预测 目录 JCRQ1河马算法四模型对比&#xff01;HO-CNN-GRU-Attention系列四模型多变量时序预测预测效果基本介绍程序设计参考资料 预测效果 基本介绍 基于HO-CNN-GRU-Attention、CNN-GRU-Attent…

探索低空经济,无人机及载人直升机低空应用技术详解

探索低空经济时&#xff0c;无人机及载人直升机低空应用技术是核心要素。以下是对这两类技术的详细解析&#xff1a; 一、无人机低空应用技术 1. 飞行控制技术 无人机需要强大的飞行控制系统&#xff0c;这涉及传感器融合、飞行器稳定性控制、自动化飞行和紧急情况下的自动避…

GStreamer —— 2.3、Windows下Qt加载GStreamer库后运行 - “教程3:动态管道“(附:完整源码)

运行效果&#xff08;音频&#xff09; 简介 上一个教程演示了GStreamer 概念。本教程中的管在它设置为 playing 状态之前完全构建。这没关系。如果 我们没有采取进一步的行动&#xff0c;数据会到达 pipeline 的 pipeline 和 pipeline 将生成错误消息并停止。但 我们将采取进一…

【Java数据结构】前K个高频单词

前K个高频单词 692. 前K个高频单词 - 力扣&#xff08;LeetCode&#xff09; 解决这个问题我们先得知道每个单词出现的次数&#xff0c;用map存储下来&#xff0c;然后将出现次数最多的通过建立小根堆解决top-K问题 &#xff0c;重点是top-K的求取。 1.建立map 首先我们可以…

Ubuntu20.04本地配置IsaacLab 4.5.0的训练环境(一)

Ubuntu20.04本地配置IsaacLab 4.5.0的训练环境&#xff08;一&#xff09; 配置conda虚拟环境&#xff08;对于这一步&#xff0c;个人感觉跟在配置IsaacLab那一节的./isaaclab.sh --install同样要执行这一步&#xff0c;建议先不执行&#xff09;配置IsaacSim配置IsaacLab 写在…

第二次CCF-CSP认证(含C++源码)

第二次CCF-CSP认证 第一道&#xff08;easy&#xff09;思路及AC代码 第二道&#xff08;easy&#xff09;基本思路及AC代码 第三道&#xff08;mid&#xff09;基本思路及AC代码solution 1 (模拟)solution 2&#xff08;KMP&#xff09; 第一道&#xff08;easy&#xff09; 题…

【项目】视频点播

一、项目介绍 1. 对视频点播系统的认识 搭建视频共享点播服务器&#xff0c;可以让所有人通过浏览器访问服务器&#xff0c;实现视频的上传查看&#xff0c;以及管理并播放的功能。主要是完成服务器端的程序业务功能的实现以及前端访问界面 html 的编写&#xff0c;能够支持客…

vue videojs使用canvas截取视频画面

前言 刚开始做的时候太多坑&#xff0c;导致一直报错&#xff1a; Uncaught (in promise) TypeError: Failed to execute ‘drawImage’ on ‘CanvasRenderingContext2D’: The provided value is not of type ‘(CSSImageValue or HTMLCanvasElement or HTMLImageElement or H…

uniapp+微信小程序+地图+传入多个标记点显示+点击打开内置地图导航+完整代码

一、效果展示 二、完整代码 <template><view class"container"><map class"map-container" :latitude"latitude" :longitude"longitude" :markers"markers" :controls"controls" show-location m…

摄像头应用编程(四):ARM Linux LCD实时预览UVC摄像头画面

文章目录 1、前言2、环境介绍3、步骤4、应用程序编写4.1、lcd初始化4.2、摄像头初始化4.3、jpeg解码4.4、开启摄像头4.5、完整的程序如下 5、测试5.1、编译应用程序5.2、运行应用程序 6、总结 1、前言 本次应用程序主要针对支持MJPEG格式输出的UVC摄像头。 2、环境介绍 rk35…

Linux下的c进程和java进程的通信-UnixSocket

1、开发c代码 引用的库 /usr/include c代码 #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/socket.h> #include <sys/un.h> #include <unistd.h>#define SOCKET_PATH "/tmp/my_socket"int mai…

音视频入门基础:RTP专题(15)——FFmpeg源码中,获取RTP的视频信息的实现

一、引言 通过FFmpeg命令可以获取到SDP文件描述的RTP流的视频压缩编码格式、色彩格式&#xff08;像素格式&#xff09;、分辨率、帧率信息&#xff1a; ffmpeg -protocol_whitelist "file,rtp,udp" -i XXX.sdp 本文以H.264为例讲述FFmpeg到底是从哪个地方获取到这…