LoginSignup
6
1

More than 3 years have passed since last update.

青春時代に狂い聴いていたけど今は聴かなくなったGReeeenの歌詞を可視化してみた。

Last updated at Posted at 2020-05-24

きっかけ

青春時代に狂い聴いていたGReeeen。
なぜあんなに聴いていたのに今聞かなくなたのだろう...そう思ったのが始まりです。
GReeeenの曲が持つメッセージ傾向を可視化し、聴かなくなった理由=曲に共感できなくなった理由を
理解するために歌詞分析を行います。

参考記事

環境

  • Macbook Catalina10.15.4
  • Python 3.7.6
  • BeautifulSoup
  • janome
  • wordcloud
  • Jupiter Notebook

1.歌詞の収集

歌ネットさんからスクレイピングします。

import requests
from bs4 import BeautifulSoup
import pandas as pd
import time

#スクレイピングしたデータを入れる表を作成
list_df = pd.DataFrame(columns=['歌詞'])

for page in range(1, 3):
    #曲ページ先頭アドレス
    base_url = 'https://www.uta-net.com'

    #歌詞一覧ページ
    url = 'https://www.uta-net.com/artist/5384/' + str(page) + '/'
    response = requests.get(url)
    soup = BeautifulSoup(response.text, 'lxml')
    links = soup.find_all('td', class_='side td1')
    for link in links:
        a = base_url + (link.a.get('href'))

        #歌詞詳細ページ
        response = requests.get(a)
        soup = BeautifulSoup(response.text, 'lxml')
        song_lyrics = soup.find('div', itemprop='lyrics')
        song_lyric = song_lyrics.text
        song_lyric = song_lyric.replace('\n','')
        #サーバーに負荷を与えないため1秒待機
        time.sleep(1)

        #取得した歌詞を表に追加
        tmp_se = pd.DataFrame([song_lyric], index=list_df.columns).T
        list_df = list_df.append(tmp_se)

print(list_df)

#csv保存
list_df.to_csv('/Users/ユーザー名/greeeen/list.csv', mode = 'a', encoding='cp932')

2. 歌詞を単語にする(形態素解析)

from janome.tokenizer import Tokenizer
import pandas as pd
import re

#list.csvファイルを読み込み
df_file = pd.read_csv('/Users/ユーザー名/greeeen/list.csv', encoding='cp932')

song_lyrics = df_file['歌詞'].tolist()

t = Tokenizer()

results = []

for s in song_lyrics:
    tokens = t.tokenize(s)

    r = []

    for tok in tokens:
        if tok.base_form == '*':
            word = tok.surface
        else:
            word = tok.base_form

        ps = tok.part_of_speech

        hinshi = ps.split(',')[0]

        if hinshi in ['名詞', '形容詞', '動詞', '副詞']:
            r.append(word)

    rl = (' '.join(r)).strip()
    results.append(rl)
    #余計な文字コードの置き換え
    result = [i.replace('\u3000','') for i in results]
    print(result)

text_file = '/Users/ユーザー名/greeeen/wakati_list.txt'
with open(text_file, 'w', encoding='utf-8') as fp:
    fp.write("\n".join(result))

3. 可視化(WordCloud)

from wordcloud import WordCloud

text_file = open('/Users/ユーザー名/greeeen/wakati_list.txt', encoding='utf-8')
text = text_file.read()

#日本語のフォントパス
fpath = '/System/Library/Fonts/ヒラギノ明朝 ProN.ttc'

#無意味そうな単語除去
stop_words = ['そう', 'ない', 'いる', 'する', 'まま', 'よう', 'てる', 'なる', 'こと', 'もう', 'いい', 'ある', 'ゆく', 'れる']

wordcloud = WordCloud(background_color='white',
    font_path=fpath, width=800, height=600, stopwords=set(stop_words)).generate(text)

#画像はwordcloud.pyファイルと同じディレクトリにpng保存
wordcloud.to_file('./wordcloud.png')

完成品

image.png

「僕ら」や「今日」など時間・空間的に当人や今に近い言葉が多いですね。
他は「行く」「進む」「変わる」など前進・変化を連想させたり、不確実性を持つ「きっと」が頻出しています。
あとは「笑う」「笑顔」が見受けられます。

結論

  • GReeeenの歌詞が持つメッセージ傾向を一言でいうと
    「未来は不確実だけど「今」に集中し仲間と笑顔で前進していこう」
    である傾向がある。

今回の分析により大人になった自分の心がかなり荒んでいることが顕在化しました。
社会適応するために冷めた心を持ったのだと思いますが、そのせいで青春時代に抱いた暑苦しく信じる心を失っていたようです。
今回の結果を踏まえ、少しでも青春時代のような若々しさを持てるよう頑張ります。
とりあいず笑う回数を増やそうかな...

6
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
1