Skip to content

Commit

Permalink
Fixed indentation issues
Browse files Browse the repository at this point in the history
  • Loading branch information
minimaxir committed May 7, 2016
1 parent e9e4056 commit faabc08
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 40 deletions.
7 changes: 3 additions & 4 deletions wordcloud_cnn.py
Expand Up @@ -5,7 +5,6 @@
from wordcloud import WordCloud, STOPWORDS
from palettable.colorbrewer.qualitative import Dark2_8


def color_func(word, font_size, position, orientation, random_state=None, **kwargs):
return tuple(Dark2_8.colors[random.randint(0,7)])

Expand All @@ -17,9 +16,9 @@ def color_func(word, font_size, position, orientation, random_state=None, **kwar

message = ''
with open(csv_path, 'rb') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
message += " " + row['link_name']
reader = csv.DictReader(csvfile)
for row in reader:
message += " " + row['link_name']

# http://stackoverflow.com/questions/7911451/pil-convert-png-or-gif-with-transparency-to-jpg-without
icon_path = fa_path + "%s.png" % icon
Expand Down
29 changes: 14 additions & 15 deletions wordcloud_cnn_reactions.py
Expand Up @@ -42,27 +42,26 @@
mask.putpixel((x, y), (r, g, b))

# create coloring from image
mask.save('test2.jpg')
image_colors = ImageColorGenerator(np.array(mask))

pattern = re.compile("[^\w']")
tokens_dict = {}

with open(csv_path, 'rb') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
text = row['link_name'].lower()
reactions = int(row['num_reactions'])
# Map each reactions count to a word,
# e.g.: {'futurist': [6599], 'ditch': [4667, 936, 298]}
tokens = pattern.sub(' ', text).split()
for token in tokens:
if token not in tokens_dict.keys():
tokens_dict[token] = [reactions]
else:
tokens_dict[token].append(reactions)
reader = csv.DictReader(csvfile)
for row in reader:
text = row['link_name'].lower()
reactions = int(row['num_reactions'])

# Map each reactions count to a word,
# e.g.: {'futurist': [6599], 'ditch': [4667, 936, 298]}

tokens = pattern.sub(' ', text).split()
for token in tokens:
if token not in tokens_dict.keys():
tokens_dict[token] = [reactions]
else:
tokens_dict[token].append(reactions)

# Calculate the average amount of reactions for headlines containing word
words_dict = [(k, np.mean(np.array(v))) for k, v in tokens_dict.items() if len(v) >= 20]
Expand Down
9 changes: 4 additions & 5 deletions wordcloud_dataisbeautiful.py
Expand Up @@ -4,7 +4,6 @@
from PIL import Image
from wordcloud import WordCloud, STOPWORDS


def grey_color_func(word, font_size, position, orientation, random_state=None, **kwargs):
return "hsl(0, 0%%, %d%%)" % random.randint(10, 50)

Expand All @@ -16,10 +15,10 @@ def grey_color_func(word, font_size, position, orientation, random_state=None, *

words_array = []
with open(csv_path, 'rb') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
if row['word'] not in STOPWORDS:
words_array.append((row['word'].upper(), float(row['num_words'])))
reader = csv.DictReader(csvfile)
for row in reader:
if row['word'] not in STOPWORDS:
words_array.append((row['word'].upper(), float(row['num_words'])))

# http://stackoverflow.com/questions/7911451/pil-convert-png-or-gif-with-transparency-to-jpg-without
icon_path = fa_path + "%s.png" % icon
Expand Down
10 changes: 4 additions & 6 deletions wordcloud_github.py
Expand Up @@ -4,7 +4,6 @@
from PIL import Image
from wordcloud import WordCloud, STOPWORDS


def grey_color_func(word, font_size, position, orientation, random_state=None, **kwargs):
return "hsl(0, 0%%, %d%%)" % random.randint(10, 50)

Expand All @@ -14,13 +13,12 @@ def grey_color_func(word, font_size, position, orientation, random_state=None, *

icon = "github"


words_array = []
with open(csv_path, 'rb') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
if row['word'] not in STOPWORDS:
words_array.append((row['word'].upper(), float(row['num_words'])))
reader = csv.DictReader(csvfile)
for row in reader:
if row['word'] not in STOPWORDS:
words_array.append((row['word'].upper(), float(row['num_words'])))

# http://stackoverflow.com/questions/7911451/pil-convert-png-or-gif-with-transparency-to-jpg-without
icon_path = fa_path + "%s.png" % icon
Expand Down
9 changes: 4 additions & 5 deletions wordcloud_yelp_neg.py
Expand Up @@ -5,7 +5,6 @@
from wordcloud import WordCloud, STOPWORDS
from palettable.colorbrewer.sequential import Reds_9


def color_func(word, font_size, position, orientation, random_state=None, **kwargs):
return tuple(Reds_9.colors[random.randint(2,8)])

Expand All @@ -17,10 +16,10 @@ def color_func(word, font_size, position, orientation, random_state=None, **kwar

words_array = []
with open(csv_path, 'rb') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
if row['stars'] is '1' and row['word'] not in STOPWORDS:
words_array.append((row['word'].upper(), float(row['count'])))
reader = csv.DictReader(csvfile)
for row in reader:
if row['stars'] is '1' and row['word'] not in STOPWORDS:
words_array.append((row['word'].upper(), float(row['count'])))

# http://stackoverflow.com/questions/7911451/pil-convert-png-or-gif-with-transparency-to-jpg-without
icon_path = fa_path + "%s.png" % icon
Expand Down
9 changes: 4 additions & 5 deletions wordcloud_yelp_pos.py
Expand Up @@ -5,7 +5,6 @@
from wordcloud import WordCloud, STOPWORDS
from palettable.colorbrewer.sequential import Greens_9


def color_func(word, font_size, position, orientation, random_state=None, **kwargs):
return tuple(Greens_9.colors[random.randint(2,8)])

Expand All @@ -17,10 +16,10 @@ def color_func(word, font_size, position, orientation, random_state=None, **kwar

words_array = []
with open(csv_path, 'rb') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
if row['stars'] is '5' and row['word'] not in STOPWORDS:
words_array.append((row['word'].upper(), float(row['count'])))
reader = csv.DictReader(csvfile)
for row in reader:
if row['stars'] is '5' and row['word'] not in STOPWORDS:
words_array.append((row['word'].upper(), float(row['count'])))

# http://stackoverflow.com/questions/7911451/pil-convert-png-or-gif-with-transparency-to-jpg-without
icon_path = fa_path + "%s.png" % icon
Expand Down

0 comments on commit faabc08

Please sign in to comment.