Saving nltk drawn parse tree to image file

前端 未结 3 2089
太阳男子
太阳男子 2020-12-01 13:03

\"enter

Is there any way to save the draw image from tree.draw() to an image file prog

3条回答
  •  Happy的楠姐
    2020-12-01 13:31

    Using the nltk.draw.tree.TreeView object to create the canvas frame automatically:

    >>> 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')
    

    Then:

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

    [output.png]:

提交回复
热议问题