fix MW word history

This commit is contained in:
julius 2022-12-09 19:13:03 +00:00
parent f65a677cb4
commit 5c5397437c

View File

@ -1,4 +1,5 @@
from dict_dl import Queue, WordParser, cw, ot, rb, uq, uqall from dict_dl import Queue, WordParser, cw, ot, rb, uq, uqall
import itertools
class MerriamWebsterParser(WordParser): class MerriamWebsterParser(WordParser):
@ -63,8 +64,8 @@ class MerriamWebsterParser(WordParser):
@property @property
def first_known_use(self): def first_known_use(self):
uses = {} uses = {}
for e in self.root.findall(".//div[@id='first-known-anchor']"): for e in self.root.findall(".//div[@class='first-known-content-section']"):
for y in e.findall(".//p[@class='ety-sl']"): for y in e.findall(".//p[@class='ety-sl pb-3']"):
uses[ot(y)] = "" uses[ot(y)] = ""
for t, y in zip( for t, y in zip(
e.findall(".//p[@class='function-label']"), e.findall(".//p[@class='function-label']"),
@ -83,7 +84,7 @@ class MerriamWebsterParser(WordParser):
@property @property
def history_and_etymology(self): def history_and_etymology(self):
hande = {} hande = {}
for e in self.root.findall(".//div[@id='etymology-anchor']"): for e in self.root.findall(".//div[@class='etymology-content-section']"):
for y in e.findall(".//p[@class='et']"): for y in e.findall(".//p[@class='et']"):
hande[ot(y)] = "" hande[ot(y)] = ""
for t, y in zip( for t, y in zip(
@ -91,6 +92,7 @@ class MerriamWebsterParser(WordParser):
e.findall(".//p[@class='et']"), e.findall(".//p[@class='et']"),
): ):
hande[ot(y)] = rb(ot(t), "(", ")") hande[ot(y)] = rb(ot(t), "(", ")")
print(hande)
return cw(hande) return cw(hande)
@property @property
@ -131,14 +133,14 @@ class MerriamWebsterParser(WordParser):
) )
# testword = "optimize" testword = "domicile"
# d = MerriamWebsterParser(testword) d = MerriamWebsterParser(testword)
# # print(d.definitions) # print(d.definitions)
# print(d.neighbours) print(d.neighbours)
# word_dict = d.todict() word_dict = d.todict()
# for k, v in word_dict[testword].items(): for k, v in word_dict[testword].items():
# print(f"### {k} ###\n", v) print(f"### {k} ###\n", v)
# exit() exit()
q = Queue(MerriamWebsterParser, "en_MerriamWebster/", "_MW.json") q = Queue(MerriamWebsterParser, "en_MerriamWebster/", "_MW.json")
q.loadDB() q.loadDB()