我正在使用stanford-nlp和Java 7以及NetBeans 7.3.1
Properties props = new Properties();
props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse, dcoref");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
String text = "the dog who bit the man";// Add your text here!
Annotation document = new Annotation(text);
pipeline.annotate(document);
List<CoreMap> sentences = document.get(SentencesAnnotation.class);
for(CoreMap sentence: sentences) {
for (CoreLabel token: sentence.get(TokensAnnotation.class)) {
String word = token.get(TextAnnotation.class);
String pos = token.get(PartOfSpeechAnnotation.class);
String ne = token.get(NamedEntityTagAnnotation.class);
}
Tree tree = sentence.get(TreeAnnotation.class);
System.out.println(tree);
System.out.println(tree.depth());
有了这个,我可以获得树的深度,但我怎样才能获得足够深度的术语&#39; dog&#39;或者这个解析树中任何其他术语的深度?
答案 0 :(得分:0)
经过一番研究,我发现这是一个愚蠢的问题(非常愚蠢)抱歉:D
无论如何,这是我所学到的:
由于句子的术语/字符串在解析树中表示为叶子,因此它们的深度将为0.
现在如何访问该术语,即如何将树迭代到该术语/ string / leaf ::
JObject