【发布时间】:2017-09-04 08:16:28
【问题描述】:
我想从Stanford CoreNLP 中的Tree 中找到每个短语(成分)的中心词,但是当我尝试将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() 的大小,但对于所有这些,我在 constituentTree.parent() 方法上得到 UnsupportedOperationException。谁能帮我获取树中“所有”成分的语义头的正确方法是什么?
【问题讨论】:
-
问题似乎是没有为该类型实现父方法。有没有关于斯坦福 CoreNLP 的文档?
标签: java stanford-nlp parse-tree