PrintTree - No head rule defined for MWE - Bug with version 3.5.2

随声附和 提交于 2019-12-11 04:09:20

问题


When I'm trying to print the tree of a sentence I've parsed using the RNN parser, it crashes when there is a MWE dependency in the sentence. It crashes with the latest version of the Stanford NLP (3.5.2), but not with the previous one (3.5.1).

Here is the error I get:

java.lang.IllegalArgumentException: No head rule defined for MWE using class edu.stanford.nlp.trees.SemanticHeadFinder in (MWE (VBG according) (TO to))
    at edu.stanford.nlp.trees.AbstractCollinsHeadFinder.determineNonTrivialHead(AbstractCollinsHeadFinder.java:242)
    at edu.stanford.nlp.trees.SemanticHeadFinder.determineNonTrivialHead(SemanticHeadFinder.java:437)
    at edu.stanford.nlp.trees.AbstractCollinsHeadFinder.determineHead(AbstractCollinsHeadFinder.java:189)
    at edu.stanford.nlp.trees.TreeGraphNode.percolateHeads(TreeGraphNode.java:315)
    at edu.stanford.nlp.trees.TreeGraphNode.percolateHeads(TreeGraphNode.java:313)
    at edu.stanford.nlp.trees.TreeGraphNode.percolateHeads(TreeGraphNode.java:313)
    at edu.stanford.nlp.trees.TreeGraphNode.percolateHeads(TreeGraphNode.java:313)
    at edu.stanford.nlp.trees.TreeGraphNode.percolateHeads(TreeGraphNode.java:313)
    at edu.stanford.nlp.trees.TreeGraphNode.percolateHeads(TreeGraphNode.java:313)
    at edu.stanford.nlp.trees.TreeGraphNode.percolateHeads(TreeGraphNode.java:313)
    at edu.stanford.nlp.trees.TreeGraphNode.percolateHeads(TreeGraphNode.java:313)
    at edu.stanford.nlp.trees.TreeGraphNode.percolateHeads(TreeGraphNode.java:313)
    at edu.stanford.nlp.trees.GrammaticalStructure.<init>(GrammaticalStructure.java:183)
    at edu.stanford.nlp.trees.UniversalEnglishGrammaticalStructure.<init>(UniversalEnglishGrammaticalStructure.java:92)
    at edu.stanford.nlp.trees.UniversalEnglishGrammaticalStructure.<init>(UniversalEnglishGrammaticalStructure.java:71)
    at edu.stanford.nlp.trees.UniversalEnglishGrammaticalStructureFactory.newGrammaticalStructure(UniversalEnglishGrammaticalStructureFactory.java:29)
    at edu.stanford.nlp.trees.UniversalEnglishGrammaticalStructureFactory.newGrammaticalStructure(UniversalEnglishGrammaticalStructureFactory.java:5)
    at edu.stanford.nlp.trees.TreePrint.printTreeInternal(TreePrint.java:652)
    at edu.stanford.nlp.trees.TreePrint.printTree(TreePrint.java:264)
    at edu.stanford.nlp.trees.TreePrint.printTree(TreePrint.java:226)

Is there a way to fix this with the latest version, or is it just a bug that will be fixed in the next version?

Thanks in advance!

EDIT:

Here is the code I use:

String paragrah = "Whatever text that contains MWE dependency.";
LexicalizedParser lp = LexicalizedParser.loadModel("edu/stanford/nlp/models/lexparser/englishRNN.ser.gz");
TreebankLanguagePack tlp = new PennTreebankLanguagePack();
TreePrint tp = new TreePrint("wordsAndTags,typedDependencies", tlp);
DocumentPreprocessor processor = new DocumentPreprocessor(new StringReader(paragraph));
for (List<HasWord> sentence : processor) {
    Tree parse = lp.apply(sentence);
    tp.printTree(parse, pw);
}

来源:https://stackoverflow.com/questions/31458296/printtree-no-head-rule-defined-for-mwe-bug-with-version-3-5-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!