-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy patharabicSpellcheck.py
37 lines (27 loc) · 1.05 KB
/
arabicSpellcheck.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
# for this script to work you will need copy the function inside yaraspell/spelldict.py file from https://github.com/linuxscout/yaraspell repo
# all credits to linuxscout/yaraspell
def mainly():
import sys
reload(sys)
sys.setdefaultencoding('utf8')
def file_len(fname):
with open(fname) as f:
for i, l in enumerate(f):
pass
return i + 1
speller = spelldict()
delims = "=",","
regexPattern = '|'.join(map(re.escape, delims))
f = open('ar_wordlist.combined', 'a')
with open('new_ar_wordlist.combined') as fp:
for line in fp:
word = re.split(regexPattern,line)[1]
exists = speller.lookup(word)
# if exists:
# print word.encode("utf8"), "correct"
# else:
# print word.encode("utf8"), "misspelled"
if exists:
f.write(line)
f.close()
print file_len("new_ar_wordlist.combined")-file_len("ar_wordlist.combined"), "corrections"