t.draw()… is not working could someone help me fix this problem please.

1,258 views
Skip to first unread message

Robel Gedam

unread,
Jul 2, 2014, 12:27:26 AM7/2/14
to nltk-...@googlegroups.com
So I typed in the code below and I am getting the error --------"IOError: No such file or directory: u'/Users/rino/nltk_data/corpora/treebank/combined/wsj_001.mrg'
I commented out everything below the second import command and the top part of the code seems to be working just fine…
I don't know why my tree is not drawing out, if someone could please explain I'd appreciate it very much…
Sincerely... Thank you for you time.


import nltk

sentence="i love you, so much"

tokens=nltk.word_tokenize(sentence)

print (tokens)

tagged=nltk.pos_tag(tokens)

print tagged[:]

entities=nltk.chunk.ne_chunk(tagged)

print (entities)


'''from nltk.corpus import treebank

t=treebank.parsed_sents('wsj_001.mrg')[0]

t.draw'''

Antonio Guerrieri

unread,
Jul 2, 2014, 5:01:04 AM7/2/14
to nltk-...@googlegroups.com
Try one more 0 in file name:
t=treebank.parsed_sents('wsj_0001.mrg')[0] 

Cheers



--
You received this message because you are subscribed to the Google Groups "nltk-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nltk-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

hyperviper

unread,
Jul 2, 2014, 5:01:40 AM7/2/14
to nltk-...@googlegroups.com
Try one more 0 in file name:
t=treebank.parsed_sents('wsj_0001.mrg')[0] 

Cheers

Robel Gedam

unread,
Jul 2, 2014, 1:13:08 PM7/2/14
to nltk-...@googlegroups.com
okay that got rid of the error but its still not drawing a tree….

Robel Gedam

unread,
Jul 2, 2014, 2:00:29 PM7/2/14
to nltk-...@googlegroups.com


On Tuesday, July 1, 2014 9:27:26 PM UTC-7, Robel Gedam wrote:
So I typed in the code below and I am not getting a tree 
Im added the print results below…
I don't know why my tree is not drawing out, if someone could please explain I'd appreciate it very much…
Sincerely... Thank you for you time.


import nltk

sentence="i love you, so much"

tokens=nltk.word_tokenize(sentence)

print (tokens)

tagged=nltk.pos_tag(tokens)

print tagged[:]

entities=nltk.chunk.ne_chunk(tagged)

print (entities)


'''from nltk.corpus import treebank

t=treebank.parsed_sents('wsj_0001.mrg')[0]

print (t.draw''')



['i', 'love', 'you', ',', 'so', 'much']
[('i', 'PRP'), ('love', 'VBP'), ('you', 'PRP'), (',', ','), ('so', 'RB'), ('much', 'RB')]
(S i/PRP love/VBP you/PRP ,/, so/RB much/RB)
<bound method Tree.draw of Tree('S', [Tree('NP-SBJ', [Tree('NP', [Tree('NNP', ['Pierre']), Tree('NNP', ['Vinken'])]), Tree(',', [',']), Tree('ADJP', [Tree('NP', [Tree('CD', ['61']), Tree('NNS', ['years'])]), Tree('JJ', ['old'])]), Tree(',', [','])]), Tree('VP', [Tree('MD', ['will']), Tree('VP', [Tree('VB', ['join']), Tree('NP', [Tree('DT', ['the']), Tree('NN', ['board'])]), Tree('PP-CLR', [Tree('IN', ['as']), Tree('NP', [Tree('DT', ['a']), Tree('JJ', ['nonexecutive']), Tree('NN', ['director'])])]), Tree('NP-TMP', [Tree('NNP', ['Nov.']), Tree('CD', ['29'])])])]), Tree('.', ['.'])])>

 

Fred Mailhot

unread,
Jul 2, 2014, 2:22:23 PM7/2/14
to nltk-...@googlegroups.com
You have "print t.draw" in your code and you can see in the output "<bound method Tree.dray of ...>" which indicates that draw needs to be called as a method. Use

t.draw()

and it should work.



--

Steven Bird

unread,
Jul 2, 2014, 2:30:32 PM7/2/14
to nltk-users
Robel -- you need to call the draw method, i.e. t.draw().
Don't use print().

http://www.nltk.org/api/nltk.html?highlight=draw#nltk.tree.Tree.draw


On 2 July 2014 14:00, Robel Gedam <rob...@gmail.com> wrote:
>
>
> On Tuesday, July 1, 2014 9:27:26 PM UTC-7, Robel Gedam wrote:
>>
>> So I typed in the code below and I am not getting a tree
>> Im added the print results below...
>> I don't know why my tree is not drawing out, if someone could please
>> explain I'd appreciate it very much...

Robel Gedam

unread,
Jul 3, 2014, 2:00:34 PM7/3/14
to nltk-...@googlegroups.com
I tried that and it didn't work… surprisingly though, it did the same thing… its like its not finishing the program & throwing an error.

Robel Gedam

unread,
Jul 3, 2014, 2:03:18 PM7/3/14
to nltk-...@googlegroups.com
Hey thanks for your reply. I just ran ran it as just t.draw() & it printed out whats below but still no tree…



['i', 'love', 'you', ',', 'so', 'much']
[('i', 'PRP'), ('love', 'VBP'), ('you', 'PRP'), (',', ','), ('so', 'RB'), ('much', 'RB')]
(S i/PRP love/VBP you/PRP ,/, so/RB much/RB)

Robel Gedam

unread,
Jul 5, 2014, 6:32:53 AM7/5/14
to nltk-...@googlegroups.com
Changed it and still no tree

Steven Bird

unread,
Jul 5, 2014, 7:52:45 AM7/5/14
to nltk-users
Robel, note that the tree is displayed in another window. Python uses
the Tkinter library for drawing trees. Please see the instructions in
the following page to test whether Tkinter is working on your machine:
https://wiki.python.org/moin/TkInter



On 5 July 2014 06:32, Robel Gedam <rob...@gmail.com> wrote:
> Changed it and still no tree
>

Ganesh Krishnamurthy

unread,
Aug 11, 2015, 10:20:02 AM8/11/15
to nltk-users
Import the library and call draw_trees
Incase if it gives error on the import then 

import nltk and then 
nltk.download('maxent_treebank_pos_tagger')
nltk.download('treebank')

from nltk.draw.tree import draw_trees
draw_trees(entities)

This ideally show solve your problem.
Reply all
Reply to author
Forward
0 new messages