Skip to content

Commit

Permalink
Loosen suggestion selection requirement to include phonetically simil…
Browse files Browse the repository at this point in the history
…ar words
  • Loading branch information
balasankarc committed Jun 29, 2016
1 parent ab0e808 commit 1185fd3
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions libindic/spellchecker/__init__.py
Expand Up @@ -148,7 +148,7 @@ def suggest(self, input_word, n=10):
for word in possible_words:
lev, sound = self.compare(input_word, word)
suggestion_item = Suggestion(input_word, word, lev, sound)
if lev < 5:
if ((lev < 5 and sound in [0, 1]) or lev < 2):
final.append(suggestion_item)
sorted_list = sorted(final, key=lambda x: x.lev)[:n]
final_list = []
Expand Down Expand Up @@ -201,17 +201,20 @@ def check_and_generate(self, word):
'''
Receives a word as input, checks if it is a valid word and returns
the suggestions if it is not.
Returns 0 along with suggestions if an incorrect word.
Returns 1 along with blank list of suggestions if word in dictionary.
Returns 2 along with blank list of suggestions if word is unique.
'''
status = self.check(word)
if status:
return {'status': True, 'suggestions': []}
return {'status': 1, 'suggestions': []}
else:
suggestions = self.suggest(word)
if suggestions:
return {'status': False, 'suggestions': suggestions}
return {'status': 0, 'suggestions': suggestions}
else:
# If there were no suggestions, it means the word was not
# similar to any of the existing root words. So, that was not a
# mistake, but an intended insertion. Hence, it is deemed as a
# valid word
return {'status': True, 'suggestions': []}
return {'status': 2, 'suggestions': []}

0 comments on commit 1185fd3

Please sign in to comment.