From 187676ca846d9cee0101f6ceff494391842f8c15 Mon Sep 17 00:00:00 2001 From: LyubomirT Date: Thu, 7 Dec 2023 12:43:49 +0200 Subject: [PATCH] Critical Bugfix --- .gitignore | 3 ++- demo.py | 2 +- lesp/autocorrect.py | 13 +++++++------ 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 707399c..774ced5 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ __pycache__/ temp/ PYPI.md pypi/ -dist/ \ No newline at end of file +dist/ +demo_gui.py \ No newline at end of file diff --git a/demo.py b/demo.py index 03a4902..0774787 100644 --- a/demo.py +++ b/demo.py @@ -19,7 +19,7 @@ def load_config(): def demo(): wordlist_path = "small_wordlist.txt" # Update with the actual path to your wordlist. Or use the pre-installed small wordlist. - proofreader = Proofreader(wordlist_path) + proofreader = Proofreader(wordlist_path=wordlist_path) while True: word = input("Enter a word: ") diff --git a/lesp/autocorrect.py b/lesp/autocorrect.py index 59dded8..d129640 100644 --- a/lesp/autocorrect.py +++ b/lesp/autocorrect.py @@ -43,13 +43,14 @@ class Proofreader: """ def __init__(self, wordlist_path: str = "lesp-wordlist.txt", cache_file: str = "lesp_cache/lesp.cache") -> None: self.wordlist_path: str = wordlist_path + self.wordlist: List[str] = [] # Initialize as an empty list self.load_wordlist() self.cache_file: str = cache_file self.cache: dict = {} - self.wordlist: List[str] = [] if cache_file: self.load_cache(cache_file) + def load_wordlist(self) -> None: """ Loads a wordlist, also can be used to dynamically switch between wordlists. The wordlist path is based on the wordlist_path attribute of the Proofreader object. @@ -251,7 +252,9 @@ def get_similar(self, word: str, similarity_rate: float, chunks: int = 4, upto: word = word.lower() similar_words: List[str] = [] - chunk_size: int = len(self.wordlist) // chunks + chunk_size = len(self.wordlist) // chunks + + chunks = [(word, similarity_rate, self.wordlist[i:i + chunk_size]) for i in range(0, len(self.wordlist), chunk_size)] if use_cache and self.cache and self.cache_file and word in self.cache: if self.cache[word] != []: @@ -259,10 +262,9 @@ def get_similar(self, word: str, similarity_rate: float, chunks: int = 4, upto: else: return None - chunks: List[tuple] = [(word, similarity_rate, self.wordlist[i:i + chunk_size]) for i in range(0, len(self.wordlist), chunk_size)] - with concurrent.futures.ThreadPoolExecutor() as executor: - results: List[List[str]] = list(executor.map(Proofreader.get_similar_worker, chunks)) + results: List[List[str]] = list(executor.map(Proofreader.get_similar_worker, chunks)) + for similar_word_list in results: similar_words.extend(similar_word_list) @@ -270,7 +272,6 @@ def get_similar(self, word: str, similarity_rate: float, chunks: int = 4, upto: similar_words = list(set(similar_words)) if set_cache and self.cache_file and word not in self.cache: - print("Setting cache for \"" + word + "\"") self.cache[word] = similar_words self.save_cache()