elasticsearch 中文分词(elasticsearch-analysis-hanlp)


elasticsearch 中文分词(elasticsearch-analysis-hanlp)

官网:https://github.com/KennFalcon/elasticsearch-analysis-hanlp

*****************************

安装hanlp插件

进入容器,在线安装

./bin/elasticsearch-plugin install https://github.com/KennFalcon/elasticsearch-analysis-hanlp/releases/download/v7.5.1/elasticsearch-analysis-hanlp-7.5.1.zip

查看安装的插件

        

重启elasticsearch使hanlp生效

*****************************

测试hanlp分词

***********************

hanlp分词方式

hanlp: hanlp默认分词

hanlp_standard: 标准分词

hanlp_index: 索引分词

hanlp_nlp: NLP分词

hanlp_n_short: N-最短路分词

hanlp_dijkstra: 最短路分词

hanlp_crf: CRF分词(已有最新方式)

hanlp_speed: 极速词典分词

***********************

测试分词

未使用hanlp分词:将所有中文分割成单个字

       

使用hanlp分词

      

 

*****************************

添加本地自定义词库

在目录/usr/share/elasticsearch/plugins/analysis-hanlp/data/dictionary/custom中新增自定义词典:hotword.txt

我要当海贼王

修改配置文件hanlp.properties,在配置选项CustomDictionaryPath后添加hotword.txt

CustomDictionaryPath=data/dictionary/custom/CustomDictionary.txt; ModernChineseSupplementaryWord.txt;hotword.txt;ChinesePlaceName.txt ns; PersonalName.txt; OrganizationName.txt; ShanghaiPlaceName.txt ns;data/dictionary/person/nrf.txt nrf;

重启elasticsearch,使修改的配置生效

***********************

使用测试

未添加本地词库

         

添加本地词库

         

*****************************

添加远程词库

**********************

相关操作

创建远程应用,用docker创建容器

                      

修改远程配置文件:hanlp-remote.xml,重启elasticsearch

       

***********************

使用测试

未添加远程词库

        

添加远程词库

       

发布了320 篇原创文章 · 获赞 91 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/weixin_43931625/article/details/103979205