-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathspellchecker.py
49 lines (36 loc) · 1.2 KB
/
spellchecker.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
45
46
47
48
49
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import re
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
# def find(substr, infile, outfile,line_to_write):
# lines = filter(lambda x: substr in x, open(infile))
# if len(lines) > 0:
# open(outfile, 'a').writelines(line_to_write)
delims = "=", ",", "\n"
regexPattern = '|'.join(map(re.escape, delims))
words = []
with open('Greek.dic') as fp:
for line in fp:
word = re.split(regexPattern, line)[0]
words.append(word)
print "finished dict"
f = open('new_el2_wordlist.combined', 'a')
with open('new_el_wordlist.combined') as fp:
for line in fp:
word = re.split(regexPattern, line)[1]
if words.__contains__(word):
f.write(line)
# print word
# find(word, 'Greek.dic', 'new_el2_wordlist.combined',line)
f.close()
print "DONE"
print file_len("new_el2_wordlist.combined")
print file_len("new_el_wordlist.combined")
print "Corrected ", file_len("new_el_wordlist.combined")-file_len("new_el2_wordlist.combined"), " words\n"