1

Before asking this question i went through these( question_1, question_2) , both are not exactly my use-cases

I am using nltk tree.draw() method to get tree visualisation of a sentence, but i need to do that for all sentences in paragraph

so i want to store the output of all sentences of a paragraph in a file, where i can preserve the representation and which will help in analysing those structures

the output through tree.draw is in this way tree visualisation

i want tree representations of all sentences of a paragraph in a file(text/image/ . ) so that it will be easy to analyse

is there an way to achieve that ?

edit : output with treeview - https://i.stack.imgur.com/Gujqn.jpg

Satyaaditya
  • 537
  • 8
  • 26

1 Answers1

1

Answer based on this answer from the almost duplicate question you linked.

The TreeView constructor can take an arbitrary number of tree arguments:

from nltk import Tree
from nltk.draw import TreeView

number_of_trees = 14

# number_of_trees identical trees
trees = [Tree.fromstring('(S (NP this tree) (VP (V is) (AdjP pretty)))') for _ in range(number_of_trees)]

TreeView(*trees)._cframe.print_to_file('output.ps')

Result converted to png from ps

Side note: an alternative to nltk for drawing trees is the treedraw option of discodop.

mcoav
  • 1,586
  • 8
  • 11
  • thanks @mcoav, but i am having a issue there, while i am printing to postscript file the nodes of tree are populated with some numbers and values in leaves are also some strange words, i will upload output in question , please have a look on it – Satyaaditya Aug 17 '18 at 05:59