forked from aadijain/graham-engine
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathspelling_correction.py
More file actions
39 lines (36 loc) · 1.1 KB
/
spelling_correction.py
File metadata and controls
39 lines (36 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from textblob import Word
def onlyspellcorrection(query_tokens):
"Corrects the spelling errors in the query"
corrected_query = []
for t in query_tokens:
w = Word(t)
a = w.correct()
corrected_query.append(a)
if cmp(corrected_query,query_tokens)==0:
return query_tokens
else:
s = ""
for i in corrected_query:
s += i
s += " "
print "Did you mean: " + s + "?"
def spellcorrection(query_tokens):
"Corrects the spelling errors in the query"
corrected_query = []
for t in query_tokens:
w = Word(t)
a = w.correct()
corrected_query.append(a)
if cmp(corrected_query,query_tokens)==0:
return query_tokens
else:
s = ""
for i in corrected_query:
s += i
s += " "
print "Did you mean: " + s + "?"
choice = int(raw_input("Press 1 to continue with the original query, otherwise Press 0\n"))
if choice==0:
return corrected_query
else:
return query_tokens