EDC_IE / postt.py
dexay's picture
Create new file
4a68892
raw
history blame
1.94 kB
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