<jupyter_start><jupyter_text>Import file<jupyter_code>phoebes_songs = open('phoebes_songs.txt', 'r') 
songs = phoebes_songs.read()
print(songs)<jupyter_output>love is sweet as summer showers
love is a wondrous work of art
but your love, oh your love,
your love is like a giant pigeon
crapping on my heart.
la la la la la. 

new york city has no power,
and the milk is getting sour.
but to me it is not scary,
'cause i stay away from dairy.
la la, la la la, la la. 

i made a man with eyes of coal
and a smile so bewitchin'.
how was i supposed to know
that my mom was dead in the kitchen?
la lalala laaa la lala la lalala la la.

my mother's ashes, even her eyelashes,
are resting in a little yellow jar.
and sometimes, when it's breezy,
i feel a little sneezy, and now i. 

you don't have to be awake to be my man.
as long as you have brainwaves
i'll be there to hold your hand.
though we just met the other day,
there's something i have got to say. 

they're tiny and chubby and so sweet to touch,
and soon they'll grow up and resent you so much.
now they're yelling at you and you don't know why,
and you cry and you cry and you cry.
and you cry and you cry[...]<jupyter_text>Define WordCloud<jupyter_code>def add_stopwords_to_wordcloud(stop_friends_on_off):
    '''
    Set on and off stopwords - whether to use Friends names or not. If 'True' it will add Friends names to stopwords.
    
    Parameters:
    ----------
    stop_friends_on_off - True/False statement.
    
    Return:
    ------
    stopwords - list of the used stopwords.
    '''
    
    stopwords = set(STOPWORDS) #set(STOPWORDS) for default exclusion
    stopwords.add('and')
    stopwords.add('the')
    stopwords.add('to')
    
    stopwords.add("Scene")
    print(stopwords)
    # Need to add stopwords for Frinds if I don't want to show their names
    stop_friends = stop_friends_on_off

    if stop_friends == True:
        stopwords.add("Monica")
        stopwords.add("Rachel")
        stopwords.add("Ross")
        stopwords.add("Phoebe")
        stopwords.add("Chandler")
        stopwords.add("Joey")
        print('Friends names will be excluded.')
    else:
        print('Firends names will be included.')

    return stopwords

stopwords = add_stopwords_to_wordcloud(True);
max_font_size = 100
min_font_size = 30
bck_color = 'white'
#width = 500
#height = 300
width=1600
height=800
colourmap = plt.cm.cividis_r
relative_scaling = 0.8 # relative scaling sets how to adjust the font sizes based on frequency
                    # relative_scaling == 1.0 means frequency dictates font-size -> Hides low-frequency words
                    # relative_scaling == 0.0 means rank dictates the relative font-size -> hides how frequently a word might appear

collocations = False # if true, it will group phrases; if false it will take single words

def generate_wordcloud_bilinear(episode, max_font_size ):
    '''
    Make a wordcloud based on the episode. Use bilinear interpolation and max font size.
    
    Parametes:
    ---------
    episode - txt of the loaded episode.
    font_size - Integer. Maximum font size used on the image.
    
    Return:
    ------
    Makes a wordcloud and plots it.
    '''
    
    # lower max_font_size
    wordcloud = WordCloud(width=width, height=height, background_color=bck_color, 
                           min_font_size = min_font_size, stopwords=stopwords, colormap = colourmap,
                         relative_scaling=relative_scaling, collocations=collocations).generate(episode)
    
    
    fig = plt.figure()
    plt.imshow(wordcloud, interpolation="bilinear")
    plt.axis("off")
    plt.show()

    fig.tight_layout()
    fig.savefig("Phoebe_songs.png", transparent=True)

    # The pil way (if you don't have matplotlib)
    # image = wordcloud.to_image()
    # image.show()
generate_wordcloud_bilinear(songs, max_font_size)<jupyter_output><empty_output><jupyter_text>Sentence sentiment<jupyter_code>text = 'This is a bit bad'

#put into textblob
obj = TextBlob(songs)

#find sentiment [0 objective; 1subjective]
print(obj.sentiment)

#returns values between -1 and 1
sentiment = obj.sentiment.polarity
print(sentiment)
obj.words;
obj.sentences;
sentence_pol = []
sentence_sub = []
for sentence in obj.sentences:
    #print(sentence.sentiment)
    #print(sentence)
    sentence_pol.append(sentence.sentiment[0])
    sentence_sub.append(sentence.sentiment[1])
words_pol = []
words_sub = []
for word in obj.words:
    #print(word)
    #print(TextBlob(word).sentiment.polarity)
    
    words_pol.append(TextBlob(word).sentiment[0])
    words_sub.append(TextBlob(word).sentiment[1])
    
np.asarray(store_pol)
df_words = pd.DataFrame({'Polarity': words_pol,
                  'Subjectivity': words_sub})
df_words.head()<jupyter_output><empty_output><jupyter_text>Words<jupyter_code>n=20
sns.set(font_scale=1.2)
#map = {i: i for i in range(-1, 1, 0.1)}

cmap = sns.color_palette("cividis")

fig, (ax0,ax1) = plt.subplots(2, 1, sharex=True, sharey=True, figsize=(10,7))

#fig, ax = plt.subplots(figsize=(10,10))
ax0 = sns.heatmap([words_pol], cmap='cividis', cbar_kws={'label': 'Polarity', 'orientation': 'vertical'}, ax=ax0)
ax1 = sns.heatmap([words_sub], cmap='cividis', cbar_kws={'label': 'Subjectivity', 'orientation': 'vertical'}, ax=ax1)

#ax.set_xlabel(r'Sentences')
#ax.xaxis.label.set_fontsize(20)

labels = [item.get_text() for item in ax.get_yticklabels()]
labels[0] = ''
#labels[1] = 'Subjectivity'
ax0.set_yticklabels(labels, fontsize=18)

#plt.xticks(np.arange(0, len(sentence_pol)+1, 1.0))
ax0.tick_params(top=False, bottom=False, left=False, right=False, labelleft=True, labelbottom=False)
ax1.tick_params(top=False, bottom=False, left=False, right=False, labelleft=True, labelbottom=False)

ax1.set_xlabel('Words')
#ax0.set_xlabel('Sentences')

#ax1.figure.axes[-1].yaxis.label.set_size(20)


plt.subplots_adjust(wspace=0.01, hspace=0)

plt.tight_layout()

fig.savefig("Phoebe_song_sentiment_words.png")

sns.regplot(x = "Polarity", y = "Subjectivity", data = df_words[df_words['Polarity']<0], color='black')
sns.regplot(x = "Polarity", y = "Subjectivity", data = df_words[df_words['Polarity']>0], color='purple')

plt.plot(df_words['Polarity'], df_words['Subjectivity'], 'kD',color='grey', zorder=-10)

plt.xlabel('Polarity')
plt.ylabel('Subjectivity')
plt.ylim(0, 1.2)<jupyter_output><empty_output><jupyter_text>Sentences<jupyter_code>n=20
sns.set(font_scale=1.2)
#map = {i: i for i in range(-1, 1, 0.1)}

cmap = sns.color_palette("cividis")

fig, (ax0,ax1) = plt.subplots(2, 1, sharex=True, sharey=True, figsize=(10,7))

#fig, ax = plt.subplots(figsize=(10,10))
ax0 = sns.heatmap([sentence_pol], cmap='cividis', cbar_kws={'label': 'Polarity', 'orientation': 'vertical'}, ax=ax0)
ax1 = sns.heatmap([sentence_sub], cmap='cividis', cbar_kws={'label': 'Subjectivity', 'orientation': 'vertical'}, ax=ax1)

#ax.set_xlabel(r'Sentences')
#ax.xaxis.label.set_fontsize(20)

labels = [item.get_text() for item in ax.get_yticklabels()]
labels[0] = ''
#labels[1] = 'Subjectivity'
ax0.set_yticklabels(labels, fontsize=18)

#plt.xticks(np.arange(0, len(sentence_pol)+1, 1.0))
ax0.tick_params(top=False, bottom=False, left=False, right=False, labelleft=True, labelbottom=False)
ax1.tick_params(top=False, bottom=False, left=False, right=False, labelleft=True, labelbottom=False)

ax1.set_xlabel('Sentences')
#ax0.set_xlabel('Sentences')

#ax1.figure.axes[-1].yaxis.label.set_size(20)


plt.subplots_adjust(wspace=0.01, hspace=0)

plt.tight_layout()

fig.savefig("Phoebe_song_sentiment.png")

df_pol_sub = pd.DataFrame({'Pol': sentence_pol,
                  'Sub': sentence_sub})

df_pol_sub.describe()
df_pol_sub['Pol'][ df_pol_sub['Pol']>0].corr(df_pol_sub['Sub'][df_pol_sub['Pol']>0])
df_pol_sub['Pol'][ df_pol_sub['Pol']<0].corr(df_pol_sub['Sub'][df_pol_sub['Pol']<0])
sns.regplot(x = "Pol", y = "Sub", data = df_pol_sub[df_pol_sub['Pol']<0], color='black')
sns.regplot(x = "Pol", y = "Sub", data = df_pol_sub[df_pol_sub['Pol']>0], color='purple')

plt.plot(df_pol_sub['Pol'][df_pol_sub['Pol']==0], df_pol_sub['Sub'][df_pol_sub['Pol']==0], 'kD', color='grey')


#plt.plot(df_words['Polarity'], df_words['Subjectivity'], 'k*') #Only words, not sentences


plt.xlabel('Polarity')
plt.ylabel('Subjectivity')
plt.ylim(0, 1.2)
sns.regplot(x = "Pol", y = "Sub", data = df_pol_sub, color='grey', order=2)

plt.plot(df_pol_sub['Pol'][df_pol_sub['Pol']==0], df_pol_sub['Sub'][df_pol_sub['Pol']==0], 'ko')

plt.xlabel('Polarity')
plt.ylabel('Subjectivity')
plt.ylim(0, 1.25)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14406184118060436, 'fraction_numerical': 0.01745139376903256, 'mean_word_length': 4.588350785340314, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '401628', 'license': 'MIT', 'n_tokens_mistral': 3270, 'n_tokens_neox': 3117, 'n_words': 720, 'path': 'Sentiment_Phoebes_songs.ipynb', 'repo_name': 'rdzudzar/friends_analysis', 'size': '8538'}