Example #1
1
from collections import Counter

from konlpy.corpus import kolaw
from konlpy.tag import Hannanum
from konlpy.plot import draw_zipf
from konlpy.utils import concordance, pprint
from matplotlib import pyplot


def draw_zipf(count_list, filename, color='blue', marker='o'):
    sorted_list = sorted(count_list, reverse=True)
    pyplot.plot(sorted_list, color=color, marker=marker)
    pyplot.xscale('log')
    pyplot.yscale('log')
    pyplot.savefig(filename)


doc = kolaw.open('constitution.txt').read()
pos = Hannanum().pos(doc)
cnt = Counter(pos)

print 'nchars  :', len(doc)
print 'ntokens :', len(doc.split())
print 'nmorphs :', len(set(pos))
print '\nTop 20 frequent morphemes:'; pprint(cnt.most_common(20))
print '\nLocations of "대한민국" in the document:'
concordance(u'대한민국', doc, show=True)

draw_zipf([b for a, b in cnt.items()], 'zipf.png')
Example #2
0
def test_utils_concordance_show(capsys):
    from konlpy.corpus import kolaw
    from konlpy.utils  import concordance
    doc = kolaw.open('constitution.txt').read()
    ccd = concordance(u'대한민국', doc, show=True)
    out, err = capsys.readouterr()
    assert out == u"0\t대한민국헌법 유구한 역사와\n9\t대한국민은 3·1운동으로 건립된 대한민국임시정부의 법통과 불의에\n98\t총강 제1조 ① 대한민국은 민주공화국이다. ②대한민국의\n100\t① 대한민국은 민주공화국이다. ②대한민국의 주권은 국민에게\n110\t나온다. 제2조 ① 대한민국의 국민이 되는\n126\t의무를 진다. 제3조 대한민국의 영토는 한반도와\n133\t부속도서로 한다. 제4조 대한민국은 통일을 지향하며,\n147\t추진한다. 제5조 ① 대한민국은 국제평화의 유지에\n787\t군무원이 아닌 국민은 대한민국의 영역안에서는 중대한\n1836\t파견 또는 외국군대의 대한민국 영역안에서의 주류에\n3620\t경제 제119조 ① 대한민국의 경제질서는 개인과\n"
Example #3
0
def test_utils_concordance_show(capsys):
    from konlpy.corpus import kolaw
    from konlpy.utils import concordance
    doc = kolaw.open('constitution.txt').read()
    ccd = concordance(u'대한민국', doc, show=True)
    out, err = capsys.readouterr()
    assert out == u"0\t대한민국헌법 유구한 역사와\n9\t대한국민은 3·1운동으로 건립된 대한민국임시정부의 법통과 불의에\n98\t총강 제1조 ① 대한민국은 민주공화국이다. ②대한민국의\n100\t① 대한민국은 민주공화국이다. ②대한민국의 주권은 국민에게\n110\t나온다. 제2조 ① 대한민국의 국민이 되는\n126\t의무를 진다. 제3조 대한민국의 영토는 한반도와\n133\t부속도서로 한다. 제4조 대한민국은 통일을 지향하며,\n147\t추진한다. 제5조 ① 대한민국은 국제평화의 유지에\n787\t군무원이 아닌 국민은 대한민국의 영역안에서는 중대한\n1836\t파견 또는 외국군대의 대한민국 영역안에서의 주류에\n3620\t경제 제119조 ① 대한민국의 경제질서는 개인과\n"
Example #4
0
tokenizer.pos("아버지가방에들어가신다")

from collections import Counter

from konlpy.corpus import kolaw
from konlpy.tag import Hannanum
from konlpy.utils import concordance, pprint
from matplotlib import pyplot


def draw_zipf(count_list, filename, color='blue', marker='o'):
    sorted_list = sorted(count_list, reverse=True)
    pyplot.plot(sorted_list, color=color, marker=marker)
    pyplot.xscale('log')
    pyplot.yscale('log')
    pyplot.savefig(filename)


doc = kolaw.open('constitution.txt').read()
pos = Hannanum().pos(doc)
cnt = Counter(pos)

print('nchars  :', len(doc))
print('ntokens :', len(doc.split()))
print('nmorphs :', len(set(pos)))
print('\nTop 20 frequent morphemes:')
pprint(cnt.most_common(20))
print('\nLocations of "대한민국" in the document:')
concordance('대한민국', doc, show=True)

draw_zipf(cnt.values(), 'zipf.png')
Example #5
0
def test_utils_concordance():
    from konlpy.corpus import kolaw
    from konlpy.utils  import concordance
    doc = kolaw.open('constitution.txt').read()
    ccd = concordance(u'대한민국', doc, show=True)
    assert ccd == [0, 9, 98, 100, 110, 126, 133, 147, 787, 1836, 3620]
Example #6
0
"""

# 꼬꼬마에 대하여
from konlpy.corpus import kolaw
from konlpy.tag import Kkma
from konlpy.utils import concordance

#'''
#헌법 관련된 텍스트 불러오기
contitution = kolaw.open('constitution.txt').read()

print(contitution)

# 몇 번째 줄에 '민주'라는 단어가 있는지 찾아줌

r = concordance(u'민주', contitution, show=False)
print("show = False => ", r)

# 텍스트 마이닝을 할 때 고려사항 : 정확성, 속도
from konlpy.tag import Kkma
from konlpy.utils import pprint

kkma = Kkma()

text = u'네, 안녕하세요. 반갑습니다.'

# 문장단위로 찾아냄
text_s = kkma.sentences(text)
print("text_s => ", text_s)

# 리스트에 담겨서 나옴
Example #7
0
def test_utils_concordance():
    from konlpy.corpus import kolaw
    from konlpy.utils import concordance
    doc = kolaw.open('constitution.txt').read()
    ccd = concordance(u'대한민국', doc, show=True)
    assert ccd == [0, 9, 98, 100, 110, 126, 133, 147, 787, 1836, 3620]