adjustments for changed prefix_length; FullDictionary

This commit is contained in:
julius 2022-07-10 04:24:31 +00:00
parent da2bb8119a
commit 6cc650af40

View File

@ -1,4 +1,5 @@
import json import json
import os
import random import random
import re import re
import string import string
@ -163,8 +164,11 @@ class FileSet(set):
class DictFile(dict): class DictFile(dict):
def __init__(self, file): def __init__(self, file):
self.file = file self.file = file
with open(self.file, "r") as f: if os.path.isfile(self.file):
super().__init__(json.load(f)) with open(self.file, "r") as f:
super().__init__(json.load(f))
else:
super()
def save(self): def save(self):
with open(self.file, "w") as f: with open(self.file, "w") as f:
@ -191,7 +195,7 @@ class Queue:
suffix, suffix,
time_base=1.01, time_base=1.01,
time_exponent=10, time_exponent=10,
prefix_length=1, prefix_length=3,
): ):
self.__dict__.update(locals()) self.__dict__.update(locals())
self.words = set() self.words = set()
@ -205,9 +209,9 @@ class Queue:
time.sleep(randtime(a, b)) time.sleep(randtime(a, b))
def loadDB(self): def loadDB(self):
for db_file in Path(self.dir_prefix).glob(f"*{self.suffix}"): d = FullDictionary(self.dir_prefix, self.suffix)
with open(db_file, "r") as f: self.words |= set(d.keys())
self.words |= set(json.load(f).keys()) print(d.readtime)
def add_word(self): def add_word(self):
self.redo.load() self.redo.load()
@ -268,5 +272,6 @@ class Queue:
if __name__ == "__main__": if __name__ == "__main__":
f = FileSet("en_merriam_webster/queue") f = FileSet("en_merriam_webster/queue")
d = DictFile("en_merriam_webster/ab_mw.json") # d = DictFile("en_merriam_webster/abc_mw.json")
# d.save()
print(d) print(d)