File size: 3,146 Bytes
a985cef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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
 
 
def precor(text):
    lines = text
    lines = lines.replace("breast and prostate cancer","breast cancer and prostate cancer")
    lines = lines.replace("prostate and breast cancer","prostate cancer and breast cancer")
    lines = lines.replace("breast, prostate and ovarian cancer","breast cancer, prostate cancer and ovarian cancer")
    lines = re.sub(r"\[\d*\]", "", lines)  # notes
    lines = re.sub(r'\(\s?(figure|Figure|table|Table|fig\.|Fig\.|tab\.|Tab\.)(\s?\w)*\s?\)',"", lines)  # (figure)|(table)
    lines = re.sub(r'www\.(?:[-\w.]|(?:%[\da-fA-F]{2}))+', "", lines)  # www.ex.com
    lines = re.sub(r'https?://(?:[-\w.]|(?:%[\da-fA-F]{2}))+', "", lines)  # http urls
    lines = re.sub(r'[a-zA-Z0-9]+[_\-.]*[a-zA-Z0-9]*@[a-zA-Z0-9]+\.\w+', "", lines)  # emails
    lines = re.sub(r'\(\)', "", lines)
    lines = re.sub(r'\[\s?[0-9]+(\–|,|\-)\s?[0-9]+\s?\]', "", lines)
    lines = re.sub(r'\(\s?[0-9]+(\–|,|\-)\s?[0-9]+\s?\)', "", lines)
    lines = re.sub(r'\[\s?[0-9]+(\–|,|\-)?\s?[0-9]*\s?\]', "", lines)
    lines = re.sub(r'\(\s?[0-9]+(\–|,|\-)?\s?[0-9]*\s?\)', "", lines)
    punc = ";.,?([)]"
    for e in punc:
        lines = lines.replace(e, " "+e+" ")
    return lines