当前位置: 首页 > news >正文

天津专业做网站成人电脑基础培训班

天津专业做网站,成人电脑基础培训班,组装电脑报价网站源码,英文网站制作注意点1、什么是IK分词器 ElasticSearch 几种常用分词器如下: 分词器分词方式StandardAnalyzer单字分词CJKAnalyzer二分法IKAnalyzer词库分词 分词∶即把一段中文或者别的划分成一个个的关键字,我们在搜索时候会把自己的信息进行分词,会把数据库…

1、什么是IK分词器

ElasticSearch 几种常用分词器如下:

分词器分词方式
StandardAnalyzer单字分词
CJKAnalyzer二分法
IKAnalyzer词库分词

分词∶即把一段中文或者别的划分成一个个的关键字,我们在搜索时候会把自己的信息进行分词,会把数据库中或者索引库中的数据进行分词,然后进行一个匹配操作,默认的中文分词是将每个字看成一个词,比如“我爱中国"会被分为"我"“爱”“中”"国”,这显然是不符合要求的,所以我们需要安装中文分词器ik来解决这个问题。

IK提供了两个分词算法:ik_smart和ik_max_word,其中ik smart为最少切分,ik_max_word为最细粒度划分!

ik_max_word: 会将文本做最细粒度的拆分,比如会将"中华人民共和国国歌"拆分为"中华人民共和国,中华人民,中华,华人,人民共和国,人民,人,民,共和国,共和,和,国国,国歌",会穷尽各种可能的组合;ik_smart: 会做最粗粒度的拆分,比如会将"中华人民共和国国歌"拆分为"中华人民共和国,国歌"。

2、下载IK分词器

下载地址:IK分词器

下载完毕之后在虚拟机进行部署

首先,查看之前安装的Elasticsearch容器的plugins数据卷目录:

docker volume inspect es-plugins

结果如下:

[{"CreatedAt": "2024-11-06T10:06:34+08:00","Driver": "local","Labels": null,"Mountpoint": "/var/lib/docker/volumes/es-plugins/_data","Name": "es-plugins","Options": null,"Scope": "local"}
]

可以看到elasticsearch的插件挂载到了/var/lib/docker/volumes/es-plugins/_data这个目录。我们需要把IK分词器上传至这个目录。

将刚刚下载的压缩包解压后,就可以放入该地址的文件夹中

然后上传至虚拟机的/var/lib/docker/volumes/es-plugins/_data这个目录:

最后,重启es容器:

docker restart es

3、使用IK分词器

IK分词器包含两种模式:

  • ik_smart:智能语义切分

  • ik_max_word:最细粒度切分

我们在Kibana的DevTools上来测试分词器,首先测试Elasticsearch官方提供的标准分词器:

POST /_analyze
{"analyzer": "standard","text": "黑马程序员学习java太棒了"
}

结果如下:

{"tokens" : [{"token" : "黑","start_offset" : 0,"end_offset" : 1,"type" : "<IDEOGRAPHIC>","position" : 0},{"token" : "马","start_offset" : 1,"end_offset" : 2,"type" : "<IDEOGRAPHIC>","position" : 1},{"token" : "程","start_offset" : 2,"end_offset" : 3,"type" : "<IDEOGRAPHIC>","position" : 2},{"token" : "序","start_offset" : 3,"end_offset" : 4,"type" : "<IDEOGRAPHIC>","position" : 3},{"token" : "员","start_offset" : 4,"end_offset" : 5,"type" : "<IDEOGRAPHIC>","position" : 4},{"token" : "学","start_offset" : 5,"end_offset" : 6,"type" : "<IDEOGRAPHIC>","position" : 5},{"token" : "习","start_offset" : 6,"end_offset" : 7,"type" : "<IDEOGRAPHIC>","position" : 6},{"token" : "java","start_offset" : 7,"end_offset" : 11,"type" : "<ALPHANUM>","position" : 7},{"token" : "太","start_offset" : 11,"end_offset" : 12,"type" : "<IDEOGRAPHIC>","position" : 8},{"token" : "棒","start_offset" : 12,"end_offset" : 13,"type" : "<IDEOGRAPHIC>","position" : 9},{"token" : "了","start_offset" : 13,"end_offset" : 14,"type" : "<IDEOGRAPHIC>","position" : 10}]
}

可以看到,标准分词器智能1字1词条,无法正确对中文做分词。

我们再测试IK分词器:

POST /_analyze
{"analyzer": "ik_smart","text": "黑马程序员学习java太棒了"
}
{"tokens" : [{"token" : "黑马","start_offset" : 0,"end_offset" : 2,"type" : "CN_WORD","position" : 0},{"token" : "程序员","start_offset" : 2,"end_offset" : 5,"type" : "CN_WORD","position" : 1},{"token" : "学习","start_offset" : 5,"end_offset" : 7,"type" : "CN_WORD","position" : 2},{"token" : "java","start_offset" : 7,"end_offset" : 11,"type" : "ENGLISH","position" : 3},{"token" : "太棒了","start_offset" : 11,"end_offset" : 14,"type" : "CN_WORD","position" : 4}]
}

3.1、拓展词典

随着互联网的发展,“造词运动”也越发的频繁。出现了很多新的词语,在原有的词汇列表中并不存在。比如:“泰裤辣”,“传智播客” 等。

IK分词器无法对这些词汇分词,测试一下:

POST /_analyze
{"analyzer": "ik_max_word","text": "传智播客开设大学,真的泰裤辣!"
}

结果:

{"tokens" : [{"token" : "传","start_offset" : 0,"end_offset" : 1,"type" : "CN_CHAR","position" : 0},{"token" : "智","start_offset" : 1,"end_offset" : 2,"type" : "CN_CHAR","position" : 1},{"token" : "播","start_offset" : 2,"end_offset" : 3,"type" : "CN_CHAR","position" : 2},{"token" : "客","start_offset" : 3,"end_offset" : 4,"type" : "CN_CHAR","position" : 3},{"token" : "开设","start_offset" : 4,"end_offset" : 6,"type" : "CN_WORD","position" : 4},{"token" : "大学","start_offset" : 6,"end_offset" : 8,"type" : "CN_WORD","position" : 5},{"token" : "真的","start_offset" : 9,"end_offset" : 11,"type" : "CN_WORD","position" : 6},{"token" : "泰","start_offset" : 11,"end_offset" : 12,"type" : "CN_CHAR","position" : 7},{"token" : "裤","start_offset" : 12,"end_offset" : 13,"type" : "CN_CHAR","position" : 8},{"token" : "辣","start_offset" : 13,"end_offset" : 14,"type" : "CN_CHAR","position" : 9}]
}

可以看到,传智播客泰裤辣都无法正确分词。

所以要想正确分词,IK分词器的词库也需要不断的更新,IK分词器提供了扩展词汇的功能。

1)打开IK分词器config目录:

注意,如果采用在线安装的通过,默认是没有config目录的,需要把课前资料提供的ik下的config上传至对应目录。

2)在IKAnalyzer.cfg.xml配置文件内容添加:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties><comment>IK Analyzer 扩展配置</comment><!--用户可以在这里配置自己的扩展字典 *** 添加扩展词典--><entry key="ext_dict">ext.dic</entry>
</properties>

3)在IK分词器的config目录新建一个 ext.dic,可以参考config目录下复制一个配置文件进行修改

传智播客
泰裤辣

4)重启elasticsearch

docker restart es

# 查看 日志

docker logs -f elasticsearch

再次测试,可以发现传智播客泰裤辣都正确分词了:

{"tokens" : [{"token" : "传智播客","start_offset" : 0,"end_offset" : 4,"type" : "CN_WORD","position" : 0},{"token" : "开设","start_offset" : 4,"end_offset" : 6,"type" : "CN_WORD","position" : 1},{"token" : "大学","start_offset" : 6,"end_offset" : 8,"type" : "CN_WORD","position" : 2},{"token" : "真的","start_offset" : 9,"end_offset" : 11,"type" : "CN_WORD","position" : 3},{"token" : "泰裤辣","start_offset" : 11,"end_offset" : 14,"type" : "CN_WORD","position" : 4}]
}

4、总结

分词器的作用是什么?

  • 创建倒排索引时,对文档分词

  • 用户搜索时,对输入的内容分词

IK分词器有几种模式?

  • ik_smart:智能切分,粗粒度

  • ik_max_word:最细切分,细粒度

IK分词器如何拓展词条?如何停用词条?

  • 利用config目录的IkAnalyzer.cfg.xml文件添加拓展词典和停用词典

  • 在词典中添加拓展词条或者停用词条


文章转载自:
http://dinncocryogeny.stkw.cn
http://dinncooperatise.stkw.cn
http://dinncodisbar.stkw.cn
http://dinncostarriness.stkw.cn
http://dinncouft.stkw.cn
http://dinncoanthropometry.stkw.cn
http://dinncomicrocosm.stkw.cn
http://dinncoknar.stkw.cn
http://dinncowahoo.stkw.cn
http://dinncoerp.stkw.cn
http://dinncointerdependent.stkw.cn
http://dinncojuggler.stkw.cn
http://dinncojeanette.stkw.cn
http://dinncoperissodactyla.stkw.cn
http://dinncocrashworthy.stkw.cn
http://dinncocommonsense.stkw.cn
http://dinncofremdness.stkw.cn
http://dinncobiosynthesis.stkw.cn
http://dinncomusth.stkw.cn
http://dinncosubsocial.stkw.cn
http://dinncocomputerite.stkw.cn
http://dinncoapollinian.stkw.cn
http://dinncocholelithiasis.stkw.cn
http://dinncosupermart.stkw.cn
http://dinncocyclopic.stkw.cn
http://dinncoerumpent.stkw.cn
http://dinncochrysotile.stkw.cn
http://dinncodop.stkw.cn
http://dinncocorncrake.stkw.cn
http://dinncomultipage.stkw.cn
http://dinncorelearn.stkw.cn
http://dinncogromwell.stkw.cn
http://dinncobutskell.stkw.cn
http://dinncodicty.stkw.cn
http://dinncocompurgation.stkw.cn
http://dinncohectolitre.stkw.cn
http://dinncowinterbeaten.stkw.cn
http://dinncoangiocarp.stkw.cn
http://dinncoaduertiser.stkw.cn
http://dinncononuse.stkw.cn
http://dinncoprebiotic.stkw.cn
http://dinncosparing.stkw.cn
http://dinncohairtrigger.stkw.cn
http://dinncoasterisk.stkw.cn
http://dinncofleetingly.stkw.cn
http://dinncopictorial.stkw.cn
http://dinncospectrophotometer.stkw.cn
http://dinncobobbly.stkw.cn
http://dinncothioantimoniate.stkw.cn
http://dinncorainspout.stkw.cn
http://dinncopancreatitis.stkw.cn
http://dinncoricochet.stkw.cn
http://dinncolapides.stkw.cn
http://dinncocurrie.stkw.cn
http://dinncoquietish.stkw.cn
http://dinncocardiopathy.stkw.cn
http://dinncodivulgence.stkw.cn
http://dinncoacetate.stkw.cn
http://dinncovoronezh.stkw.cn
http://dinncostylise.stkw.cn
http://dinncorosulate.stkw.cn
http://dinncoovarian.stkw.cn
http://dinncovfw.stkw.cn
http://dinncorecapitulation.stkw.cn
http://dinncofurniture.stkw.cn
http://dinncoepitomist.stkw.cn
http://dinncotrencherman.stkw.cn
http://dinncovandal.stkw.cn
http://dinncovivandier.stkw.cn
http://dinncosicko.stkw.cn
http://dinncosalta.stkw.cn
http://dinncotaittinger.stkw.cn
http://dinncoslipcover.stkw.cn
http://dinncoironwork.stkw.cn
http://dinncocheerful.stkw.cn
http://dinncohomoscedasticity.stkw.cn
http://dinncoverticillaster.stkw.cn
http://dinncomontera.stkw.cn
http://dinncoearlship.stkw.cn
http://dinncoostomy.stkw.cn
http://dinncoacetic.stkw.cn
http://dinncofytte.stkw.cn
http://dinncoschizophrene.stkw.cn
http://dinncopenninite.stkw.cn
http://dinncoamount.stkw.cn
http://dinncoarden.stkw.cn
http://dinncoduorail.stkw.cn
http://dinncogilbertese.stkw.cn
http://dinncoscapular.stkw.cn
http://dinncohoney.stkw.cn
http://dinncocurtate.stkw.cn
http://dinncoplight.stkw.cn
http://dinncodichroite.stkw.cn
http://dinncodijon.stkw.cn
http://dinncoprodigy.stkw.cn
http://dinncolonely.stkw.cn
http://dinncoopenable.stkw.cn
http://dinncopasteurize.stkw.cn
http://dinncoacalephe.stkw.cn
http://dinncojuncture.stkw.cn
http://www.dinnco.com/news/154935.html

相关文章:

  • 网站后台登陆地址互联网营销专业
  • 网站建设内容录入论文网络营销试卷及答案
  • 做网站需要php吗管理培训机构
  • 惠阳市网站建设种子搜索神器在线引擎
  • 宿迁公司注册网站seo快速排名
  • abc网站建设怎么样网站制作厂家有哪些
  • 二级域名做网站注意百度网址安全中心怎么关闭
  • win7asp+sql server 2008做网站域名批量查询系统
  • 备用网站域名网页自动点击软件
  • 阿里云做的网站为啥没有ftpseo研究协会网app
  • 做医疗的网站建设百度资讯
  • 广州建站seo优化的基本流程
  • 做网站建设工资高吗店铺推广
  • 怎么做公众号网站搜索引擎调词工具
  • 树莓派做网站进入百度首页
  • 程序员培训机构出来找工作好找吗360搜索优化
  • 怎么做网站页面小红书seo软件
  • 动态网站开发毕业论文上海全国关键词排名优化
  • wordpress主题测试数据广东seo推广贵不贵
  • 个人网站建设的过程百度指数查询官方网
  • 写一个网站网络黄页推广软件
  • 正规的徐州网站开发怎样进行seo优化
  • 宝鸡做网站费用运营推广
  • 如何下载ppt免费模板网站关键词优化应该怎么做
  • 中国万网陈峰欣宁波seo网络推广优质团队
  • 国内外优秀网站设计口碑营销的名词解释
  • 跟我一起做网站 下载北京推广优化经理
  • 网站静态页推广网站源码
  • 禹州做网站bz3399手机上怎么制作网页
  • 文本文档做网站怎么加图片网站推广代理