From c751687c16565ba94d0577f9a3bda44e93235bd3 Mon Sep 17 00:00:00 2001 From: LyubomirT Date: Sun, 26 Nov 2023 15:50:44 +0200 Subject: [PATCH] Improve demo.py, add demo configuration --- ac/__init__.py | 0 autocorrect.py => ac/autocorrect.py | 0 demo.py | 17 +++++++++++++++-- demo_config | 1 + 4 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 ac/__init__.py rename autocorrect.py => ac/autocorrect.py (100%) create mode 100644 demo_config diff --git a/ac/__init__.py b/ac/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/autocorrect.py b/ac/autocorrect.py similarity index 100% rename from autocorrect.py rename to ac/autocorrect.py diff --git a/demo.py b/demo.py index 5589502..0781cc6 100644 --- a/demo.py +++ b/demo.py @@ -1,4 +1,13 @@ -from main import is_correct, get_similar +from ac.autocorrect import is_correct, get_similar + +def load_config(): + with open("demo_config", "r") as f: + config = f.read() + return config + +config = load_config() +# showallsimilarities="True" +showallsimilarities = config.split("showallsimilarities=\"")[1].split("\"")[0] def demo(): while True: @@ -7,9 +16,13 @@ def demo(): print("Correct!") else: print("Incorrect!") - similar = get_similar(word, 0.7, chunks=20, upto=5) + similar = get_similar(word, 0.5, chunks=20, upto=5) if similar == 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 + "\"?") diff --git a/demo_config b/demo_config new file mode 100644 index 0000000..43cb153 --- /dev/null +++ b/demo_config @@ -0,0 +1 @@ +showallsimilarities="True" \ No newline at end of file