Stanford Core NLP示例代码SemanticGraph异常

时间:2015-04-26 13:03:26

标签: stanford-nlp

我刚刚尝试了Core NLP示例代码,包含在 StanfordCoreNlpDemo.java 下载。当试图解析书的一章时,语义图中会抛出异常:

Exception in thread "main" java.lang.NullPointerException
at edu.stanford.nlp.semgraph.SemanticGraph.removeEdge(SemanticGraph.java:122)
at edu.stanford.nlp.trees.UniversalEnglishGrammaticalStructure.expandPPConjunction(UniversalEnglishGrammaticalStructure.java:553)
at edu.stanford.nlp.trees.UniversalEnglishGrammaticalStructure.expandPPConjunctions(UniversalEnglishGrammaticalStructure.java:508)
at edu.stanford.nlp.trees.UniversalEnglishGrammaticalStructure.collapseDependencies(UniversalEnglishGrammaticalStructure.java:807)
at edu.stanford.nlp.trees.GrammaticalStructure.typedDependenciesCollapsed(GrammaticalStructure.java:877)
at edu.stanford.nlp.semgraph.SemanticGraphFactory.makeFromTree(SemanticGraphFactory.java:188)
at edu.stanford.nlp.semgraph.SemanticGraphFactory.generateCollapsedDependencies(SemanticGraphFactory.java:90)
at edu.stanford.nlp.pipeline.ParserAnnotatorUtils.fillInParseAnnotations(ParserAnnotatorUtils.java:51)
at edu.stanford.nlp.pipeline.ParserAnnotator.finishSentence(ParserAnnotator.java:266)
at edu.stanford.nlp.pipeline.ParserAnnotator.doOneSentence(ParserAnnotator.java:245)
at edu.stanford.nlp.pipeline.SentenceAnnotator.annotate(SentenceAnnotator.java:96)
at edu.stanford.nlp.pipeline.AnnotationPipeline.annotate(AnnotationPipeline.java:68)
at edu.stanford.nlp.pipeline.StanfordCoreNLP.annotate(StanfordCoreNLP.java:412)
at epubReader.Test.main(Test.java:68)

我已将其缩小为一句话负责,即使单独解析:

"Generally speaking, he was a scout, and rarely stood at a watch nearer than the four hundred and fiftieth metre, and then only as a cordon commander."

我遗漏的句子的语法或语义是否有什么特别之处,导致错误?

1 个答案:

答案 0 :(得分:2)

不,这句话很好,不幸的是我们的依赖转换器中存在错误。

词性标注器输出一个非常奇怪的POS序列,导致解析器生成一个完全错误的解析树,导致选区到依赖转换器中出现此异常。

我修复了转换器中的错误,但除非您从GitHub克隆代码并自行编译,否则在下一个版本发布之前,这不会帮助您。

但是你仍然可以通过禁用POS标记器来解析这句话(请参阅parser FAQ了解有关如何执行此操作的详细信息)或使用neural network dependency parser