如何安装elasticsearch中文切词插件hanlp
发表于:2025-11-13 作者:千家信息网编辑
千家信息网最后更新 2025年11月13日,这篇文章主要介绍如何安装elasticsearch中文切词插件hanlp,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!hanlp好处的,就是它的data字典比较齐全.githu
千家信息网最后更新 2025年11月13日如何安装elasticsearch中文切词插件hanlp
这篇文章主要介绍如何安装elasticsearch中文切词插件hanlp,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
hanlp好处的,就是它的data字典比较齐全.
github上有国人写hanlp支持es的插件
https://github.com/pengcong90/elasticsearch-analysis-hanlp
下载它的安装 release 包
下载发现解压按它的安装要求总找不到hanlp.properties文件
将源码git下来,发现路径有问题.
package org.elasticsearch.index.analysis;import com.hankcs.hanlp.HanLP;import com.hankcs.hanlp.utility.Predefine;import com.hankcs.lucene4.HanLPIndexAnalyzer;import org.elasticsearch.common.inject.Inject;import org.elasticsearch.common.inject.assistedinject.Assisted;import org.elasticsearch.common.settings.Settings;import org.elasticsearch.env.Environment;import org.elasticsearch.index.IndexSettings;/** */public class HanLPAnalyzerProvider extends AbstractIndexAnalyzerProvider{ private final HanLPIndexAnalyzer analyzer; private static String sysPath = String.valueOf(System.getProperties().get("user.dir")); @Inject public HanLPAnalyzerProvider(IndexSettings indexSettings, Environment env, @Assisted String name, @Assisted Settings settings) { super(indexSettings, name, settings); //原来路径 //Predefine.HANLP_PROPERTIES_PATH = sysPath.substring(0, sysPath.length()-4) + "/plugins/analysis-hanlp/hanlp.properties"; //修改后正确路径 Predefine.HANLP_PROPERTIES_PATH = sysPath + "/plugins/analysis-hanlp/hanlp.properties"; analyzer = new HanLPIndexAnalyzer(true); } public static HanLPAnalyzerProvider getIndexAnalyzerProvider(IndexSettings indexSettings, Environment env, String name, Settings settings) { return new HanLPAnalyzerProvider(indexSettings, env, name, settings); } public static HanLPAnalyzerProvider getSmartAnalyzerProvider(IndexSettings indexSettings, Environment env, String name, Settings settings) { return new HanLPAnalyzerProvider(indexSettings, env, name, settings); } @Override public HanLPIndexAnalyzer get() { return this.analyzer; }}
因为它的hanlp版本是1.2.8,最新版本是1.5.4
修改pom.xml为
com.hankcs hanlp portable-1.5.4
打包编译
在$ES_HOME下/plugins建立analysis-hanlp文件
目录下结构为
hanlp.properties属性(可以直接从 https://github.com/hankcs/HanLP 的realease下载修改root路径就行了)
#本配置文件中的路径的根目录,根目录+其他路径=完整路径(支持相对路径,请参考:https://github.com/hankcs/HanLP/pull/254)#Windows用户请注意,路径分隔符统一使用/root=/opt/elasticsearch-5.5.1/plugins/analysis-hanlp#核心词典路径CoreDictionaryPath=data/dictionary/CoreNatureDictionary.txt#2元语法词典路径BiGramDictionaryPath=data/dictionary/CoreNatureDictionary.ngram.txt#停用词词典路径CoreStopWordDictionaryPath=data/dictionary/stopwords.txt#同义词词典路径CoreSynonymDictionaryDictionaryPath=data/dictionary/synonym/CoreSynonym.txt#人名词典路径PersonDictionaryPath=data/dictionary/person/nr.txt#人名词典转移矩阵路径PersonDictionaryTrPath=data/dictionary/person/nr.tr.txt#繁简词典根目录tcDictionaryRoot=data/dictionary/tc#自定义词典路径,用;隔开多个自定义词典,空格开头表示在同一个目录,使用"文件名 词性"形式则表示这个词典的词性默认是该词性。优先级递减。#另外data/dictionary/custom/CustomDictionary.txt是个高质量的词库,请不要删除。所有词典统一使用UTF-8编码。CustomDictionaryPath=data/dictionary/custom/CustomDictionary.txt; 现代汉语补充词库.txt; 全国地名大全.txt ns; 人名词典.txt; 机构名词典.txt; 上海地名.txt ns;data/dictionary/person/nrf.txt nrf;#CRF分词模型路径CRFSegmentModelPath=data/model/segment/CRFSegmentModel.txt#HMM分词模型HMMSegmentModelPath=data/model/segment/HMMSegmentModel.bin#分词结果是否展示词性ShowTermNature=true#IO适配器,实现com.hankcs.hanlp.corpus.io.IIOAdapter接口以在不同的平台(Hadoop、Redis等)上运行HanLP#默认的IO适配器如下,该适配器是基于普通文件系统的。#IOAdapter=com.hankcs.hanlp.corpus.io.FileIOAdapter
plugin-descriptor.properties和plugin-security.policy属性按 elasticsearch-analysis-hanlp 的release包属性修改.
修改ES启动,并启动
vim /opt/elasticsearch-5.5.1config/jvm.options #新增-Djava.security.policy=/opt/elasticsearch-5.5.1/plugins/analysis-hanlp/plugin-security.policy
测试安装成功否命令
GET /_analyze?analyzer=hanlp-index&pretty=true { "text":"公安部:各地校车将享最高路权" }data字典文件从 https://github.com/hankcs/HanLP/releases 下载,解压就行了.
以上是"如何安装elasticsearch中文切词插件hanlp"这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注行业资讯频道!
路径
词典
文件
词性
插件
人名
属性
根目录
适配器
适配
中文
内容
地名
字典
模型
版本
目录
篇文章
词库
参考
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
药品MS数据库
数据库更新实验心得
海南管理软件开发中心
用户认证服务器 中标
安丘天气预报软件开发
八十年代服务器十大品牌
一图读懂国家网络安全宣传
中学网络安全主题班会心得
哈密小程序软件开发公司
中国中医案例数据库
日语专业软件开发
2000个人版数据库补丁
珠海商城软件开发联系方式
福州微创网络技术有限公司
sql查询数据库所有记录
厦门金融软件开发程序员工资
计算机软件开发技术专业考研
国外银行网络安全职位年薪
会软件开发可以在哪找项目
固定资产数据库卡片表
市总工会网络安全宣传周成效
app的服务器设置是什么意思
云南税务服务器云主机
服务器管理日记完整版
南京云呼叫中心软件开发公司
云服务器管理hc云计算
浪潮服务器怎么重做阵列
有关网络安全意识主题班队会
黑色沙漠数据库设置
长沙华中近帮互联网科技