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

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

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

  1. List<Tree> allConstituents = new ArrayList<>();
  2. private Tree parseTree;
  3. List<CoreMap> sentences = LoadAndParse(language, filetype, modelPath, text);
  4. for (CoreMap sentence : sentences) {
  5. Tree parse = sentence.get(TreeAnnotation.class);
  6. allConstituents = parseTree.subTreeList();
  7. for (int i = 0; i < allConstituents.size(); i++) {
  8. Tree constituentTree = allConstituents.get(i);
  9. HeadFinder headFinder = new SemanticHeadFinder();
  10. String head = constituentTree.headTerminal(headFinder, constituentTree.parent());
  11. }
  12. }

我举了一个例子:

  1. Your tasks are challenging:

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

mlnl4t2r

mlnl4t2r1#

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

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

相关问题