<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          IK分詞器詳解

          共 2659字,需瀏覽 6分鐘

           ·

          2021-01-17 22:21

          點(diǎn)擊上方藍(lán)色字體,選擇“置頂或者星標(biāo)”?

          優(yōu)質(zhì)文章第一時(shí)間送達(dá)!


          IK分詞器

          什么是 IK 分詞器

          分詞:即把一段中文或者別的劃分成一個(gè)個(gè)的關(guān)鍵字,我們?cè)谒阉鲿r(shí)候會(huì)把自己的信息進(jìn)行分詞,會(huì)把數(shù)據(jù)庫(kù)中或者索引庫(kù)中的數(shù)據(jù)進(jìn)行分詞,然后進(jìn)行一個(gè)匹配操作,默認(rèn)的中文分詞器是將每個(gè)字看成一個(gè)詞,比如"我愛技術(shù)"會(huì)被分為"我","愛","技","術(shù)",這顯然不符合要求,所以我們需要安裝中文分詞器IK來解決這個(gè)問題

          IK提供了兩個(gè)分詞算法:ik_smartik_max_word

          其中ik_smart為最少切分,ik_max_word為最細(xì)粒度劃分

          下載安裝

          下載不說直接安裝.記得版本相同,?公眾號(hào)內(nèi)回復(fù)電腦環(huán)境關(guān)鍵字可獲取我已經(jīng)下載好的.

          解壓縮后拷貝到ElasticSearchplugins文件夾下

          創(chuàng)建 ik 目錄

          重啟ES

          之前是沒有插件加載的

          可以清晰的看到加載了 analysis-ik

          也可以通過ES自帶的工具查看 命令行執(zhí)行 ElasticSearch-plugin list

          進(jìn)入Kibana測(cè)試

          先測(cè)試 ik_smart

          最少劃分

          GET?_analyze
          {
          ??"analyzer":?"ik_smart"
          ??,?"text":?"天津理工大學(xué)"
          }

          返回結(jié)果

          {
          ??"tokens"?:?[
          ????{
          ??????"token"?:?"天津",
          ??????"start_offset"?:?0,
          ??????"end_offset"?:?2,
          ??????"type"?:?"CN_WORD",
          ??????"position"?:?0
          ????},
          ????{
          ??????"token"?:?"理工大學(xué)",
          ??????"start_offset"?:?2,
          ??????"end_offset"?:?6,
          ??????"type"?:?"CN_WORD",
          ??????"position"?:?1
          ????}
          ??]
          }

          最細(xì)粒度劃分

          GET?_analyze
          {
          ??"analyzer":?"ik_max_word"
          ??,?"text":?"天津理工大學(xué)"
          }

          返回結(jié)果

          {
          ??"tokens"?:?[
          ????{
          ??????"token"?:?"天津",
          ??????"start_offset"?:?0,
          ??????"end_offset"?:?2,
          ??????"type"?:?"CN_WORD",
          ??????"position"?:?0
          ????},
          ????{
          ??????"token"?:?"理工大學(xué)",
          ??????"start_offset"?:?2,
          ??????"end_offset"?:?6,
          ??????"type"?:?"CN_WORD",
          ??????"position"?:?1
          ????},
          ????{
          ??????"token"?:?"理工大",
          ??????"start_offset"?:?2,
          ??????"end_offset"?:?5,
          ??????"type"?:?"CN_WORD",
          ??????"position"?:?2
          ????},
          ????{
          ??????"token"?:?"理工",
          ??????"start_offset"?:?2,
          ??????"end_offset"?:?4,
          ??????"type"?:?"CN_WORD",
          ??????"position"?:?3
          ????},
          ????{
          ??????"token"?:?"工大",
          ??????"start_offset"?:?3,
          ??????"end_offset"?:?5,
          ??????"type"?:?"CN_WORD",
          ??????"position"?:?4
          ????},
          ????{
          ??????"token"?:?"大學(xué)",
          ??????"start_offset"?:?4,
          ??????"end_offset"?:?6,
          ??????"type"?:?"CN_WORD",
          ??????"position"?:?5
          ????}
          ??]
          }

          若發(fā)現(xiàn)結(jié)果沒有區(qū)別, 而且他不認(rèn)為 查詢的詞 比如 鑫澤 是一個(gè)詞, 這就是一個(gè)問題,怎么辦呢?

          這種自己需要的詞,需要自己加到字典中

          IK分詞器增加自己的配置

          我們找到IK的配置文件, 位于ik/config/IKAnalyzer.cfg.xml

          IKAnalyzer.cfg.xml


          properties?SYSTEM?"http://java.sun.com/dtd/properties.dtd">
          <properties>
          ?<comment>IK?Analyzer?擴(kuò)展配置comment>
          ?
          ?<entry?key="ext_dict">entry>
          ??
          ?<entry?key="ext_stopwords">entry>
          ?
          ?
          ?
          ?
          properties>

          修改后的IKAnalyzer.cfg.xml


          properties?SYSTEM?"http://java.sun.com/dtd/properties.dtd">
          <properties>
          ?<comment>IK?Analyzer?擴(kuò)展配置comment>
          ?
          ?<entry?key="ext_dict">xinze.dicentry>
          ??
          ?<entry?key="ext_stopwords">entry>
          ?
          ?
          ?
          ?
          properties>

          xinze.dic

          鑫澤

          測(cè)試

          GET?_analyze
          {
          ??"analyzer":?"ik_smart"
          ??,?"text":?"超級(jí)喜歡鑫澤"
          }

          結(jié)果

          {
          ??"tokens"?:?[
          ????{
          ??????"token"?:?"超級(jí)",
          ??????"start_offset"?:?0,
          ??????"end_offset"?:?2,
          ??????"type"?:?"CN_WORD",
          ??????"position"?:?0
          ????},
          ????{
          ??????"token"?:?"喜歡",
          ??????"start_offset"?:?2,
          ??????"end_offset"?:?4,
          ??????"type"?:?"CN_WORD",
          ??????"position"?:?1
          ????},
          ????{
          ??????"token"?:?"鑫澤",
          ??????"start_offset"?:?4,
          ??????"end_offset"?:?6,
          ??????"type"?:?"CN_WORD",
          ??????"position"?:?2
          ????}
          ??]
          }

          文章已上傳gitee https://gitee.com/codingce/hexo-blog
          項(xiàng)目地址: https://github.com/xzMhehe/codingce-java


          更多推薦內(nèi)容

          ↓↓↓

          線性表概述

          線性表的順序存儲(chǔ)——順序表

          Redis配置文件詳解

          如果你喜歡本文

          請(qǐng)長(zhǎng)按二維碼,關(guān)注公眾號(hào)

          轉(zhuǎn)發(fā)朋友圈,是對(duì)我最大的支持喲

          以上,便是今天的分享,希望大家喜歡,覺得內(nèi)容不錯(cuò)的,歡迎「分享」「」或者點(diǎn)擊「在看」支持,謝謝各位。

          瀏覽 60
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  久久精品无码一区二区小草千夏 | 2018天天日天天操 | 苍井空最新一区二区三区电影 | 欧美性爱亚洲日韩 | 天堂视频在线 |