-
Notifications
You must be signed in to change notification settings - Fork 6
/
C137.py
63 lines (45 loc) · 1.57 KB
/
C137.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import os
import json
import matplotlib.pyplot as plt
import numpy as np
from PIL import Image
from wordcloud import WordCloud
import data_preprocessing_shit as dps
from nltk.collocations import BigramAssocMeasures, BigramCollocationFinder
import nltk
import random
from operator import itemgetter
with open('processed_files/rick.json') as jd:
rick = json.load(jd)
with open('processed_files/morty.json') as jd:
morty = json.load(jd)
def make_wordcloud(text):
# rickmask = np.array(Image.open('rick.png'))
wordcloud = WordCloud(max_words=2000, max_font_size=50).generate(text)
plt.figure(figsize=(16, 12))
plt.imshow(wordcloud)
plt.axis("off")
# plt.tight_layout(pad=5)
plt.savefig('mortycloud.png', dpi=800)
# plt.show()
return True
def bigram_cloud(toks):
finder = BigramCollocationFinder.from_words(toks)
bigram_measures = BigramAssocMeasures()
scored = finder.score_ngrams(bigram_measures.raw_freq)
scoredList = sorted(scored, key=itemgetter(1), reverse=True)
word_dict = {}
listLen = len(scoredList)
for i in range(listLen):
word_dict['_'.join(scoredList[i][0])] = scoredList[i][1]
WC_height = 500
WC_width = 1000
WC_max_words = 100
wordCloud = WordCloud(max_words=WC_max_words, height=WC_height, width=WC_width)
wordCloud.generate_from_frequencies(word_dict)
plt.title('Most frequently occurring bigrams connected with an underscore_')
plt.imshow(wordCloud, interpolation='bilinear')
plt.axis("off")
plt.show()
text = morty['morty']
make_wordcloud(text)