60 lines
1.5 KiB
Python
60 lines
1.5 KiB
Python
import json
|
|
|
|
with open("a_mw.json", "r") as f:
|
|
mw = json.load(f)
|
|
|
|
import random
|
|
|
|
import matplotlib.pyplot as plt
|
|
from wordcloud import WordCloud
|
|
|
|
|
|
def grey_color_func(
|
|
word, font_size, position, orientation, random_state=None, **kwargs
|
|
):
|
|
return "hsl(0, 0%%, %d%%)" % random.randint(60, 100)
|
|
|
|
|
|
# mask = np.array(Image.open(path.join(d, "stormtrooper_mask.png")))
|
|
word = "abhorrent"
|
|
text = " ".join(mw[word]["synonyms"] + [word])
|
|
|
|
wc = WordCloud(
|
|
max_words=200,
|
|
width=1920,
|
|
height=1080,
|
|
margin=10,
|
|
min_font_size=40,
|
|
max_font_size=100,
|
|
random_state=1,
|
|
).generate(text)
|
|
default_colors = wc.to_array()
|
|
# plt.title("Custom colors")
|
|
# plt.imshow(wc.recolor(color_func=grey_color_func, random_state=3),
|
|
# interpolation="bilinear")
|
|
plt.figure()
|
|
plt.title(word)
|
|
plt.imshow(default_colors, interpolation="bilinear")
|
|
plt.axis("off")
|
|
plt.show()
|
|
exit()
|
|
# letters = {k[0] for k in mw}
|
|
# start = time.time()
|
|
# for c in letters:
|
|
# c_db = {k:v for k,v in mw.items() if k[0] == c}
|
|
# with open(f"{c}_mw.json", "w") as f: # save DB
|
|
# json.dump(c_db, f, separators=(",", ":"), indent=2)
|
|
# print(time.time() - start)
|
|
# exit()
|
|
|
|
# types = {w["word"] for w in mw if not w["history_and_etymology"]}
|
|
types = [w["type"] for w in mw]
|
|
print(len(types))
|
|
|
|
new_mw = {w["word"]: {k: v for k, v in w.items() if k != "word"} for w in mw}
|
|
|
|
print(new_mw)
|
|
print(len(new_mw))
|
|
with open("new_mw.json", "w") as f:
|
|
json.dump(new_mw, f, separators=(",", ":"), indent=2)
|