# import matplotlib.pyplot as plt # from PIL import Image # from wordcloud import STOPWORDS, WordCloud from dict_dl import Dictionary d = Dictionary("en_merriam_webster/", "_mw.json") # d = Dictionary("en_MW_thesaurus/", "_mwt.json") # d = Dictionary("de_duden/", "_duden.json") print(f"{d.readtime:.06f}") # print([k for k in d if not all([c in string.ascii_letters for c in k])]) print([k for k in d if "?" in k]) exit() again = set() for k,v in d.items(): for ke,di in v.items(): if ke != "type": if "related" in di: again.add(k) print(again, len(again)) with open(f"{d.dir_prefix}redo", "at") as f: f.write("\n".join(list(again))) exit() 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(os.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)