Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -101,13 +101,14 @@ def editTwoLetters(word, allowSwitches=True):
|
|
| 101 |
return editTwoSet
|
| 102 |
|
| 103 |
|
| 104 |
-
def getCorrections(word, probablity, vocabulary):
|
| 105 |
-
|
| 106 |
-
n_best = []
|
| 107 |
suggestions = list((word in vocabulary and word) or editOneLetter(word).intersection(vocabulary) or editTwoLetters(
|
| 108 |
word).intersection(vocabulary))
|
| 109 |
-
|
| 110 |
-
|
|
|
|
|
|
|
| 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('/')
|