File size: 1,940 Bytes
4a68892
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import re

def postcor(blist):
    crlist = blist
    remrow = []
    for i in range(len(crlist)-1):
        if len(crlist[i][0]) <= 1 or len(crlist[i][1]) <= 1 or crlist[i][2] == "other":
            remrow += [crlist[i]]
            continue
        xlt = re.findall(r'[a-zA-Z]', crlist[i][0])
        if len(xlt)==0:
            remrow += [crlist[i]]
            continue
        xlt = re.findall(r'[a-zA-Z]', crlist[i][1])
        if len(xlt) == 0:
            remrow += [crlist[i]]
            continue
        

        for j in range(i+1,len(crlist)):
            if re.sub(r"(-|'| |_)", "", crlist[i][0]).lower() == re.sub(r"(-|'| |_)", "", crlist[j][0]).lower():
                if len(crlist[i][0]) < len(crlist[j][0]):
                    crlist[j][0] = crlist[i][0]
                elif len(crlist[i][0]) > len(crlist[j][0]):
                    crlist[i][0] = crlist[j][0]

            if re.sub(r"(-|'| |_)", "", crlist[i][1]).lower() == re.sub(r"(-|'| |_)", "", crlist[j][1]).lower():
                if len(crlist[i][1]) < len(crlist[j][1]):
                    crlist[j][1] = crlist[i][1]
                elif len(crlist[i][1]) > len(crlist[j][1]):
                    crlist[i][1] = crlist[j][1]

            if len(crlist[i][0])-len(crlist[j][0]) == 1 and crlist[j][0] in crlist[i][0] and crlist[i][0][-1] == "s":
                crlist[i][0] = crlist[j][0]
            elif len(crlist[i][0])-len(crlist[j][0]) == -1 and crlist[i][0] in crlist[j][0] and crlist[j][0][-1] == "s":
                crlist[j][0] = crlist[i][0]
            if len(crlist[i][1])-len(crlist[j][1]) == 1 and crlist[j][1] in crlist[i][1] and crlist[i][1][-1] == "s":
                crlist[i][0] = crlist[j][0]
            elif len(crlist[i][1])-len(crlist[j][1]) == -1 and crlist[i][1] in crlist[j][1] and crlist[j][1][-1] == "s":
                crlist[j][1] = crlist[i][1]

    for rw in remrow:
        crlist.remove(rw)
    
    return crlist