python3에서 재판 판례 데이터에서 Word Cloud 생성
anaconda 설치 해야 할지도
(zsh)
brew install mecab mecab-ipadic
pip3.5 install mecab-python3
pip3.5 install wordcloud
pip3.5 install numpy Pillow matplotlib # wordcloudを使用するために必要なライブラリ
#brew install numpy # error
#brew install homebrew/python/numpy # smthngs wrong...
#sudo xcode-select --install # doesnt work...
### 新語が追加されたMeCab辞書"mecab-ipadic-neologd"を取得
cd /usr/local/lib/mecab/dic
git clone --depth 1 https://github.com/neologd/mecab-ipadic-neologd.git
./bin/install-mecab-ipadic-neologd -n
wordcloud.py
import MeCab
from os import path
from wordcloud import WordCloud
import matplotlib.pyplot as plt
pos_list = [10, 11, 31, 32, 34]
pos_list.extend(list(range(36,50)))
pos_list.extend([59, 60, 62, 67])
def create_mecab_list(text):
mecab_list = []
mecab = MeCab.Tagger("-Ochasen -d /usr/local/lib/mecab/dic/mecab-ipadic-neologd")
mecab.parse("")
# encoding = text.encode('utf-8')
node = mecab.parseToNode(text)
while node:
if len(node.surface) > 1:
if node.posid in pos_list:
morpheme = node.surface
mecab_list.append(morpheme)
node = node.next
return mecab_list
with open("./086064_hanrei_utf8.txt", "r") as file:
hanrei = file.read()
string = " ".join(create_mecab_list(hanrei))#.decode("utf-8")
fpath = "/Library/Fonts/ヒラギノ丸ゴ ProN W4.ttc"
wordcloud = WordCloud(
# background_color="white",
max_font_size=40,
relative_scaling=.5,
# width=900,
# height=500,
font_path=fpath
).generate(string)
plt.figure()
plt.imshow(wordcloud)
plt.axis("off")
plt.show()
(zsh)
python3 wordcloud.py
Reference
이 문제에 관하여(python3에서 재판 판례 데이터에서 Word Cloud 생성), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/berry-clione/items/f76ba92b4298898b6fd3텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)