-
Notifications
You must be signed in to change notification settings - Fork 5
/
demo.py
43 lines (37 loc) · 1.35 KB
/
demo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from lesp.autocorrect import Proofreader
def load_config():
try:
with open("demo_config", "r") as f:
config = f.read()
return config
except FileNotFoundError:
raise FileNotFoundError("demo_config not found!")
try:
config = load_config()
except FileNotFoundError as error:
print(error)
exit()
# showallsimilarities="True"
showallsimilarities = config.split("showallsimilarities=\"")[1].split("\"")[0]
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=wordlist_path)
while True:
word = input("Enter a word: ")
if proofreader.is_correct(word):
print("Correct!")
else:
print("Incorrect!")
similar = proofreader.get_similar(word, 0.5, chunks=20, upto=5, set_cache=True, use_cache=True)
if similar is None:
print("No similar words found.")
elif showallsimilarities == "True":
print("Did you mean any of the following?")
for w in similar:
print("\"" + w + "\"")
else:
similar = similar[0]
print("Did you mean \"" + similar + "\"?")
print()
if __name__ == "__main__":
demo()