Commit | Line | Data |
---|---|---|
265d3d9a SBS |
1 | #!/bin/bash |
2 | ||
3 | # Function to replace contractions | |
0736b7d0 | 4 | function replace_apos() { |
265d3d9a SBS |
5 | # Desc: Replace ' with ʼ in contractions |
6 | # Note: In contractions of UTF-8 text file, replaces U+0027 | |
7 | # APOSTROPHE with U+02BC MODIFIER LETTER APOSTROPHE | |
39496272 | 8 | # Input: stdin |
265d3d9a SBS |
9 | # arg1 file path |
10 | # Output: stdout | |
0736b7d0 | 11 | # Version: 1.1.1 (BK-2020-03) |
265d3d9a SBS |
12 | # Depends: GNU sed 4.8 |
13 | ||
14 | # Check input | |
15 | if [[ "$#" -gt 1 ]]; then | |
16 | echo "FATAL:Incorrect argument count:$#" 1>&2; | |
17 | return 1; | |
18 | fi; | |
19 | ||
20 | if [[ -f "$1" ]]; then | |
21 | # Use specified file | |
22 | input="$1"; | |
23 | else | |
24 | # Use standard input | |
25 | input="-"; | |
26 | fi; | |
27 | ||
28 | # Perform substitutions | |
7e653610 SBS |
29 | ## Note: See https://en.wiktionary.org/wiki/Category:English_contractions |
30 | ## Note: Order of replacements sorted most-specific first. | |
265d3d9a | 31 | sed -E \ |
7e653610 SBS |
32 | -e "s/(you|You|YOU)'(ren|REN|ven|VEN)'(t|T)/\1ʼ\2ʼ\3/g" \ |
33 | -e "s/(you|You|YOU)'(dn|DN)'(t|T)'(ve|VE)/\1ʼ\2ʼ\3ʼ\4/g" \ | |
34 | -e "s/(you|You|YOU)'(d|D|ll|LL)'(ve|VE)/\1ʼ\2ʼ\3/g" \ | |
35 | -e "s/(you|You|YOU)'(d|D|ll|LL|re|RE|ve|VE)/\1ʼ\2/g" \ | |
36 | -e "s/(y|Y)'(all|ALL)'(dn|DN)'(t|T)'(ve|VE)/\1ʼ\2ʼ\3ʼ\4ʼ\5/g" \ | |
37 | -e "s/(y|Y)'(all|ALL)'(d|D)'(nt|NT)'(ve|VE)/\1ʼ\2ʼ\3ʼ\4ʼ\5/g" \ | |
38 | -e "s/(y|Y)'(all|ALL)'(d|D)'(ve|VE)/\1ʼ\2ʼ\3ʼ\4/g" \ | |
39 | -e "s/(y|Y)'(all|ALL)'(d|D|ll|LL|re|RE|ve|VE)/\1ʼ\2ʼ\3/g" \ | |
40 | -e "s/(y|Y)'(all|ALL)/\1ʼ\2/g" \ | |
41 | -e "s/(y|Y)'(ain|AIN)'(t|T)/\1ʼ\2ʼ\3/g" \ | |
42 | -e "s/(wouldn|Wouldn|WOULDN)'(t|T)'(ve|VE)/\1ʼ\2ʼ\3/g" \ | |
43 | -e "s/(wouldn|Wouldn|WOULDN)'(t|T)/\1ʼ\2/g" \ | |
44 | -e "s/(won|Won|WON)'(t|T)'(ve|VE)/\1ʼ\2ʼ\3/g" \ | |
45 | -e "s/(won|Won|WON)'(t|T)/\1ʼ\2/g" \ | |
46 | -e "s/(who|Who|WHO)'(d|D|ll|LL)'(ve|VE)/\1ʼ\2ʼ\3/g" \ | |
47 | -e "s/(who|Who|WHO)'(d|D|ll|LL|re|RE|s|S|ve|VE)/\1ʼ\2/g" \ | |
eb9061ae | 48 | -e "s/(where|Where|WHERE)'(d|D|s|S)/\1ʼ\2/g" \ |
7e653610 SBS |
49 | -e "s/(what|What|WHAT)'(ll|LL|re|RE|s|S|ve|VE)/\1ʼ\2/g" \ |
50 | -e "s/(weren|Weren|WEREN)'(t|T)/\1ʼ\2/g" \ | |
51 | -e "s/(we|We|WE)'(ven|VEN)'(t|T)/\1ʼ\2ʼ\3/g" \ | |
52 | -e "s/(we|We|WE)'(ren|REN)'(t|T)/\1ʼ\2ʼ\3/g" \ | |
53 | -e "s/(we|We|WE)'(d|D|ll|LL)'(ve|VE)/\1ʼ\2ʼ\3/g" \ | |
54 | -e "s/(we|We|WE)'(d|D|ll|LL|re|RE|ve|VE)/\1ʼ\2/g" \ | |
eb9061ae | 55 | -e "s/(wasn|Wasn|WASN)'(t|T)/\1ʼ\2/g" \ |
7e653610 SBS |
56 | -e "s/(they|They|THEY)'(d|D|ll|LL)'(ve|VE)/\1ʼ\2ʼ\3/g" \ |
57 | -e "s/(they|They|THEY)'(d|D|ll|LL|re|RE|ve|VE)/\1ʼ\2/g" \ | |
58 | -e "s/(there|There|THERE)'(ll|LL)'(ve|VE)/\1ʼ\2ʼ\3/g" \ | |
59 | -e "s/(there|There|THERE)'(s|S|ve|VE)/\1ʼ\2/g" \ | |
60 | -e "s/(that|That|THAT)'(d|D|ll|LL)'(ve|VE)/\1ʼ\2ʼ\3/g" \ | |
61 | -e "s/(that|That|THAT)'(d|D|ll|LL|s|S)/\1ʼ\2/g" \ | |
62 | -e "s/(shouldn|Shouldn|SHOULDN)'(t|T)'(ve|VE)/\1ʼ\2ʼ\3/g" \ | |
63 | -e "s/(shouldn|Shouldn|SHOULDN)'(t|T)/\1ʼ\2/g" \ | |
64 | -e "s/(she|She|SHE)'(d|D|ll|LL)'(ve|VE)/\1ʼ\2ʼ\3/g" \ | |
65 | -e "s/(she|She|SHE)'(d|D|ll|LL|s|S)/\1ʼ\2/g" \ | |
66 | -e "s/(shan|Shan|SHAN)'(t|T)/\1ʼ\2/g" \ | |
e424b710 SBS |
67 | -e "s/'(s|S)\b/ʼ\1/g" \ |
68 | -e "s/(s|S)'( |$)/\1ʼ\2/g" \ | |
7e653610 SBS |
69 | -e "s/(oughtn|Oughtn|OUGHTN)'(t|T)'(ve|VE)/\1ʼ\2ʼ\3/g" \ |
70 | -e "s/(oughtn|Oughtn|OUGHTN)'(t|T)/\1ʼ\2/g" \ | |
eb9061ae | 71 | -e "s/(o|O)'(clock|CLOCK)/\1ʼ\2/g" \ |
7e653610 SBS |
72 | -e "s/(mustn|Mustn|MUSTN)'(t|T)/\1ʼ\2/g" \ |
73 | -e "s/(mustn|Mustn|MUSTN)'(t|T)'(ve|VE)/\1ʼ\2ʼ\3/g" \ | |
74 | -e "s/(mustn|Mustn|MUSTN)'(t|T)/\1ʼ\2/g" \ | |
75 | -e "s/(mightn|Mightn|MIGHTN)'(t|T)'(ve|VE)/\1ʼ\2ʼ\3/g" \ | |
76 | -e "s/(mightn|Mightn|MIGHTN)'(t|T)/\1ʼ\2/g" \ | |
77 | -e "s/(might|Might|MIGHT)'(ve|VE)/\1ʼ\2/g" \ | |
78 | -e "s/(let|Let|LET)'(s|S)/\1ʼ\2/g" \ | |
79 | -e "s/(it|It|IT)'(d|D|ll|LL)'(ve|VE)/\1ʼ\2ʼ\3/g" \ | |
80 | -e "s/(it|It|IT)'(d|D|ll|LL|s|S)/\1ʼ\2/g" \ | |
81 | -e "s/(isn|Isn|ISN)'(t|T)/\1ʼ\2/g" \ | |
82 | -e "s/(I|i)'(dn|DN)'(t|T)'(ve|VE)/\1ʼ\2ʼ\3ʼ\4/g" \ | |
83 | -e "s/(I|i)'(d|D|ll|LL)'(ve|VE)/\1ʼ\2ʼ\3/g" \ | |
84 | -e "s/(I|i)'(d|D|ll|LL|m|M|ve|VE)/\1ʼ\2/g" \ | |
eb9061ae | 85 | -e "s/(how|How|HOW)'(d|D)/\1ʼ\2/g" \ |
7e653610 SBS |
86 | -e "s/(he|He|HE)'(d|D|ll|LL)'(ve|VE)/\1ʼ\2ʼ\3/g" \ |
87 | -e "s/(he|He|HE)'(d|D|ll|LL|s|S)/\1ʼ\2/g" \ | |
88 | -e "s/(haven|Haven|HAVEN)'(t|T)/\1ʼ\2/g" \ | |
89 | -e "s/(hasn|Hasn|HASN)'(t|T)/\1ʼ\2/g" \ | |
90 | -e "s/(hadn|Hadn|HADN)'(t|T)'(ve|VE)/\1ʼ\2ʼ\3/g" \ | |
91 | -e "s/(hadn|Hadn|HADN)'(t|T)/\1ʼ\2/g" \ | |
eb9061ae | 92 | -e "s/'(em\b)/ʼ\1/g" \ |
7e653610 SBS |
93 | -e "s/(d|D)'(ya|YA|you|YOU)/\1ʼ\2/g" \ |
94 | -e "s/(don|Don|DON)'(t|T)/\1ʼ\2/g" \ | |
95 | -e "s/(doesn|Doesn|DOESN)'(t|T)/\1ʼ\2/g" \ | |
96 | -e "s/(didn|Didn|DIDN)'(t|T)/\1ʼ\2/g" \ | |
97 | -e "s/(could|Could|COULD)'(ve|VE)/\1ʼ\2/g" \ | |
98 | -e "s/(couldn|Couldn|COULDN)'(t|T)'(ve|VE)/\1ʼ\2ʼ\3/g" \ | |
99 | -e "s/(couldn|Couldn|COULDN)'(t|T)/\1ʼ\2/g" \ | |
eb9061ae | 100 | -e "s/(c|C)'(mere|MERE)/\1ʼ\2/g" \ |
7e653610 SBS |
101 | -e "s/(can|Can|CAN)'(t|T)'(ve|VE)/\1ʼ\2ʼ\3/g" \ |
102 | -e "s/(can|Can|CAN)'(t|T)/\1ʼ\2/g" \ | |
eb9061ae SBS |
103 | -e "s/'(cause|Cause|CAUSE)/ʼ\1/g" \ |
104 | -e "s/'(bout|Bout|BOUT)/ʼ\1/g" \ | |
7e653610 SBS |
105 | -e "s/(aren|Aren|AREN)'(t|T)/\1ʼ\2/g" \ |
106 | -e "s/(ate|Ate|ATE)'(nt|NT)/\1ʼ\2/g" \ | |
107 | -e "s/(ain|Ain|AIN)'(t|T)/\1ʼ\2/g" \ | |
108 | "$input" | |
265d3d9a | 109 | }; # replace ' with ʼ in contractions |
4aa4ed1b SBS |
110 | |
111 | # Author: Steven Baltakatei Sandoval | |
112 | # License: GPLv3+ |