forked from shehzad-hathi/SpellNazi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plausibleWords.py
35 lines (27 loc) · 914 Bytes
/
plausibleWords.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
import metaphone
def plausibleWords(incorrectWord):
USengDict = open("enUS.txt","r")
GBengDict = open("enGB.txt","r")
phoneticDictUS = open("metaphonicDictUS.txt","r")
phoneticDictGB = open("metaphonicDictGB.txt","r")
temp = (metaphone.dm(incorrectWord))[0]
plausibleList = []
plausibleListTemp = []
ctr = 0
for line in phoneticDictUS:
if line[:-1] == temp:
plausibleListTemp.append((ctr,"USprimary"))
ctr = ctr + 1
ctr = 0
for line in phoneticDictGB:
if line[:-1] == temp:
plausibleListTemp.append((ctr,"GBprimary"))
ctr = ctr + 1
linesUS = USengDict.readlines()
linesGB = GBengDict.readlines()
for i in xrange(len(plausibleListTemp)):
if plausibleListTemp[i][1] == "USprimary":
plausibleList.append(linesUS[plausibleListTemp[i][0]][:-1])
else:
plausibleList.append(linesGB[plausibleListTemp[i][0]][:-1])
return plausibleList