@@ -30,36 +30,46 @@ def get_args():
30
30
if os .path .isfile (args .text ):
31
31
lines = []
32
32
for line in open (args .text ):
33
- lines .append (line .strip ())
33
+ lines .append (line .rstrip ())
34
34
35
35
args .text = '\n ' .join (lines )
36
36
return args
37
37
38
38
def fry (word ):
39
- pattern1 = '([yY])(ou)([\W]*$)'
40
- m = re .match (pattern1 , word )
41
-
42
39
40
+ pattern1 = "([yY])(ou)([\W][" + string .ascii_letters + "]*)"
41
+ m = re .match (pattern1 , word )
43
42
44
43
if m :
45
44
g = m .groups ()
45
+ # print(g)
46
+ if g [2 ]:
47
+ end = g [2 ]
48
+ else :
49
+ end = ''
46
50
if g [0 ] and g [1 ]:
47
- return f"{ g [0 ]} 'all"
51
+ return f"{ g [0 ]} 'all" + end
52
+
53
+ pattern3 = "([yY])(ou)$"
54
+ m = re .match (pattern3 , word )
55
+ if m :
56
+ g = m .groups ()
57
+ return f"{ g [0 ]} 'all"
48
58
49
59
vowels = 'aeuoiAEUOI'
50
60
consonants = '' .join (filter (lambda e : e not in vowels , string .ascii_letters ))
51
- pattern2 = "([" + consonants + "]*)([" + vowels + "]+)[^']([" + consonants + "]*)(ing)(\W)?"
61
+ pattern2 = "([" + string . ascii_letters + "]*)(ing)(\W)?"
52
62
53
63
m = re .match (pattern2 , word )
54
64
if m :
55
65
g = m .groups ()
56
- print (g )
57
- if g [4 ]:
58
- end = g [4 ]
66
+ # print(g)
67
+ if g [2 ]:
68
+ end = g [2 ]
59
69
else :
60
70
end = ''
61
- if g [ 1 ] :
62
- return '' .join (g [: 3 ])+ "in'" + end
71
+ if len ( list ( filter ( lambda e : e in vowels , g [ 0 ]))) > 0 :
72
+ return '' .join (g [0 ])+ "in'" + end
63
73
64
74
return word
65
75
@@ -77,7 +87,9 @@ def main():
77
87
text = args .text
78
88
79
89
for line in args .text .splitlines ():
80
- print (' ' .join ([fry (w ) for w in line .split ()]))
90
+ # print(line)
91
+ # print(re.split('\s', line))
92
+ print (' ' .join ([fry (w ) for w in re .split ('\s' , line )]))
81
93
82
94
83
95
0 commit comments