Skip to content

Commit

Permalink
Update wordlist path and improve similarity search
Browse files Browse the repository at this point in the history
  • Loading branch information
LyubomirT committed Nov 26, 2023
1 parent 8c75968 commit 933f116
Show file tree
Hide file tree
Showing 4 changed files with 10,012 additions and 6 deletions.
14 changes: 10 additions & 4 deletions main.py → autocorrect.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ def get_similar_worker(args):
similar_words.append(w)
return similar_words

def get_similar(word, similarity_rate, chunks=4):
def get_similar(word, similarity_rate, chunks=4, upto=3):
if upto < 1:
raise ValueError("Can only return 1 or more similar words.")
word = word.lower()
similar_words = []
chunk_size = len(wordlist) // chunks

Expand All @@ -59,7 +62,10 @@ def get_similar(word, similarity_rate, chunks=4):
for similar_word_list in results:
similar_words.extend(similar_word_list)

if similar_words:
return similar_words
similar_words = list(set(similar_words))

if len(similar_words) == 0:
return None
else:
return None
# Return only upto similar words
return similar_words[:upto]
2 changes: 1 addition & 1 deletion config
Original file line number Diff line number Diff line change
@@ -1 +1 @@
wordlist="wordlist.txt"
wordlist="small_wordlist.txt"
2 changes: 1 addition & 1 deletion demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def demo():
print("Correct!")
else:
print("Incorrect!")
similar = get_similar(word, 0.7, chunks=500)
similar = get_similar(word, 0.7, chunks=20, upto=5)
if similar == None:
print("No similar words found.")
else:
Expand Down
Loading

0 comments on commit 933f116

Please sign in to comment.