开发者社区> 问答> 正文

ikanalyzer和lucene整合关于扩展词典?报错

ik版本是3.2.0stable.jar    lucene版本是3.0.2.jar

----------------IKAnalyzer.cfg.xml的配置内容----------------------------

<properties>  
    <entry key="ext_dict">/ext_first.dic</entry>  
</properties>

------------------测试代码-------------------------------------------------

public static void main(String[] args) throws IOException {
    new TestAnalyzer().test(new IKAnalyzer(), "我是个大帅哥,而且很聪明的大帅哥");
}

public void test(Analyzer analyzer,String text) throws IOException{
        System.out.println("分词器是:"+analyzer.getClass().getName());
        TokenStream tokenStream=analyzer.tokenStream("content", new StringReader(text));
        tokenStream.addAttribute(TermAttribute.class);
        while(tokenStream.incrementToken()){
            TermAttribute termAttribute=tokenStream.getAttribute(TermAttribute.class);
            System.out.println(termAttribute.term());
        }
}


但是结果报错了:报错信息如下。麻烦大家给点建议:

        分词器是:org.wltea.analyzer.lucene.IKAnalyzer
        Exception in thread "main" java.lang.ExceptionInInitializerError
        at org.wltea.analyzer.seg.ChineseSegmenter.<init>(ChineseSegmenter.java:37)
        at org.wltea.analyzer.cfg.Configuration.loadSegmenter(Configuration.java:114)
        at org.wltea.analyzer.IKSegmentation.<init>(IKSegmentation.java:54)
        at org.wltea.analyzer.lucene.IKTokenizer.<init>(IKTokenizer.java:44)
        at org.wltea.analyzer.lucene.IKAnalyzer.tokenStream(IKAnalyzer.java:45)
        at cn.gdpe.lucene.TestAnalyzer.test(TestAnalyzer.java:32)
        at cn.gdpe.lucene.TestAnalyzer.main(TestAnalyzer.java:27)
        Caused by: java.lang.ArrayIndexOutOfBoundsException: 0
        at org.wltea.analyzer.dic.DictSegment.fillSegment(DictSegment.java:139)
        at org.wltea.analyzer.dic.DictSegment.fillSegment(DictSegment.java:128)
        at org.wltea.analyzer.dic.Dictionary.loadMainDict(Dictionary.java:134)
        at org.wltea.analyzer.dic.Dictionary.<init>(Dictionary.java:71)
        at org.wltea.analyzer.dic.Dictionary.<clinit>(Dictionary.java:41)
        ... 7 more



谢谢大家了

展开
收起
爱吃鱼的程序员 2020-06-09 14:02:02 702 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    是不是这个路径问题?<spanstyle="font-family:Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#E53333;">/ext_first.dic回复<aclass='referer'target='_blank'>@抽象派:IKAnalyzer2012_u6.jarlucene是3.6.2版本回复<aclass='referer'target='_blank'>@李永china:请问下,您换了什么版本?谢谢您。我重新弄了个版本就好了[4]

    2020-06-09 14:02:18
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载