如何从节点列表及其 children 在 NLTK 中生成带括号的树字符串

How can I generate a bracketed tree string in NLTK from a list of nodes and their children

NLTK 文档中有大量通过解析括号内的字符串来构造树的示例。有没有一种简单的方法可以从 parents 及其 children 的列表中构建树?我希望能够生成括号内的字符串作为输出。

parent : children 
14_fine : 12_the,13_nasd
8_allegations : 7_the
10_consented : 11_to
4_admitted : 2_morgan,3_neither,15_.,6_denied,5_nor
11_to : 14_fine
6_denied : 8_allegations,9_but,10_consented
2_morgan : 1_j.p.

回答(感谢 frankov):看这里的演示函数:http://www.nltk.org/_modules/nltk/parse/dependencygraph.html

转换成 conll 格式然后做类似的事情

dg = DependencyGraph(conll_data1)
tree = dg.tree()
tree.pprint()