Elalimy commited on
Commit
74bad15
1 Parent(s): bd75cc4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -101,13 +101,14 @@ def editTwoLetters(word, allowSwitches=True):
101
  return editTwoSet
102
 
103
 
104
- def getCorrections(word, probablity, vocabulary):
105
- suggestion = []
106
- n_best = []
107
  suggestions = list((word in vocabulary and word) or editOneLetter(word).intersection(vocabulary) or editTwoLetters(
108
  word).intersection(vocabulary))
109
- n_best = [[s, probablity[s]] for s in list(reversed(suggestions))]
110
- return n_best
 
 
111
 
112
 
113
  @app.route('/')
 
101
  return editTwoSet
102
 
103
 
104
+ def getCorrections(word, probablity, vocabulary, max_suggestions=6):
105
+ suggestions = []
 
106
  suggestions = list((word in vocabulary and word) or editOneLetter(word).intersection(vocabulary) or editTwoLetters(
107
  word).intersection(vocabulary))
108
+ suggestions_with_prob = [[s, probablity[s]] for s in list(reversed(suggestions))]
109
+ suggestions_with_prob.sort(key=lambda x: x[1], reverse=True)
110
+ top_suggestions = suggestions_with_prob[:max_suggestions]
111
+ return top_suggestions
112
 
113
 
114
  @app.route('/')