0
得到UnsupportedOperationException異常,我想找到Stanford CoreNLP
從Tree
每個短語(成分)的中心詞,但是當我嘗試tree.Parent()
對於任何constituents
的,我得到UnsupportedOperationException
。我究竟做錯了什麼?爲什麼我與斯坦福CoreNLP
這裏是我的代碼:
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()
的大小,但所有這些,我得到的UnsupportedOperationException
的constituentTree.parent()
方法。任何人都可以幫助我得到樹中所有組成成分的語義頭的正確方法嗎?
這個問題似乎是父方法沒有爲那個類型實現的。有沒有關於斯坦福CoreNLP的任何文件? – Stultuske