HanLP icon indicating copy to clipboard operation
HanLP copied to clipboard

调用crf分词的时候出现ArrayIndexOutOfBoundsException错误

Open kelciej opened this issue 9 years ago • 2 comments

错误如下: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 148 at com.hankcs.hanlp.seg.common.Vertex.compileRealWord(Vertex.java:115) at com.hankcs.hanlp.seg.common.Vertex.(Vertex.java:99) at com.hankcs.hanlp.seg.common.Vertex.(Vertex.java:91) at com.hankcs.hanlp.seg.common.Vertex.(Vertex.java:196) at com.hankcs.hanlp.seg.Segment.combineWords(Segment.java:380) at com.hankcs.hanlp.seg.Segment.combineByCustomDictionary(Segment.java:221) at com.hankcs.hanlp.seg.CRF.CRFSegment.segSentence(CRFSegment.java:142) at com.hankcs.hanlp.seg.Segment.seg(Segment.java:558) at test.TegTest.main(TegTest.java:33)

找到是下面这句出错 String str = "什么是谷精草"; List seg = segment.seg(str);

谷精草这个东西我通过自定义词典定义为其他的词语,此处不知道出现了什么错误,希望能够得到解答,谢谢

kelciej avatar Mar 28 '17 11:03 kelciej

我无法复现你的问题,有可能是反射词性引发的,警告已经说了现在的策略了。额外附赠一点建议,试试升级JDK1.8或其他高一点版本的JDK,现在的反射代码在1.8上面运行良好。

public void testIssue452() throws Exception
{
    CustomDictionary.insert("谷精草", "其他 123");
    System.out.println(new CRFSegment().enableCustomDictionary(true).seg("什么是谷精草"));
}

Mar 30, 2017 6:42:37 PM com.hankcs.hanlp.corpus.util.CustomNatureUtility 警告: 已激活自定义词性功能,由于采用了反射技术,用户需对本地环境的兼容性和稳定性负责! 如果用户代码X.java中有switch(nature)语句,需要调用CustomNatureUtility.registerSwitchClass(X.class)注册X这个类 [什么/ry, 是/vshi, 谷精草/其他]

hankcs avatar Mar 30 '17 23:03 hankcs

先谢谢你的回答。我的jdk已经是1.8的。然后目前已经解决了这个问题,我在源代码的某些地方加上了我新增的词性。出现这个错误大概是由于 某些词 本身的词性为 null。进入自定义词性遍历的步骤时,没办法匹配词性,故而导致上述问题。 不管怎么样,还是很感谢你的回答。

kelciej avatar Mar 31 '17 01:03 kelciej