NLTK 文档有大量通过解析括号字符串来构造树的示例。有没有一种简单的方法可以从 parent 及其 child 的列表中构建树?我希望能够生成括号内的字符串作为输出。
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()
关于python - 如何从节点及其子节点列表中生成 NLTK 中的括号树字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29230623/