博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
使用HanLP增强Elasticsearch分词功能
阅读量:6886 次
发布时间:2019-06-27

本文共 2842 字,大约阅读时间需要 9 分钟。

hot3.png

hanlp-ext 插件源码地址:http://git.oschina.net/hualongdata/hanlp-exthttps://github.com/hualongdata/hanlp-ext

Elasticsearch 默认对中文分词是按“字”进行分词的,这是肯定不能达到我们进行分词搜索的要求的。官方有一个 SmartCN 中文分词插件,另外还有一个 IK 分词插件使用也比较广。但这里,我们采用 HanLP 这款 自然语言处理工具 来进行中文分词。

Elasticsearch

Elasticsearch 的默认分词效果是惨不忍睹的。

GET /_analyze?pretty    {      "text" : ["重庆华龙网海数科技有限公司"]    }

输出:

{  "tokens": [    {      "token": "重",      "start_offset": 0,      "end_offset": 1,      "type": "
", "position": 0 }, { "token": "庆", "start_offset": 1, "end_offset": 2, "type": "
", "position": 1 }, { "token": "华", "start_offset": 2, "end_offset": 3, "type": "
", "position": 2 }, { "token": "龙", "start_offset": 3, "end_offset": 4, "type": "
", "position": 3 }, { "token": "网", "start_offset": 4, "end_offset": 5, "type": "
", "position": 4 }, { "token": "海", "start_offset": 5, "end_offset": 6, "type": "
", "position": 5 }, { "token": "数", "start_offset": 6, "end_offset": 7, "type": "
", "position": 6 }, { "token": "科", "start_offset": 7, "end_offset": 8, "type": "
", "position": 7 }, { "token": "技", "start_offset": 8, "end_offset": 9, "type": "
", "position": 8 }, { "token": "有", "start_offset": 9, "end_offset": 10, "type": "
", "position": 9 }, { "token": "限", "start_offset": 10, "end_offset": 11, "type": "
", "position": 10 }, { "token": "公", "start_offset": 11, "end_offset": 12, "type": "
", "position": 11 }, { "token": "司", "start_offset": 12, "end_offset": 13, "type": "
", "position": 12 } ]}

可以看到,默认是按字进行分词的。

elasticsearch-hanlp

HanLP

是一款使用 Java 实现的优秀的,具有如下功能:

  • 中文分词
  • 词性标注
  • 命名实体识别
  • 关键词提取
  • 自动摘要
  • 短语提取
  • 拼音转换
  • 简繁转换
  • 文本推荐
  • 依存句法分析
  • 语料库工具

安装 elasticsearch-hanlp(安装见:https://github.com/hualongdata/hanlp-ext/tree/master/es-plugin)插件以后,我们再来看看分词效果。

GET /_analyze?pretty    {      "analyzer" : "hanlp",      "text" : ["重庆华龙网海数科技有限公司"]    }

输出:

{  "tokens": [    {      "token": "重庆",      "start_offset": 0,      "end_offset": 2,      "type": "ns",      "position": 0    },    {      "token": "华龙网",      "start_offset": 2,      "end_offset": 5,      "type": "nr",      "position": 1    },    {      "token": "海数",      "start_offset": 5,      "end_offset": 7,      "type": "nr",      "position": 2    },    {      "token": "科技",      "start_offset": 7,      "end_offset": 9,      "type": "n",      "position": 3    },    {      "token": "有限公司",      "start_offset": 9,      "end_offset": 13,      "type": "nis",      "position": 4    }  ]}

HanLP 的功能不止简单的中文分词,有很多功能都可以集成到 Elasticsearch 中。

心动不如行动:http://git.oschina.net/hualongdata/hanlp-exthttps://github.com/hualongdata/hanlp-ext

转载于:https://my.oschina.net/yangbajing/blog/877984

你可能感兴趣的文章
【MySQL】5.7新特性之五
查看>>
一个清理和查询都要兼顾的简单方案
查看>>
归档日志路径三个参数DB_RECOVERY_FILE_DEST和LOG_ARCHIVE_DEST和LOG_ARCHIVE_DEST_n
查看>>
【Xamarin挖墙脚系列:Xamarin.Android的API设计准则】
查看>>
JProgressBar的一个框架
查看>>
HDOJ/HDU 1062 Text Reverse(字符串翻转~)
查看>>
基于Macaca的混合H5应用UI自动化入门
查看>>
[转]scite文本编辑器的说明
查看>>
阿里云ECS CentOs7.3下搭建LAMP环境(Apache2.4 + Mysql5.7 + PHP5.6 + Laravel5.2)
查看>>
axure rp
查看>>
MySQL---数据库从入门走向大神系列(七)-Java访问数据库配置及简单使用方法execute...
查看>>
【框架】[Spring]纯Java方式实现AOP拦截-详解ThrowsAdvice异常通知
查看>>
微信小程序把玩(八)view组件
查看>>
一分钟发现一个引力透镜,天文学家使用神经网络探索宇宙
查看>>
微信,是怎么过来的(2010-2015)
查看>>
NGINX 添加MP4、FLV视频支持模块
查看>>
Apache Flink fault tolerance源码剖析(二)
查看>>
C#实现字符串按多个字符采用Split方法分割
查看>>
Linux学习-->如何通过Shell脚本实现发送邮件通知功能?
查看>>
python 类
查看>>