2016-10-26 1 views
0

私は実装にスタンフォードパーサーを使用します。 さまざまな情報を抽出するために、文章のツリーを使用したいと思います。スタンフォードパーサーのツリー内で補題を抽出

私は、コードを使用:、私は補題を抽出することができませんでした

Tree sentenceTree= sentence.get(TreeCoreAnnotations.TreeAnnotation.class); 
for (Tree sentenceTree: t) { 
String pos = sentenceTree.label().value(); 
String wd = sentenceTree.firstChild().label().value(); 
Integer wdIndex = ?? 
CoreLabel token = sentence.get(CoreAnnotations.TokensAnnotation.class).get(wdIndex); 

}

誰のことを行います。私は私のCoreMap文と対応するツリーを持っている

Get certain nodes out of a Parse Treeどのようにそれを行うアイデアを持っている?

私は、次のコードを試してみました、それが動作しますが、それはどちらも、いくつかの警告を生成しませんし、非常にきれいではありません。

Annotation a = new Annotation("geese"); 
ss.pipeline.annotate(a); 
CoreMap se = a.get(CoreAnnotations.SentencesAnnotation.class).get(0); 
CoreLabel token = se.get(CoreAnnotations.TokensAnnotation.class).get(0); 
String lemma = token.get(CoreAnnotations.LemmaAnnotation.class); 
System.out.println(lemma); // goose 

は誰にどんなアドバイスをしていますか?

ありがとうございました!

+0

CoreMap(文章)の単語インデックスと同じ値の文章ツリーに単語インデックスがありますか? –

答えて

1

私は同じ問題がありましたが、私はペアの葉と葉のインデックスのHashMapで解決しました。このコードは、名詞であるすべての一致するリーフのlemmatizedバージョンを出力します。

このソリューションは、検索されたノードがリーフの1つ前のレベルである場合にのみ機能します。

関連する問題