Kiwi 라이브러리

yield 란?

11

워드 클라우드

!pip install wordcloud

file_path = '/content/drive/MyDrive/Colab Notebooks/SW엔지니어/data/KakaoTalk_20250423_1124_16_633_group.txt'
with open(file_path, 'r', encoding='utf-8') as f:
  text = f.read()

# re 라이브러리 : regular expression (정규 표현식) > 문자열 검색 치환 추출
import re

# 대괄호 []로 정규표현식으로 찾아서 빈문자열로 치환
cleaned_text = re.sub(r'\\[.*?\\]','',text)
# .* >> 모든 문자
# ? >> ex) [..] asdasdasd [...] >> 전부 삭제 방지

# 여러 공백 하나의 공백으로 치환해주는 것
cleaned_text = re.sub(r'\\s+','',cleaned_text)
# \\s >> 공백 문자 + 는 연속된 공백문자
cleaned_text

# 워드 클라우드 만들기 matplotlib import
from wordcloud import WordCloud
import matplotlib.pyplot as plt

# 워드 클라우드를 객체를 만들기
wordcloud = WordCloud(font_path = '/content/drive/MyDrive/Colab Notebooks/SW엔지니어/data/NanumGothic.ttf',
                      width=800, height = 400, background_color = 'white').generate(cleaned_text)
# generate(cleaned_text) : 단어의 빈도에 따라 글자의 크기 조절

# 워드 클라우드 시각화
plt.figure(figsize=(10,6))
plt.imshow(wordcloud, interpolation = 'bilinear') # 워드 클라우드 시각화 픽셀 깨짐 방지
plt.axis('off') # x축, y축 표시 off
plt.show()