diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2016-05-30 11:31:20 -0400 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2016-05-30 11:31:20 -0400 |
commit | 6c2aca03c89b37e136ab4c7ea58b485dadc85bcd (patch) | |
tree | a9e562aa7e55b02d789755c61bbc4e5c1a8fb383 /lib/adverb_query.cpp | |
parent | f94d32242380b23b361f66eb021cad17c35acd8c (diff) | |
download | verbly-6c2aca03c89b37e136ab4c7ea58b485dadc85bcd.tar.gz verbly-6c2aca03c89b37e136ab4c7ea58b485dadc85bcd.tar.bz2 verbly-6c2aca03c89b37e136ab4c7ea58b485dadc85bcd.zip |
Added pronunciation syllable count and stress structure
Also updated CMakeLists.txt such that including projects don't have to include sqlite3.
Diffstat (limited to 'lib/adverb_query.cpp')
-rw-r--r-- | lib/adverb_query.cpp | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/lib/adverb_query.cpp b/lib/adverb_query.cpp index 1c22712..3e62bb7 100644 --- a/lib/adverb_query.cpp +++ b/lib/adverb_query.cpp | |||
@@ -102,6 +102,13 @@ namespace verbly { | |||
102 | return *this; | 102 | return *this; |
103 | } | 103 | } |
104 | 104 | ||
105 | adverb_query& adverb_query::with_stress(filter<std::vector<bool>> _arg) | ||
106 | { | ||
107 | _stress = _arg; | ||
108 | |||
109 | return *this; | ||
110 | } | ||
111 | |||
105 | adverb_query& adverb_query::with_prefix(filter<std::string> _f) | 112 | adverb_query& adverb_query::with_prefix(filter<std::string> _f) |
106 | { | 113 | { |
107 | _f.clean(); | 114 | _f.clean(); |
@@ -263,6 +270,68 @@ namespace verbly { | |||
263 | conditions.push_back("superlative IS NOT NULL"); | 270 | conditions.push_back("superlative IS NOT NULL"); |
264 | } | 271 | } |
265 | 272 | ||
273 | if (!_stress.empty()) | ||
274 | { | ||
275 | std::stringstream cond; | ||
276 | if (_stress.get_notlogic()) | ||
277 | { | ||
278 | cond << "adverb_id NOT IN"; | ||
279 | } else { | ||
280 | cond << "adverb_id IN"; | ||
281 | } | ||
282 | |||
283 | cond << "(SELECT adverb_id FROM adverb_pronunciations WHERE "; | ||
284 | |||
285 | std::function<std::string (filter<std::vector<bool>>, bool)> recur = [&] (filter<std::vector<bool>> f, bool notlogic) -> std::string { | ||
286 | switch (f.get_type()) | ||
287 | { | ||
288 | case filter<std::vector<bool>>::type::singleton: | ||
289 | { | ||
290 | std::ostringstream _val; | ||
291 | for (auto syl : f.get_elem()) | ||
292 | { | ||
293 | if (syl) | ||
294 | { | ||
295 | _val << "1"; | ||
296 | } else { | ||
297 | _val << "0"; | ||
298 | } | ||
299 | } | ||
300 | |||
301 | bindings.emplace_back(_val.str()); | ||
302 | |||
303 | if (notlogic == f.get_notlogic()) | ||
304 | { | ||
305 | return "stress = ?"; | ||
306 | } else { | ||
307 | return "stress != ?"; | ||
308 | } | ||
309 | } | ||
310 | |||
311 | case filter<std::vector<bool>>::type::group: | ||
312 | { | ||
313 | bool truelogic = notlogic != f.get_notlogic(); | ||
314 | |||
315 | std::list<std::string> clauses; | ||
316 | std::transform(std::begin(f), std::end(f), std::back_inserter(clauses), [&] (filter<std::vector<bool>> f2) { | ||
317 | return recur(f2, truelogic); | ||
318 | }); | ||
319 | |||
320 | if (truelogic == f.get_orlogic()) | ||
321 | { | ||
322 | return "(" + verbly::implode(std::begin(clauses), std::end(clauses), " AND ") + ")"; | ||
323 | } else { | ||
324 | return "(" + verbly::implode(std::begin(clauses), std::end(clauses), " OR ") + ")"; | ||
325 | } | ||
326 | } | ||
327 | } | ||
328 | }; | ||
329 | |||
330 | cond << recur(_stress, _stress.get_notlogic()); | ||
331 | cond << ")"; | ||
332 | conditions.push_back(cond.str()); | ||
333 | } | ||
334 | |||
266 | if (!_with_prefix.empty()) | 335 | if (!_with_prefix.empty()) |
267 | { | 336 | { |
268 | std::function<std::string (filter<std::string>, bool)> recur = [&] (filter<std::string> f, bool notlogic) -> std::string { | 337 | std::function<std::string (filter<std::string>, bool)> recur = [&] (filter<std::string> f, bool notlogic) -> std::string { |