zoukankan      html  css  js  c++  java
  • Elasticsearch中文分词

      分词插件:IK Analysis Plugin

      简介:

        IK Analyzer是一个开源的,基于java语言开发的轻量级的中文分词工具包。从2006年12月推出1.0版开始, IKAnalyzer已经推出了4个大版本。 最初,它是以开源项目Luence为应用主体的,结合词典分词和文法分析算法的中文分词组件。从3.0版本开始,IK发展为面向Java的公用分词组件,独立于Lucene项目, 同时提供了对Lucene的默认优化实现。在2012版本中,IK实现了简单的分词歧义排除算法,标志着IK分词器从单纯的词典分词向模拟语义分词衍化

      

      特性:

        ①:采用了特有的“正向迭代最细粒度切分算法“,支持细粒度和智能分词两种切分模式

        ②:在系统环境:Core2 i7 3.4G双核,4G内存,window 7 64位, Sun JDK 1.6_29 64位 普通pc环境测试,IK2012具有160万字/秒(3000KB/S)的高速处理能力

        ③:2012版本的智能分词模式支持简单的分词排歧义处理和数量词合并输出

        ④:采用了多子处理器分析模式,支持:英文字母、数字、中文词汇等分词处理,兼容韩文、日文字符

        ⑤:优化的词典存储,更小的内存占用。支持用户词典扩展定义。特别的,在2012版本,词典支持中文,英文,数字混合词语

      分词方式:

    Analyzer Introduction
    ik_smart

    会做最粗粒度的拆分,适合 Phrase 查询

    ik_max_word 会将文本做最细粒度的拆分,会穷尽各种可能的组合,适合 Term Query

      分词配置:

        配置文件:IKAnalyzer.cfg.xml can be located at {conf}/analysis-ik/config/IKAnalyzer.cfg.xml or {plugins}/elasticsearch-analysis-ik-*/config/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">custom/mydict.dic;custom/single_word_low_freq.dic</entry>
         <!--用户可以在这里配置自己的扩展停止词字典-->
        <entry key="ext_stopwords">custom/ext_stopword.dic</entry>
         <!--用户可以在这里配置远程扩展字典 -->
        <entry key="remote_ext_dict">location</entry>
         <!--用户可以在这里配置远程扩展停止词字典-->
        <entry key="remote_ext_stopwords">http://xxx.com/xxx.dic</entry>
    </properties>

        修改字典中的词条后,等待约1min,就会完成词库的热更新。

      分词效果:

        1、ik_smart

    GET _analyze
    {
      "text": ["结婚的和尚未结婚的"],
      "analyzer": "ik_smart"
    }

         result:

    {
      "tokens" : [
        {
          "token" : "结婚",
          "start_offset" : 0,
          "end_offset" : 2,
          "type" : "CN_WORD",
          "position" : 0
        },
        {
          "token" : "的",
          "start_offset" : 2,
          "end_offset" : 3,
          "type" : "CN_CHAR",
          "position" : 1
        },
        {
          "token" : "和尚",
          "start_offset" : 3,
          "end_offset" : 5,
          "type" : "CN_WORD",
          "position" : 2
        },
        {
          "token" : "未",
          "start_offset" : 5,
          "end_offset" : 6,
          "type" : "CN_CHAR",
          "position" : 3
        },
        {
          "token" : "结婚",
          "start_offset" : 6,
          "end_offset" : 8,
          "type" : "CN_WORD",
          "position" : 4
        },
        {
          "token" : "的",
          "start_offset" : 8,
          "end_offset" : 9,
          "type" : "CN_CHAR",
          "position" : 5
        }
      ]
    }

        2、ik_max_word

    GET _analyze
    {
      "text": ["结婚的和尚未结婚的"],
      "analyzer": "ik_max_word"
    }

        result:

    {
      "tokens" : [
        {
          "token" : "结婚",
          "start_offset" : 0,
          "end_offset" : 2,
          "type" : "CN_WORD",
          "position" : 0
        },
        {
          "token" : "的",
          "start_offset" : 2,
          "end_offset" : 3,
          "type" : "CN_CHAR",
          "position" : 1
        },
        {
          "token" : "和尚",
          "start_offset" : 3,
          "end_offset" : 5,
          "type" : "CN_WORD",
          "position" : 2
        },
        {
          "token" : "尚未",
          "start_offset" : 4,
          "end_offset" : 6,
          "type" : "CN_WORD",
          "position" : 3
        },
        {
          "token" : "未结",
          "start_offset" : 5,
          "end_offset" : 7,
          "type" : "CN_WORD",
          "position" : 4
        },
        {
          "token" : "结婚",
          "start_offset" : 6,
          "end_offset" : 8,
          "type" : "CN_WORD",
          "position" : 5
        },
        {
          "token" : "的",
          "start_offset" : 8,
          "end_offset" : 9,
          "type" : "CN_CHAR",
          "position" : 6
        }
      ]
    }

      

      更多IK Analysis Plugin介绍请访问: https://github.com/medcl/elasticsearch-analysis-ik

       下载:https://code.google.com/archive/p/ik-analyzer/

      

    END.

  • 相关阅读:
    codeforces C. Cows and Sequence 解题报告
    codeforces A. Point on Spiral 解题报告
    codeforces C. New Year Ratings Change 解题报告
    codeforces A. Fox and Box Accumulation 解题报告
    codeforces B. Multitasking 解题报告
    git命令使用
    shell简单使用
    知识束缚
    php 调用系统命令
    数据传输方式(前端与后台 ,后台与后台)
  • 原文地址:https://www.cnblogs.com/yangyongjie/p/15771973.html
Copyright © 2011-2022 走看看