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
是不是这个路径问题?<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]
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。