Stanford Core NLP 示例代码 SemanticGraph 异常

Stanford Core NLP example code SemanticGraph exception

我刚刚试用了核心 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."

我遗漏的句子的语法或语义是否有任何特殊之处导致错误?

不,句子没问题,不幸的是,这是我们依赖转换器中的一个错误。

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

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

但是您仍然可以通过禁用词性标注器来解析这句话(请参阅 parser FAQ for details on how to do this) or by using the neural network dependency parser