如何打印斯坦福JavaNLP的解析树 [英] How to print the parse tree of Stanford JavaNLP

查看:150
本文介绍了如何打印斯坦福JavaNLP的解析树的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用 edu.stanford.nlp。* 包获取所有名词短语。我得到了标签值NP的所有子树,但我无法获得正常的原始 String 格式(不是Penn树格式)。

I am trying to get all the noun phrases using the edu.stanford.nlp.* package. I got all the subtrees of label value "NP", but I am not able to get the normal original String format (not Penn Tree format).

例如。对于 subtree.toString()给出(NP(ND全部)(NSS次)))但是我想要字符串所有时间。谁能帮帮我吗。在此先感谢。

E.g. for the subtree.toString() gives (NP (ND all)(NSS times))) but I want the string "all times". Can anyone please help me. Thanks in advance.

推荐答案

我相信你想要的是:

final StringBuilder sb = new StringBuilder();

for ( final Tree t : tree.getLeaves() ) {
     sb.append(t.toString()).append(" ");
}

虽然我不是百分百肯定,但我似乎记得这是解决方案用于我几年前工作的一些软件。

While I'm not 100% sure, I seem to recall this being the solution used for some software I worked on a few years back.

这篇关于如何打印斯坦福JavaNLP的解析树的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆