In [45]:
from konlpy.corpus import kobill    # Docs from pokr.kr/bill

#-*- coding: utf-8 -*-

files_ko = kobill.fileids()         # Get file ids
dir = '/Users/chanjinpark/GitHub/NRFAnalysis/pythoncode/NLTK/data/'
doc_ko = kobill.open('1809890.txt').read()

In [46]:
# Tokenize
from konlpy.tag import Twitter; t = Twitter()
tokens_ko = t.morphs(doc_ko)

In [47]:
import nltk
ko = nltk.Text(tokens_ko, name='대한민국 국회 의안 제 1809890호')   # For Python 2, input `name` as u'유니코드'

In [48]:
#-*- coding: utf-8 -*-
print(len(ko.tokens))       # returns number of tokens (document length)
print(len(set(ko.tokens)))  # returns number of unique tokens
# ko.vocab()                  # returns frequency distribution

In [49]:
%matplotlib inline

import matplotlib.pyplot as plt
import matplotlib
matplotlib.rc('font',family='AppleGothic')

ko.plot(50)
ko.count('초등학교')   # Counts occurrences


Out[49]:
6

In [50]:
#ko.dispersion_plot([u'육아휴직', u'초등학교', u'공무원'])
print ko.concordance('초등학교')
print ko.similar('자녀')

In [51]:
# Tagging and chunking
from konlpy.tag import Twitter; t = Twitter()
tags_ko = t.pos("작고 노란 강아지가 페르시안 고양이에게 짖었다")

In [53]:
parser_ko = nltk.RegexpParser("NP: {<Adjective>*<Noun>*}")
chunks_ko = parser_ko.parse(tags_ko)
chunks_ko.draw()


---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-53-8fbb59ea556f> in <module>()
      1 parser_ko = nltk.RegexpParser("NP: {<Adjective>*<Noun>*}")
      2 chunks_ko = parser_ko.parse(tags_ko)
----> 3 chunks_ko.draw()

/usr/local/lib/python2.7/site-packages/nltk/tree.pyc in draw(self)
    683         Open a new window containing a graphical diagram of this tree.
    684         """
--> 685         from nltk.draw.tree import draw_trees
    686         draw_trees(self)
    687 

/usr/local/lib/python2.7/site-packages/nltk/draw/tree.py in <module>()
     13 import sys
     14 
---> 15 from tkinter import IntVar, Menu, Tk
     16 
     17 from nltk.util import in_idle

/usr/local/lib/python2.7/site-packages/nltk/compat.pyc in load_module(self, name)
    135             if name not in sys.modules:
    136                 if name == 'tkinter':
--> 137                     mod = TkinterPackage()
    138                 else:
    139                     mod = __import__(self.module_map[name])

/usr/local/lib/python2.7/site-packages/nltk/compat.pyc in __init__(self)
    110     class TkinterPackage(object):
    111         def __init__(self):
--> 112             self.mod = __import__("Tkinter")
    113             self.__path__ = ["nltk_py2_tkinter_package_path"]
    114 

/usr/local/Cellar/python/2.7.12/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py in <module>()
     37     # Attempt to configure Tcl/Tk without requiring PATH
     38     import FixTk
---> 39 import _tkinter # If this fails your Python may not be configured for Tk
     40 tkinter = _tkinter # b/w compat for export
     41 TclError = _tkinter.TclError

ImportError: No module named _tkinter

In [ ]: