安装elasticsearch中文切词插件hanlp
hanlp好处的,就是它的data字典比较齐全.
github上有国人写hanlp支持es的插件
https://github.com/pengcong90/elasticsearch-analysis-hanlp
1
下载它的安装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为
<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文件
目录下结构为
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 下载,解压就行了.
文章来源于小白鸽的博客
低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
阿里云10月多款“老产品”更新计费模式,速看免花冤枉钱
在刚过去的10月份,阿里云多款产品更新了计费模式,有些产品功能开始收费,有些产品功能则改外免费,接下来小编为各位看官详述一番。 MaxCompute 外表功能正式收费 从2018年10月31日开始,MaxCompute SQL外表功能开始计费。通过MaxCompute SQL外表功能直接处理OSS/TableStore(OTS)数据,从而处理音频、视频、图像、气象等非结构化数据以及K-V类型的数据。 外表功能采用的计费标准为一次SQL计算费用=计算输入数据量SQL复杂度SQL价格。SQL价格是0.03元/GB/复杂度 ,复杂度系数为1。当天的所有计量信息在第二天做一次性汇总收费,并直接体现在用户账户账单中。了解详情请戳:https://www.aliyun.com/product/odps?spm=5176.10695662.74765
- 下一篇
web开发安全框架中的Apache Shiro的应用
web开发安全框架中的Apache Shiro的应用前阶段就hadoop的分享了一些内容,希望对新手入门的朋友有点帮助吧!对于hadoop新手入门的,还是比较推荐大快搜索的DKHadoop发行版,三节点标准版还是值得拥有的(三节点的标准版是可以免费下载的,与付费版的目前功能一样,只是节点数量不同,对于新手而言三节点的够用了)。正在学习hadoop可以下载一下研究学习之用,也可以留言向我索要! 今天准备分享一下Apache Shiro 在web开发中的应用。shiro安全框架是目前为止作为登录注册最常用的框架,因为它十分的强大简单,提供了认证、授权、加密和会话管理等功能 。shiro能做什么?认证:验证用户的身份授权:对用户执行访问控制:判断用户是否被允许做某事会话管理:在任何环境下使用 Session API,即使没有 Web 或EJB 容器。加密:以更简洁易用的方式使用加密功能,保护或隐藏数据防止被偷窥Realms:聚集一个或多个用户安全数据的数据源单点登录(SSO)功能。为没有关联到登录的用户启用 "Remember Me“ 服务Shiro 的四大核心部分Authenticatio...
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- Docker使用Oracle官方镜像安装(12C,18C,19C)
- SpringBoot2编写第一个Controller,响应你的http请求并返回结果
- SpringBoot2整合Redis,开启缓存,提高访问速度
- CentOS7安装Docker,走上虚拟化容器引擎之路
- CentOS7编译安装Cmake3.16.3,解决mysql等软件编译问题
- CentOS关闭SELinux安全模块
- SpringBoot2全家桶,快速入门学习开发网站教程
- CentOS7编译安装Gcc9.2.0,解决mysql等软件编译问题
- CentOS8安装Docker,最新的服务器搭配容器使用
- CentOS7设置SWAP分区,小内存服务器的救世主