溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

如何使用HanLP增強Elasticsearch分詞功能

發布時間:2021-12-16 11:53:11 來源:億速云 閱讀:450 作者:小新 欄目:開發技術

這篇文章主要介紹如何使用HanLP增強Elasticsearch分詞功能,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!

Elasticsearch 默認對中文分詞是按“字”進行分詞的,這是肯定不能達到我們進行分詞搜索的要求的。官方有一個 SmartCN 中文分詞插件,另外還有一個 IK 分詞插件使用也比較廣。但這里,我們采用 HanLP 這款 自然語言處理工具 來進行中文分詞。

Elasticsearch

Elasticsearch 的默認分詞效果是慘不忍睹的。

    GET /_analyze?pretty
    {      "text" : ["廣州億速云計算科技有限公司"]
    }

輸出:

{  "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": "科",      "start_offset": 7,      "end_offset": 8,      "type": "<IDEOGRAPHIC>",      "position": 7
    },
    {      "token": "技",      "start_offset": 8,      "end_offset": 9,      "type": "<IDEOGRAPHIC>",      "position": 8
    },
    {      "token": "有",      "start_offset": 9,      "end_offset": 10,      "type": "<IDEOGRAPHIC>",      "position": 9
    },
    {      "token": "限",      "start_offset": 10,      "end_offset": 11,      "type": "<IDEOGRAPHIC>",      "position": 10
    },
    {      "token": "公",      "start_offset": 11,      "end_offset": 12,      "type": "<IDEOGRAPHIC>",      "position": 11
    },
    {      "token": "司",      "start_offset": 12,      "end_offset": 13,      "type": "<IDEOGRAPHIC>",      "position": 12
    }
  ]
}

可以看到,默認是按字進行分詞的。

elasticsearch-hanlp

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分詞功能”這篇文章的所有內容,感謝各位的閱讀!希望分享的內容對大家有幫助,更多相關知識,歡迎關注億速云行業資訊頻道!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女