Briswell Tech Blog

ブリスウェルのテックブログです

Word Cloud で記事を可視化

最近のブログ記事の内容を可視化すべく

WordCloud for Python documentation — wordcloud 1.8.1 documentation

こちらの「Word Cloud」ライブラリを利用してみます。その名の通り、頻繁に出てくる「単語(Word)」を、その出現頻度に比例する大きさで「雲(Cloud)」のように並べて表示してくれます。以下のようなパラメータ設定が可能です。

wordcloud = WordCloud(
    font_path = "/System/Library/Fonts/ヒラギノ角ゴシック W6.ttc", #フォントのパス
    width = 900, height = 600, #キャンバスのサイズ
    background_color = "white",   #背景色
    stopwords = ['さん','くん'], #除外する単語
    max_words = 500,   #単語数の上限
    min_font_size = 4,   #最小のフォントサイズ
    collocations = False   #複合語のオプション
    ).generate(words_blog)

Welcome to janome's documentation! (Japanese) — Janome v0.4 documentation (ja)

また、こちらの「Janome」ライブラリを使用して、単語を名詞のみに絞ります。ただし、代名詞(例:そこ)、非自立(例:もの)、数(例:1)は除外します。

word_list=[]
for token in tokens:
    word = token.surface
    part_1 = token.part_of_speech.split(',')[0]
    part_2 = token.part_of_speech.split(',')[1]
     
    if part_1 == "名詞":
        if (part_2 != "代名詞") and (part_2 != "非自立") and (part_2 != "数"):
            word_list.append(word)

では、確認してみましょう。

f:id:KenjiU:20211031224401p:plain

古き良きものを今の時代にも、伝えていきたい所存でございます。