-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestinatom.py
More file actions
49 lines (46 loc) · 1.54 KB
/
testinatom.py
File metadata and controls
49 lines (46 loc) · 1.54 KB
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
def spelling_corrector(s1,s2):
s1=s1.lower().split()
s2new=[i.lower() for i in s2]
s3=[None]*(len(s1))
for i in s1:
if len(i)<=2:
n=s1.index(i)
s3[n]=s1[n]
else:
if i in s2new:
n=s1.index(i)
s3[n]=s1[n]
for j in s2new:
if len(i) - len(j) == -1:
if i == j[:-1] or i == j[1:]:
n=s1.index(i)
m=s2new.index(j)
s3[n]=s2new[m]
else:
for k in range(len(j)):
if i == j[:k] + j[k+1:]:
n=s1.index(i)
m=s2new.index(j)
s3[n]=s2new[m]
elif len(i) - len(j) == 1:
if i[:-1] == j or i[1:] == j:
n=s1.index(i)
m=s2new.index(j)
s3[n]=s2new[m]
else:
for k in range(len(i)):
if j == i[:k] + i[k+1:]:
n=s1.index(i)
m=s2new.index(j)
s3[n]=s2new[m]
print (s3)
for i in s3:
if i == None:
n=s3.index(i)
s3[n]=s1[n]
result=''
for i in s3:
result=result+' '+i
print (result)
return result
spelling_corrector ('Thes is vary essy', ['this', 'is', 'very', 'very', 'easy'])