-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspell corection.py
More file actions
72 lines (68 loc) · 2.61 KB
/
spell corection.py
File metadata and controls
72 lines (68 loc) · 2.61 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
def spelling_corrector(s1,s2):
s_org=s1
s1=s1.lower().split()
s2new=[i.lower() for i in s2]
s3=[None]*(len(s1))
for a in s3:
if a == None:
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]
break
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]
break
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]
break
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]
break
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]
break
elif len(i) == len(j):
for k in range(len(j)):
if i[:k] + i[k+1:] == j[:k] + j[k+1:]:
n=s1.index(i)
m=s2new.index(j)
s3[n]=s2new[m]
break
print ('orginal string is: ', s_org)
#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+' '
result=result.strip()
dd=' '.join(s3)
print ('corrective string is: ', result)
print ('and with join commeand: ', ' '.join(s3))
print (dd)
outcome ='we live python'
res = outcome == dd
print (res)
spelling_corrector ('Wee lpve Pythen', ['we', 'Live', 'In', 'Python'])