반응형
워드클라우드
워드클라우드 워클생성기 워클 단어구름 한글 워드클라우드 구름단어 글자구름 구름글자 태그클라우드 워드클라우드 태그구름 랜덤이미지 블로그이미지 페이스북이미지
wordcloud.kr
위처럼 인터넷 사이트에 워드클라우드 생성기가 존재한다.
그런데 이 사이트는 몇가지 문제가 있었다.
1. 10,000자 이상 텍스트는 입력할 수 없다.
2. 불용어(표시되지 않기를 원하는 단어)를 설정할 수 없다.
3. 아래와 같이 "명사"만 출력할 수 없다.
그래서 워드클라우드 생성 프로그램을 만들기로 했다!
대략적인 뼈대와 활용 방법을 순서대로 소개하면
1. 프로그램을 실행한다.
2. 원하는 텍스트를 넣고 생성 버튼을 누른다.
실행결과는!
불용어를 추가할 텍스트 위젯을 추가해야하고, GUI를 좀더 매끄럽게 다듬어야하긴 하지만...
우선 위 프로그램을 만드는 소스코드는 아래와 같다.
#워드클라우드 관련 라이브러리
from konlpy.tag import Okt
from wordcloud import WordCloud
from collections import Counter
import matplotlib.pyplot as plt
# GUI 관련 라이브러리
from tkinter import *
# 날짜 관련 라이브러리
from datetime import datetime
# 말뭉치 데이터 가져오기
from konlpy.corpus import kolaw #말뭉치 중 kolaw
sample_text = kolaw.open('constitution.txt').read() #말뭉치 kolaw 활용하기
with open("corpus.txt", mode="w", encoding="utf-8-sig") as f:
f.write(sample_text)
f.close()
# GUI 프로그래밍
#tk 활성화
root = Tk()
lbl_txt = Label(root, text="아래에 워드클라우드를 만들 문장을 넣어주세요")
lbl_txt.pack()
txt = Text(root)
txt.pack()
# 워드클라우드 프로그래밍
tagging = Okt()
wordcloud = WordCloud(font_path="C:\Windows\Fonts\HMFMOLD.TTF",
max_font_size=200,
background_color="#FFFFFF",
width = 800, height = 800)
def create_wordcloud():
txt_value = txt.get(index1 = "0.0", index2 = "end")
nouns = tagging.nouns(txt_value)
count_nouns = Counter(nouns)
result = wordcloud.generate_from_frequencies(count_nouns)
file_name = datetime.now().strftime("%Y%m%d") + "wordcloud.png"
plt.tight_layout()
plt.axis("off")
result.to_file(file_name)
btn_make = Button(root, text="생성", command = create_wordcloud)
btn_make.pack()
root.mainloop()
다른 사람들도 python 설치 없이, exe 파일로 사용할 수 있도록 pyinstaller로 exe파일로도 변환할 예정!!
반응형
'데이터 분석' 카테고리의 다른 글
(데이터, 그래프 비공개)6학년 진단평가 결과(1/2) (0) | 2022.03.21 |
---|---|
커리어넷 연봉 그래프 만들기 (0) | 2022.03.15 |
2017-2020 년 서울 모기지수 평균 그래프 (2) | 2022.03.06 |
워드클라우드 만들기 기초 활용! (0) | 2022.03.03 |
2020년 서울 주거지, 수변부, 공원 모기지수 그래프로 나타내기 (2) | 2022.02.28 |
댓글