0
これは私が絵としてスタンフォードパーサの木を持っているスタンフォードパーサスタンフォードパーサー:Cの親のパスを取得する方法--->ルート?
の写真です。私はC'parentのパスをルートにしたい。例:"but"のパス - > root = CC Sルートまたは "it"のパスparent - > root:PRP NP VP VP S Sルート。しかし、私はそれをどうやって行うのか分かりません。私はステートメントを解析するためにStanford Parserを使用します。
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