python - 将 nltk 绘制的解析树保存到图像文件

标签 python tree nlp nltk text-parsing

enter image description here

有没有办法以编程方式将绘制图像从 tree.draw() 保存到图像文件?我尝试查看文档,但找不到任何内容。

最佳答案

使用 nltk.draw.tree.TreeView对象自动创建 Canvas 框架:

>>> from nltk.tree import Tree
>>> from nltk.draw.tree import TreeView
>>> t = Tree.fromstring('(S (NP this tree) (VP (V is) (AdjP pretty)))')
>>> TreeView(t)._cframe.print_to_file('output.ps')

然后:

>>> import os
>>> os.system('convert output.ps output.png')

[输出.png]:

enter image description here

关于python - 将 nltk 绘制的解析树保存到图像文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23429117/

相关文章:

python - np.meshgrid 部分中的标签点

javascript - 在 d3.js 中有 child 朝向多边的树(类似于家谱)

mysql - 顺序 sql 树层次结构

python - 无法在 CentOS 上安装 lxml

python - Pandas 在 df ["C"中说 7 ] 但实际上要求 7 的索引返回空列表 - 为什么?

python - 如何在 qtextbox 中显示 json 数据

c - 如何比较二叉树中的根路径和叶路径

python - 我如何评估我的技术?

python - NLP 共指解析

ios - iOS NSLinguisticTagger在获取词干时始终返回null