python - use tkinter for nltk draw inside of jupyter notebook -
i'm trying draw graph (inline) of nltk
inside of jupyter-notebook
. got error:
tclerror: no display name , no $display environment variable
i have tried set $display
different values:
$env display=0.0 # or $env display=inline # or $env display=
but got error (or similar):
tclerror: couldn't connect display "0.0"
here code https://github.com/hyzhak/nltk-experiments/blob/master/main.ipynb last cell.
environment: official anaconda3 docker -- continuumio/anaconda3:4.4.0
https://github.com/continuumio/docker-images. nltk==3.2.3
inside.
python 3.6.1 |anaconda 4.4.0 (64-bit)| (default, may 11 2017, 13:09:58) type "copyright", "credits" or "license" more information. ipython 5.3.0 -- enhanced interactive python.
how solve error , inline nltk
graph inside of jupyter notebook
?
update 1
http://www.nltk.org/_modules/nltk/draw/tree.html#draw_trees according sources of nltk tree draw uses tkinter
.
update 2
i have asked same question in official nltk github repository https://github.com/nltk/nltk/issues/1765
update 3
i think reason of error headless host (docker). have installed xvfb
seems note enough.
run apt-get install -y xvfb
solution
i thought xvfb
launched default should run explicitly. after have launched make screenshots of nltk tree graph.
import os import nltk ipython.display import image chunkgram = r"""chunk: {<rb.?>*<vb.?>*<nnp>+<nn>?}""" chunkparser = nltk.regexpparser(chunkgram) tagged = [('tonight', 'nn'), ('we', 'prp'), ('are', 'vbp'), ('comforted', 'vbn'), ('by', 'in'), ('the', 'dt'), ('hope', 'nn'), ('of', 'in'), ('a', 'dt'), ('glad', 'jj'), ('reunion', 'nn'), ('with', 'in'), ('the', 'dt'), ('husband', 'nn'), ('who', 'wp'), ('was', 'vbd'), ('taken', 'vbn'), ('so', 'rb'), ('long', 'rb'), ('ago', 'rb'), (',', ','), ('and', 'cc'), ('we', 'prp'), ('are', 'vbp'), ('grateful', 'jj'), ('for', 'in'), ('the', 'dt'), ('good', 'jj'), ('life', 'nn'), ('of', 'in'), ('coretta', 'nnp'), ('scott', 'nnp'), ('king', 'nnp'), ('.', '.')] chunked = chunkparser.parse(tagged) nltk.draw.tree.treeview(chunked)._cframe.print_to_file('output.ps') os.system('convert output.ps output.png') image(filename='output.png')
[out]:
Comments
Post a Comment