-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNoVery.html
233 lines (192 loc) · 5.8 KB
/
NoVery.html
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="novery_style.css">
</head>
<body>
<center> <h1> 'very' no more</h1> </center>
<div class="container">
<div class = "left">
<center>
<textarea autofocus type="text" id="input">You can enter text here to remove 'very' from it. Example: "So avoid using the word 'very' because it's lazy. A man is not very tired, he is exhausted. Don't use very sad, use morose. Language was invented for one reason, boys - to woo women - and, in that endeavor, laziness will not do. It also won't do in your essays."</textarea>
<br>
<br>
<button type="button" onclick="myFunction()"> No 'very' please </button>
<br>
<br>
<textarea readonly placeholder = "Output text appears here" type="text" id="output"></textarea>
</center>
</div>
<div class = "right">
<img src = "http://abigailgamble.com/wp-content/uploads/2013/09/tumblr_m7nqacNylf1ry1gtjo1_500.jpg" title = "So avoid using the word 'very' because it's lazy. A man is not very tired, he is exhausted. Don't use very sad, use morose. Language was invented for one reason, boys; to woo women, and in that endeavor laziness will not do! -- N.H. Kleinbaum, Dead Poets Society. Image source : http://abigailgamble.com/wp-content/uploads/2013/09/tumblr_m7nqacNylf1ry1gtjo1_500.jpg" align="left">
</div>
</div>
<script>
ReplacableList = {
'afraid' : 'terrified',
'angry' : 'furious',
'bad' : 'atrocious',
'beautiful' : 'exquisite',
'big' : 'immense',
'bright' : 'dazzling',
'capable' : 'accomplished',
'clean' : 'spotless',
'clever' : 'brilliant',
'cold' : 'freezing',
'conventional' : 'conservative',
'dirty' : 'squalid',
'dry' : 'parched',
'eager' : 'keen',
'fast' : 'quick',
'fierce' : 'ferocious',
'good' : 'superb',
'happy' : 'jubilant',
'hot' : 'scalding',
'hungry' : 'ravenous',
'large' : 'colossal',
'lively' : 'vivacious',
'loved' : 'adored',
'neat' : 'immaculatd',
'old' : 'ancient',
'poor' : 'destitute',
'pretty' : 'beautiful',
'quiet' : 'silent',
'risky' : 'perilous',
'roomy' : 'spacious',
'rude' : 'vulgar',
'sad' : 'morose',
'serious' : 'solemn',
'small' : 'tiny',
'strong' : 'unyielding',
'stupid' : 'idiotic',
'tasty' : 'delicious',
'thin' : 'gaunt',
'tired' : 'exhausted',
'ugly' : 'hideous',
'valuable' : 'precious',
'weak' : 'feeble',
'wet' : 'soaked',
'wicked' : 'villainous',
'wise' : 'sagacious',
'worried' : 'anxious'
};
FalseStarts = ["'", '"', '(', '—', '-']; // characters that can appear before very
FalseStops = ['.', ',', '!', '?', ':', ';', '"', "'", '-', '—', ')', '(']; // Characters that can appear after the word to be replaced
function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
function getCanonical_first(word){
var pos = -1;
for (var i = 0; i < FalseStarts.length; i++) {
if (word[0] == FalseStarts[i]) {
pos = i;
break;
};
};
if (pos >= 0)
word = word.slice(1, word.length);
var isCapitalV = false;
if (word[0] == "V")
isCapitalV = true;
return [pos, isCapitalV, word];
}
function getCanonical_last(word){
var pos = -1;
for (var i = 0; i < FalseStops.length; i++) {
if (word[word.length-1] == FalseStops[i]) {
pos = i;
break;
};
};
if (pos >= 0)
word = word.slice(0, word.length-1);
return [pos, word];
}
function getReplacement(word) {
// debugPrint(word)
var temp = getCanonical_last(word);
var pos = temp[0];
var word = temp[1];
// debugPrint(temp[0]);
// debugPrint(temp[1]);
var ans = -1;
var key;
if (word in ReplacableList){
ans = ReplacableList[word]
}
// for(var key in ReplacableList) {
// if (key == word){
// ans = ReplacableList[key];
// break;
// }
// }
if ((pos >= 0) && (ans != -1))
ans = ans + FalseStops[pos];
return ans;
}
function debugPrint(val){
var output = document.getElementById("demo").innerHTML;
document.getElementById("demo").innerHTML = output + String(val) + ' ' ;
}
function myFunction() {
var textIn = document.getElementById("input").value;
var words = textIn.split(" ");
var j = 0;
var i = 0;
while(i < words.length){
// debugPrint(words)
// debugPrint
// debugPrint(i);
// debugPrint(j);
// debugPrint('<br>');
var temp = getCanonical_first(words[i]);
var pos = temp[0];
var isCapitalV = temp[1];
var word = temp[2];
// debugPrint(pos);
// debugPrint(isCapitalV);
// debugPrint(word);
word = word.toLowerCase();
// debugPrint(word);
if ((word == "very") && (i < words.length - 1)){
var ans = getReplacement(words[i+1]);
// debugPrint(words[i+1]);
// debugPrint(ans);
// debugPrint('<br>');
if (ans != -1) {
if (isCapitalV){
ans = capitalizeFirstLetter(ans);
}
if (pos > 0){
ans = FalseStarts[pos] + ans;
}
words[j] = ans;
i++;
}
else {
words[j] = words[i];
}
}
else{
words[j] = words[i];
}
i++;
j++;
}
// debugPrint(words)
// debugPrint
// debugPrint(i);
// debugPrint(j);
// debugPrint('<br>');
words = words.slice(0, j);
document.getElementById("output").innerHTML = '';
for (var i = 0; i < words.length; i++) {
document.getElementById("output").innerHTML += words[i] + ' ';
};
}
word = 'angry.';
temp = getReplacement(word);
debugPrint(temp);
</script>
</body>
</html>