为什么我在StanfordCoreNLP中遇到不支持的操作异常

gajydyqb  于 2021-07-03  发布在  Java
关注(0)|答案(1)|浏览(445)

我想从一个句子中找出每个短语(成分)的中心词 TreeStanford CoreNLP ,但当我尝试 tree.Parent() 对于任何一个 constituents ,我明白了 UnsupportedOperationException . 我做错什么了?
这是我的密码:

List<Tree> allConstituents = new ArrayList<>();
    private Tree parseTree;

  List<CoreMap> sentences = LoadAndParse(language, filetype, modelPath, text);

            for (CoreMap sentence : sentences) {
                Tree parse = sentence.get(TreeAnnotation.class);
                allConstituents = parseTree.subTreeList();

            for (int i = 0; i < allConstituents.size(); i++) {
                    Tree constituentTree = allConstituents.get(i);
                    HeadFinder headFinder = new SemanticHeadFinder();
                    String head = constituentTree.headTerminal(headFinder, constituentTree.parent());

                }
              }

我举了一个例子:

Your tasks are challenging:

我得到的是13号 parseTree.subTreeList() 但对他们来说 UnsupportedOperationExceptionconstituentTree.parent() 方法。有谁能帮我找到树中“所有”成分的语义头的正确方法吗?

mlnl4t2r

mlnl4t2r1#

我不确定这是否真的是一个适用于所有人的答案,但在我的情况下,这是有帮助的:
使用主 Tree 包括整个句子作为所有成分的第二个输入;即:

String head = constituentTree.headTerminal(headFinder, parseTree);

相关问题