斯坦福NLP:以树格式打印解析器树



这是一个愚蠢的问题,但是我如何以树格式打印NLP解析树的结果?

这是我的代码:

public static void main(String[] args) {
Annotation document =
new Annotation("My dog also likes eating sausage.");
Properties props = new Properties();
props.setProperty("annotators", "tokenize,ssplit,pos,lemma,ner,parse");
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);
pipeline.annotate(document);
for (CoreMap sentence : document.get(CoreAnnotations.SentencesAnnotation.class)) {
Tree constituencyParse = sentence.get(TreeCoreAnnotations.TreeAnnotation.class);
System.out.println(constituencyParse);
}
}

执行时,我在 Eclipse 控制台中得到以下结果:

(ROOT (S (NP (PRP$ My) (NN dog)) (ADVP (RB also)) (VP (VBZ likes) (NP (JJ eating) (NN sausage))) (. .)))

有没有办法以实际的树格式打印它,即这样的东西?

(ROOT
(S
(NP (PRP$ My) (NN dog))
(ADVP (RB also))
(VP (VBZ likes)
(S
(VP (VBG eating)
(NP (NN sausage)))))
(. .)))

以下语句将以打印格式打印树。

tree.pennPrint();

最新更新