본문 바로가기

PYTHON/워드클라우드

konlpy 0kt counter 써보기

728x90
from konlpy.tag import Okt
from collections import Counter
from konlpy.corpus import kolaw
from konlpy.corpus import kobill
import codecs

okt = Okt()

f = codecs.open('testtext.txt','r', encoding ='utf8')
text = f.read()
print(text)

# kolaw.open('./testtext.txt').read()[:30]

print("okt.morphs(text)")
print(okt.morphs(text))

print("okt.nouns(text)")
print(okt.nouns(text))

print("okt.phrases(text)")
print(okt.phrases(text))

# pos : 품사부착
# norm – If True, normalize tokens.
# stem – If True, stem tokens.
# join – If True, returns joined sets of morph and tag.

print("okt.pos(text)") 
print(okt.pos(text))

print("okt.pos(text, norm=True)")
print(okt.pos(text, norm=True))

print("okt.pos(text, norm=True, stem=True)")
print(okt.pos(text, norm=True, stem=True))

# counter
print("Counter(okt.morphs(text) )")
print(Counter(okt.morphs(text) ))
from konlpy.tag import Okt
from collections import Counter
from konlpy.corpus import kolaw
from konlpy.corpus import kobill
import codecs
import pytagcloud
from Ipython.display import image

okt = Okt()

f = codecs.open('testtext.txt','r', encoding ='utf8')
text = f.read()
print(text)

# kolaw.open('./testtext.txt').read()[:30]

# print("okt.morphs(text)")
# print(okt.morphs(text))

print("okt.nouns(text)")
print(okt.nouns(text))

# print("okt.phrases(text)")
# print(okt.phrases(text))

# pos : 품사부착
# norm – If True, normalize tokens.
# stem – If True, stem tokens.
# join – If True, returns joined sets of morph and tag.

# print("okt.pos(text)") 
# print(okt.pos(text))

# print("okt.pos(text, norm=True)")
# print(okt.pos(text, norm=True))

# print("okt.pos(text, norm=True, stem=True)")
# print(okt.pos(text, norm=True, stem=True))

# counter
print("Counter(okt.morphs(text) )")
count=Counter(okt.morphs(text) )

# count

print(count.most_common(10))
taglist = pytagcloud.make_tags(tag2,maxsize=80)
taglist