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