zoukankan      html  css  js  c++  java
  • solr集成mmseg4j分词

    到了分词这部,相信你已经把solr整合到tomcat里了,没有的话看我前面的文章有讲到。

    我这里使用的是mmseg4j-1.9.1版本的。

    http://down.51cto.com/data/1275975这个是下载zip的链接。

    解压后把mmseg4j-1.9.1 文件夹下dist下的三个jar包拷贝到tomcat/webapps/solr/WEB-INF/lib下。

    在schema.xml下配置分词器。

        <types>
        <fieldtype name="string"  class="solr.StrField" sortMissingLast="true" omitNorms="true"/>
        <fieldType name="long" class="solr.TrieLongField" precisionStep="0" positionIncrementGap="0"/>
        <fieldType name="int" class="solr.TrieIntField" precisionStep="0" positionIncrementGap="0"/>
        <fieldType name="textComplex" class="solr.TextField" >
          <analyzer>
            <tokenizer class="com.chenlb.mmseg4j.solr.MMSegTokenizerFactory" mode="complex" />
          </analyzer>
        </fieldType>
        <fieldType name="textMaxWord" class="solr.TextField" >
          <analyzer>
            <tokenizer class="com.chenlb.mmseg4j.solr.MMSegTokenizerFactory" mode="max-word" />
          </analyzer>
        </fieldType>
        <fieldType name="textSimple" class="solr.TextField" >
          <analyzer>
            <tokenizer class="com.chenlb.mmseg4j.solr.MMSegTokenizerFactory" mode="simple" />
          </analyzer>
        </fieldType>
        </types>
      <fields>
          <field name="id"   type="int"    indexed="true"  stored="true"  />
          <field name="gender"  type="string"    indexed="true"  stored="true"   /> 
          <field name="name"      type="textComplex"    indexed="true"  stored="true"   /> 
          <field name="major"     type="textComplex"    indexed="true"  stored="true"   />
          <field name="grade"     type="textComplex"    indexed="true"  stored="true"   />
          <field name="_version_" type="long"      indexed="true"  stored="true"/>
      </fields>
    <copyField source="major" dest="name"/>
    <copyField source="grade" dest="name"/>

    然后进入solr的页面。

    分词的结果页面却是这样的。出现这样的错误:TokenStream contract violation: reset()/close() call missing, reset() called multiple times, or subclass does not call super.reset(). Please see Javadocs of TokenStream class for more information about the correct consuming workflow.然后通过查找网上资料。是源代码出错了。这个mmseg4j-1.9.1是一个maven项目来的。通过mawen导入项目修改下面的代码。

    添加注释的代码super.reset();然后clean一下,install一下,target会生成一个mmseg4j-analysis-1.9.2-SNAPSHOT.jar文件,将他复制到tomcat/webapps/solr/WEB-INF/lib下,并改名为mmseg4j-analysis-1.9.2.jar,删除mmseg4j-analysis-1.9.1.jar,或者改名为mmseg4j-analysis-1.9.1.jar覆盖掉原来的jar。

    重启tomcat,再测试,结果出来了:

    分词成功了。

  • 相关阅读:
    C:表达式、语句、声明
    SAIO Swift All In One Diablo版 安装指南 Alpha
    Python自然语言处理学习笔记(60):7.1 信息抽取
    Python自然语言处理学习笔记(59):练习
    Python自然语言处理学习笔记(62):7.3 开发和评价分块器
    doctest模块的使用说明
    Python自然语言处理学习笔记(61):7.2 分块
    Python自然语言处理学习笔记(57):小结
    使用cURL操作Openstack对象存储的ReST API
    认证系统
  • 原文地址:https://www.cnblogs.com/hjy9420/p/4229056.html
Copyright © 2011-2022 走看看