Skip to content

Commit

Permalink
Refactor wordlist loading and remove duplicates. Delete config.
Browse files Browse the repository at this point in the history
  • Loading branch information
LyubomirT committed Nov 29, 2023
1 parent 6fa98a6 commit 04f8b56
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 0 additions & 1 deletion config

This file was deleted.

6 changes: 5 additions & 1 deletion lesp/autocorrect.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ def __init__(self, wordlist_path="lesp-wordlist.txt"):
def load_wordlist(self):
try:
with open(self.wordlist_path, "r") as f:
self.wordlist = f.read().split("\n")
self.wordlist = f.read().strip().split("\n")
# Remove duplicate words in the wordlist
self.wordlist = list(set(self.wordlist))
# Remove leading and trailing whitespaces from each word
self.wordlist = [word.strip() for word in self.wordlist]
if not all(word.isalpha() for word in self.wordlist):
raise ValueError("Invalid wordlist format. Words must contain only alphabetic characters.")
except FileNotFoundError:
Expand Down

0 comments on commit 04f8b56

Please sign in to comment.