diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2016-03-27 14:28:54 -0400 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2016-03-27 14:28:54 -0400 |
commit | 4c94e100e87a09284f0e0a5bc0df688672492a1e (patch) | |
tree | f94611f057268dbc1000fb66cd89a8d3ad809d7a /lib/adverb_query.cpp | |
parent | 429f6195f6a4410ae45ef3f560b0745ac60184c1 (diff) | |
download | verbly-4c94e100e87a09284f0e0a5bc0df688672492a1e.tar.gz verbly-4c94e100e87a09284f0e0a5bc0df688672492a1e.tar.bz2 verbly-4c94e100e87a09284f0e0a5bc0df688672492a1e.zip |
Added prefix/suffix search, and word complexity search for nouns, adjectives, and adverbs
Word complexity refers to the number of words in a noun, adjective, or adverb.
Diffstat (limited to 'lib/adverb_query.cpp')
-rw-r--r-- | lib/adverb_query.cpp | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/lib/adverb_query.cpp b/lib/adverb_query.cpp index 639f16f..c9d0d09 100644 --- a/lib/adverb_query.cpp +++ b/lib/adverb_query.cpp | |||
@@ -67,6 +67,29 @@ namespace verbly { | |||
67 | return *this; | 67 | return *this; |
68 | } | 68 | } |
69 | 69 | ||
70 | adverb_query& adverb_query::with_prefix(filter<std::string> _f) | ||
71 | { | ||
72 | _f.clean(); | ||
73 | _with_prefix = _f; | ||
74 | |||
75 | return *this; | ||
76 | } | ||
77 | |||
78 | adverb_query& adverb_query::with_suffix(filter<std::string> _f) | ||
79 | { | ||
80 | _f.clean(); | ||
81 | _with_suffix = _f; | ||
82 | |||
83 | return *this; | ||
84 | } | ||
85 | |||
86 | adverb_query& adverb_query::with_complexity(int _arg) | ||
87 | { | ||
88 | _with_complexity = _arg; | ||
89 | |||
90 | return *this; | ||
91 | } | ||
92 | |||
70 | adverb_query& adverb_query::has_antonyms() | 93 | adverb_query& adverb_query::has_antonyms() |
71 | { | 94 | { |
72 | _has_antonyms = true; | 95 | _has_antonyms = true; |
@@ -177,6 +200,85 @@ namespace verbly { | |||
177 | conditions.push_back("superlative IS NOT NULL"); | 200 | conditions.push_back("superlative IS NOT NULL"); |
178 | } | 201 | } |
179 | 202 | ||
203 | if (!_with_prefix.empty()) | ||
204 | { | ||
205 | std::function<std::string (filter<std::string>, bool)> recur = [&] (filter<std::string> f, bool notlogic) -> std::string { | ||
206 | switch (f.get_type()) | ||
207 | { | ||
208 | case filter<std::string>::type::singleton: | ||
209 | { | ||
210 | if (notlogic == f.get_notlogic()) | ||
211 | { | ||
212 | return "base_form LIKE @PREFIX"; | ||
213 | } else { | ||
214 | return "base_form NOT LIKE @PREFIX"; | ||
215 | } | ||
216 | } | ||
217 | |||
218 | case filter<std::string>::type::group: | ||
219 | { | ||
220 | bool truelogic = notlogic != f.get_notlogic(); | ||
221 | |||
222 | std::list<std::string> clauses; | ||
223 | std::transform(std::begin(f), std::end(f), std::back_inserter(clauses), [&] (filter<std::string> f2) { | ||
224 | return recur(f2, truelogic); | ||
225 | }); | ||
226 | |||
227 | if (truelogic == f.get_orlogic()) | ||
228 | { | ||
229 | return "(" + verbly::implode(std::begin(clauses), std::end(clauses), " AND ") + ")"; | ||
230 | } else { | ||
231 | return "(" + verbly::implode(std::begin(clauses), std::end(clauses), " OR ") + ")"; | ||
232 | } | ||
233 | } | ||
234 | } | ||
235 | }; | ||
236 | |||
237 | conditions.push_back(recur(_with_prefix, false)); | ||
238 | } | ||
239 | |||
240 | if (!_with_suffix.empty()) | ||
241 | { | ||
242 | std::function<std::string (filter<std::string>, bool)> recur = [&] (filter<std::string> f, bool notlogic) -> std::string { | ||
243 | switch (f.get_type()) | ||
244 | { | ||
245 | case filter<std::string>::type::singleton: | ||
246 | { | ||
247 | if (notlogic == f.get_notlogic()) | ||
248 | { | ||
249 | return "base_form LIKE @SUFFIX"; | ||
250 | } else { | ||
251 | return "base_form NOT LIKE @SUFFIX"; | ||
252 | } | ||
253 | } | ||
254 | |||
255 | case filter<std::string>::type::group: | ||
256 | { | ||
257 | bool truelogic = notlogic != f.get_notlogic(); | ||
258 | |||
259 | std::list<std::string> clauses; | ||
260 | std::transform(std::begin(f), std::end(f), std::back_inserter(clauses), [&] (filter<std::string> f2) { | ||
261 | return recur(f2, truelogic); | ||
262 | }); | ||
263 | |||
264 | if (truelogic == f.get_orlogic()) | ||
265 | { | ||
266 | return "(" + verbly::implode(std::begin(clauses), std::end(clauses), " AND ") + ")"; | ||
267 | } else { | ||
268 | return "(" + verbly::implode(std::begin(clauses), std::end(clauses), " OR ") + ")"; | ||
269 | } | ||
270 | } | ||
271 | } | ||
272 | }; | ||
273 | |||
274 | conditions.push_back(recur(_with_suffix, false)); | ||
275 | } | ||
276 | |||
277 | if (_with_complexity != unlimited) | ||
278 | { | ||
279 | conditions.push_back("complexity = @COMPLEX"); | ||
280 | } | ||
281 | |||
180 | if (_has_antonyms) | 282 | if (_has_antonyms) |
181 | { | 283 | { |
182 | conditions.push_back("adverb_id IN (SELECT adverb_2_id FROM adverb_antonymy)"); | 284 | conditions.push_back("adverb_id IN (SELECT adverb_2_id FROM adverb_antonymy)"); |
@@ -421,6 +523,23 @@ namespace verbly { | |||
421 | sqlite3_bind_int(ppstmt, sqlite3_bind_parameter_index(ppstmt, "@EXCID"), except._id); | 523 | sqlite3_bind_int(ppstmt, sqlite3_bind_parameter_index(ppstmt, "@EXCID"), except._id); |
422 | } | 524 | } |
423 | 525 | ||
526 | for (auto prefix : _with_prefix.inorder_flatten()) | ||
527 | { | ||
528 | std::string pfat = prefix + "%"; | ||
529 | sqlite3_bind_text(ppstmt, sqlite3_bind_parameter_index(ppstmt, "@PREFIX"), pfat.c_str(), pfat.length(), SQLITE_STATIC); | ||
530 | } | ||
531 | |||
532 | for (auto suffix : _with_suffix.inorder_flatten()) | ||
533 | { | ||
534 | std::string pfat = "%" + suffix; | ||
535 | sqlite3_bind_text(ppstmt, sqlite3_bind_parameter_index(ppstmt, "@SUFFIX"), pfat.c_str(), pfat.length(), SQLITE_STATIC); | ||
536 | } | ||
537 | |||
538 | if (_with_complexity != unlimited) | ||
539 | { | ||
540 | sqlite3_bind_int(ppstmt, sqlite3_bind_parameter_index(ppstmt, "@COMPLEX"), _with_complexity); | ||
541 | } | ||
542 | |||
424 | for (auto antonym : _antonym_of.inorder_flatten()) | 543 | for (auto antonym : _antonym_of.inorder_flatten()) |
425 | { | 544 | { |
426 | sqlite3_bind_int(ppstmt, sqlite3_bind_parameter_index(ppstmt, "@ANTID"), antonym._id); | 545 | sqlite3_bind_int(ppstmt, sqlite3_bind_parameter_index(ppstmt, "@ANTID"), antonym._id); |