iis服务器助手广告广告
返回顶部
首页 > 资讯 > 数据库 >如何安装elasticsearch中文切词插件hanlp
  • 224
分享到

如何安装elasticsearch中文切词插件hanlp

2024-04-02 19:04:59 224人浏览 泡泡鱼
摘要

这篇文章主要介绍如何安装elasticsearch中文切词插件haNLP,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!hanlp好处的,就是它的data字典比较齐全.GitHub上有

这篇文章主要介绍如何安装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<HanLPIndexAnalyzer> {
    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为

       <dependency>
                <groupId>com.hankcs</groupId>
                <artifactId>hanlp</artifactId>
                <version>portable-1.5.4</version>
            <!--<systemPath>${pom.basedir}/lib/hanlp-1.2.8.jar</systemPath>-->
            <!--<scope>system</scope>-->
        </dependency>

打包编译

在$ES_HOME下/plugins建立analysis-hanlp文件 
目录下结构为 
如何安装elasticsearch中文切词插件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接口以在不同的平台(hadoopRedis等)上运行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”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注编程网数据库频道!

您可能感兴趣的文档:

--结束END--

本文标题: 如何安装elasticsearch中文切词插件hanlp

本文链接: https://www.lsjlt.com/news/65124.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • oracle怎么查询当前用户所有的表
    要查询当前用户拥有的所有表,可以使用以下 sql 命令:select * from user_tables; 如何查询当前用户拥有的所有表 要查询当前用户拥有的所有表,可以使...
    99+
    2024-05-14
    oracle
  • oracle怎么备份表中数据
    oracle 表数据备份的方法包括:导出数据 (exp):将表数据导出到外部文件。导入数据 (imp):将导出文件中的数据导入表中。用户管理的备份 (umr):允许用户控制备份和恢复过程...
    99+
    2024-05-14
    oracle
  • oracle怎么做到数据实时备份
    oracle 实时备份通过持续保持数据库和事务日志的副本来实现数据保护,提供快速恢复。实现机制主要包括归档重做日志和 asm 卷管理系统。它最小化数据丢失、加快恢复时间、消除手动备份任务...
    99+
    2024-05-14
    oracle 数据丢失
  • oracle怎么查询所有的表空间
    要查询 oracle 中的所有表空间,可以使用 sql 语句 "select tablespace_name from dba_tablespaces",其中 dba_tabl...
    99+
    2024-05-14
    oracle
  • oracle怎么创建新用户并赋予权限设置
    答案:要创建 oracle 新用户,请执行以下步骤:以具有 create user 权限的用户身份登录;在 sql*plus 窗口中输入 create user identified ...
    99+
    2024-05-14
    oracle
  • oracle怎么建立新用户
    在 oracle 数据库中创建用户的方法:使用 sql*plus 连接数据库;使用 create user 语法创建新用户;根据用户需要授予权限;注销并重新登录以使更改生效。 如何在 ...
    99+
    2024-05-14
    oracle
  • oracle怎么创建新用户并赋予权限密码
    本教程详细介绍了如何使用 oracle 创建一个新用户并授予其权限:创建新用户并设置密码。授予对特定表的读写权限。授予创建序列的权限。根据需要授予其他权限。 如何使用 Oracle 创...
    99+
    2024-05-14
    oracle
  • oracle怎么查询时间段内的数据记录表
    在 oracle 数据库中查询指定时间段内的数据记录表,可以使用 between 操作符,用于比较日期或时间的范围。语法:select * from table_name wh...
    99+
    2024-05-14
    oracle
  • oracle怎么查看表的分区
    问题:如何查看 oracle 表的分区?步骤:查询数据字典视图 all_tab_partitions,指定表名。结果显示分区名称、上边界值和下边界值。 如何查看 Oracle 表的分区...
    99+
    2024-05-14
    oracle
  • oracle怎么导入dump文件
    要导入 dump 文件,请先停止 oracle 服务,然后使用 impdp 命令。步骤包括:停止 oracle 数据库服务。导航到 oracle 数据泵工具目录。使用 impdp 命令导...
    99+
    2024-05-14
    oracle
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作