Commit ·
b79dc02
1
Parent(s): cd97621
Upload ChatIPC.cpp
Browse files- 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
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
}
|
| 155 |
|
| 156 |
-
static bool is_common_preposition(const std::string &s){
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
}
|
| 163 |
|
| 164 |
-
static bool is_common_aux_or_modal(const std::string &s){
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 170 |
}
|
| 171 |
|
| 172 |
static bool begins_with_vowel_sound(const std::string &s){
|
| 173 |
if (s.empty()) return false;
|
| 174 |
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 178 |
}
|
| 179 |
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
|
|
|
| 183 |
}
|
| 184 |
|
| 185 |
-
|
|
|
|
| 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 |
|