-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
44 lines (42 loc) · 1.1 KB
/
__init__.py
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
40
41
42
43
44
import enchant
import context
def check(sentence):
c = context.Context()
corrected = ""
d = enchant.Dict("en_US")
words = sentence.split()
for word in words:
if d.check(word):
c.addWord(word)
else:
c.addWord('')
#print "[Context] red words are "
#print c.lastwords
for i in range(len(words)):
word=words[i]
if len(corrected):
corrected += " "
if d.check(word):
corrected += word
else:
possible = d.suggest(word)
chosen = c.getBestWord(possible,i)
c.addWord(chosen,i)
corrected += chosen
#print "[Context] final words are "
#print c.lastwords
return corrected
def dumbcheck(sentence):
c = context.Context()
corrected = ""
d = enchant.Dict("en_US")
words = sentence.split()
for word in words:
if len(corrected):
corrected += " "
if d.check(word):
corrected += word
else:
chosen = d.suggest(word)[0]
corrected += chosen
return corrected