-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_me.py
65 lines (37 loc) · 1.38 KB
/
run_me.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
"""This program implements a spell checker"""
#!/usr/bin/env python
__author__ = "plaban nayak"
from lib.BloomFilter import BloomFilter
import sys
if __name__ == "__main__":
print "This program implements a spell checker"
# open the file to read correct words
try:
file_ = open("./list_of_words.txt","r")
except IOError:
print "File containing list of correct words not found"
sys.exit(1)
# read the words from file
words = file_.readlines()
# count the size of bloom filter bit array for minimal false positives
k = 11
n = len(words)
size = int (k * n * 10 / 7)
# create a bloom filter object
bloom_filter = BloomFilter(size)
print "Wait: adding words to dictionary"
for word in words:
word = word.strip("\r\n")
#add words to the Bloom Filter
bloom_filter.add_word(word)
while True:
print "Enter a word to check for spelling or ctrl -c to exit"
try:
word = str(raw_input())
word = word.lower()
if bloom_filter.check_word(word) :
print "Correct"
else:
print "Incorrect"
except KeyboardInterrupt :
sys.exit(1)