technician1 commited on
Commit
b79dc02
·
1 Parent(s): cd97621

Upload ChatIPC.cpp

Browse files
Files changed (1) hide show
  1. ChatIPC.cpp +66 -23
ChatIPC.cpp CHANGED
@@ -147,42 +147,85 @@ static bool is_punctuation_only_token(const std::string &s){
147
  return true;
148
  }
149
 
150
- static bool is_common_determiner(const std::string &s){
151
- return s == "a" || s == "an" || s == "the" || s == "this" || s == "that" ||
152
- s == "these" || s == "those" || s == "my" || s == "your" || s == "his" ||
153
- s == "her" || s == "its" || s == "our" || s == "their";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154
  }
155
 
156
- static bool is_common_preposition(const std::string &s){
157
- return s == "of" || s == "in" || s == "on" || s == "at" || s == "by" ||
158
- s == "for" || s == "from" || s == "with" || s == "into" || s == "onto" ||
159
- s == "about" || s == "over" || s == "under" || s == "after" || s == "before" ||
160
- s == "between" || s == "through" || s == "during" || s == "without" || s == "within" ||
161
- s == "under" || s == "across" || s == "against" || s == "among" || s == "around";
 
 
 
 
 
 
 
 
 
162
  }
163
 
164
- static bool is_common_aux_or_modal(const std::string &s){
165
- return s == "to" || s == "be" || s == "am" || s == "is" || s == "are" || s == "was" ||
166
- s == "were" || s == "been" || s == "being" || s == "have" || s == "has" ||
167
- s == "had" || s == "do" || s == "does" || s == "did" || s == "can" ||
168
- s == "could" || s == "may" || s == "might" || s == "must" || s == "shall" ||
169
- s == "should" || s == "will" || s == "would";
 
 
 
 
 
170
  }
171
 
172
  static bool begins_with_vowel_sound(const std::string &s){
173
  if (s.empty()) return false;
174
 
175
- if (s.rfind("hour", 0) == 0 || s.rfind("honest", 0) == 0 || s.rfind("honor", 0) == 0 ||
176
- s.rfind("heir", 0) == 0 || s.rfind("herb", 0) == 0) {
177
- return true;
 
 
 
 
 
 
 
 
 
 
 
 
 
178
  }
179
 
180
- if (s.rfind("uni", 0) == 0 || s.rfind("use", 0) == 0 || s.rfind("user", 0) == 0 ||
181
- s.rfind("one", 0) == 0 || s.rfind("once", 0) == 0 || s.rfind("euro", 0) == 0) {
182
- return false;
 
183
  }
184
 
185
- char c = s[0];
 
186
  return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';
187
  }
188
 
 
147
  return true;
148
  }
149
 
150
+ static std::string to_lower_ascii(std::string s) {
151
+ std::transform(s.begin(), s.end(), s.begin(),
152
+ [](unsigned char c) { return static_cast<char>(std::tolower(c)); });
153
+ return s;
154
+ }
155
+
156
+ static bool is_common_determiner(const std::string &s) {
157
+ static const std::unordered_set<std::string> words = {
158
+ "a", "an", "the", "this", "that", "these", "those",
159
+ "my", "your", "his", "her", "its", "our", "their",
160
+ "all", "some", "any", "each", "every", "either", "neither",
161
+ "no", "many", "much", "more", "most", "few", "fewer", "less",
162
+ "little", "several", "both", "another", "other", "such",
163
+ "own", "same", "certain", "what", "which", "whose",
164
+ "whatever", "whichever", "enough", "various", "particular"
165
+ };
166
+
167
+ return words.find(to_lower_ascii(s)) != words.end();
168
  }
169
 
170
+ static bool is_common_preposition(const std::string &s) {
171
+ static const std::unordered_set<std::string> words = {
172
+ "of", "in", "on", "at", "by", "for", "from", "with",
173
+ "into", "onto", "about", "over", "under", "after", "before",
174
+ "between", "through", "during", "without", "within", "across",
175
+ "against", "among", "around", "as", "like", "per", "via",
176
+ "toward", "towards", "upon", "beneath", "beside", "besides",
177
+ "beyond", "inside", "outside", "near", "past", "since",
178
+ "until", "till", "up", "down", "off", "out", "underneath",
179
+ "amid", "amidst", "despite", "except", "regarding", "concerning",
180
+ "throughout", "amongst", "opposite", "along", "behind", "ahead",
181
+ "above", "below", "plus", "minus"
182
+ };
183
+
184
+ return words.find(to_lower_ascii(s)) != words.end();
185
  }
186
 
187
+ static bool is_common_aux_or_modal(const std::string &s) {
188
+ static const std::unordered_set<std::string> words = {
189
+ "to", "be", "am", "is", "are", "was", "were", "been", "being",
190
+ "have", "has", "had", "do", "does", "did",
191
+ "can", "could", "may", "might", "must", "shall", "should", "will",
192
+ "would", "ought", "need", "dare", "used",
193
+ "cannot", "can't", "won't", "wouldn't", "shouldn't", "couldn't",
194
+ "mustn't", "mayn't", "mightn't", "shan't"
195
+ };
196
+
197
+ return words.find(to_lower_ascii(s)) != words.end();
198
  }
199
 
200
  static bool begins_with_vowel_sound(const std::string &s){
201
  if (s.empty()) return false;
202
 
203
+ const std::string t = to_lower_ascii(s);
204
+
205
+ static const std::unordered_set<std::string> vowel_sound_exceptions = {
206
+ "hour", "hours", "honest", "honesty", "honor", "honour", "honorable", "honourable",
207
+ "heir", "heiress", "herb", "herbal", "herbalist", "homage", "hono(u)rary"
208
+ };
209
+
210
+ static const std::unordered_set<std::string> consonant_sound_prefixes = {
211
+ "uni", "univ", "unit", "use", "user", "euro", "eu", "one", "once", "ouija",
212
+ "ufo", "ut", "uk", "ubiq", "ewe", "eul", "eup", "x", "y"
213
+ };
214
+
215
+ for (const auto &w : vowel_sound_exceptions) {
216
+ if (t.rfind(w, 0) == 0) {
217
+ return true;
218
+ }
219
  }
220
 
221
+ for (const auto &p : consonant_sound_prefixes) {
222
+ if (t.rfind(p, 0) == 0) {
223
+ return false;
224
+ }
225
  }
226
 
227
+ if (t.empty()) return false;
228
+ char c = t[0];
229
  return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';
230
  }
231