dict_dl/analysis.py

87 lines
2.2 KiB
Python
Raw Normal View History

2023-09-05 14:00:29 +00:00
from dict_dl import FullDictionary
2022-07-07 07:12:37 +00:00
# import matplotlib.pyplot as plt
# from PIL import Image
# from wordcloud import STOPWORDS, WordCloud
2023-09-05 14:00:29 +00:00
d = FullDictionary("en_MerriamWebster/", "_MW.json")
2022-07-10 02:48:14 +00:00
# d = Dictionary("en_MW_thesaurus/", "_mwt.json")
2022-07-07 07:12:37 +00:00
# d = Dictionary("de_duden/", "_duden.json")
print(f"{d.readtime:.06f}")
2022-07-08 10:43:24 +00:00
2023-09-05 14:00:29 +00:00
print(
sorted(
[
k
for k in d
if not any([c in ["a", "e", "i", "o", "u", "_"] for c in k.lower()])
and len(k) > 2
and k[-1] not in string.ascii_uppercase
]
)
)
2022-07-10 02:48:14 +00:00
# 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()
2022-07-08 15:42:29 +00:00
again = set()
2022-07-10 04:35:09 +00:00
for k, v in d.items():
for ke, di in v.items():
if ke != "type":
2022-07-08 15:42:29 +00:00
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)))
2022-07-07 07:12:37 +00:00
exit()
2022-07-08 10:43:24 +00:00
2022-07-10 04:35:09 +00:00
2022-07-07 07:12:37 +00:00
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)