-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathspellchecker.py
71 lines (62 loc) · 2.11 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#Thank you Steve Barnes, Command Line Spelling Checker
#https://softwarerecs.stackexchange.com/questions/26923/command-line-#spell-check-for-windows
from __future__ import print_function
import sys
import enchant
#import json
import csv
def makeWords(line):
words = line.replace('\"', '')
words = words.replace('*', '')
words = words.replace('#', '')
words = words.replace(';', '')
words = words.replace(':', '')
words = words.replace(',', '')
words = words.replace('?', '')
words = words.replace('.', '')
# words = words.replace('\'', '')
words = words.replace('\\', '')
words = words.replace('/', '')
words = words.replace('!', '')
words = words.replace(')', '')
words = words.replace('(', '')
#words = words.lower()
words = words.split()
return words
ignoreWords = []
with open("spellchecker.exceptions.txt") as fp:
for cnt, line in enumerate(fp):
if (line[:1] == '#'):
continue;
for ignoreWord in makeWords(line):
ignoreWords.append(ignoreWord)
#sys.stdout.write("{ \"Results\":[")
first=True
d = enchant.Dict("en_UK") # or en_US, de_DE, fr_FR, en_AU on my system
for line in sys.stdin:
words = makeWords(line)
for word in words:
ignoreIt = False
if (word[0] == '['):
ignoreIt = True
for ignoreWord in ignoreWords:
if ignoreWord == word:
ignoreIt = True
break
if ignoreIt:
continue;
if not d.check(word):
hint = ' or '.join(d.suggest(word)[:7])
writer = csv.writer(sys.stdout, delimiter=',', quotechar='\"', quoting=csv.QUOTE_MINIMAL)
if (first == True):
writer.writerow([ 'Word' ] + [ 'Hint' ])
first=False
writer.writerow([ word ] + [ hint ])
#data = { 'Word': word, 'Status': 'Failed', 'Hint': hint }
#if (first == False):
# sys.stdout.write(",")
#else:
# first=False
#json.dump(data, sys.stdout)
#sys.stdout.write("]}")
sys.stdout.flush()