0
這是斯坦福解析器Stanford Parser:如何獲得C的父級路徑---> root?
圖片我有斯坦福解析器樹爲圖片。我想獲得C'parent的路徑 - >以root身份。例如:「but」'parent - > root = CC S Root的路徑,或者「it」parent - > root的路徑:PRP NP VP VP S S Root。但我不知道該怎麼做。我使用斯坦福分析器來解析語句。
statement = "I have a dog , but I don't like it"
Annotation document = new Annotation(statement);
pipeline.annotate(document);
List<CoreMap> sentences = document
.get(CoreAnnotations.SentencesAnnotation.class);
for (CoreMap sentence : sentences) {
Tree tree = sentence.get(TreeCoreAnnotations.TreeAnnotation.class);
List<Tree> leaves = new ArrayList<>();
leaves = tree.getLeaves(leaves);
for (Tree leave : leaves) {
String compare = leave.toString();
if(compare.equals(data.connective) == true) {
// How to get path but --> root
}
}
我試過先使用Tree.parent()或Tree.parent(curr)。但輸出顯示錯誤或錯誤的答案.... – drag
這將是非常有用的信息,包括在您原來的問題。你究竟做了什麼,輸出是什麼? – whrrgarbl
謝謝!這真的很有用。我修復並找到解決方法。謝謝:D – drag