summary refs log tree commit diff stats
path: root/lib/adjective_query.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/adjective_query.cpp')
-rw-r--r--lib/adjective_query.cpp69
1 files changed, 69 insertions, 0 deletions
diff --git a/lib/adjective_query.cpp b/lib/adjective_query.cpp index 5f1cbe7..90ccef4 100644 --- a/lib/adjective_query.cpp +++ b/lib/adjective_query.cpp
@@ -88,6 +88,13 @@ namespace verbly {
88 return *this; 88 return *this;
89 } 89 }
90 90
91 adjective_query& adjective_query::with_stress(filter<std::vector<bool>> _arg)
92 {
93 _stress = _arg;
94
95 return *this;
96 }
97
91 adjective_query& adjective_query::with_prefix(filter<std::string> _f) 98 adjective_query& adjective_query::with_prefix(filter<std::string> _f)
92 { 99 {
93 _f.clean(); 100 _f.clean();
@@ -338,6 +345,68 @@ namespace verbly {
338 case adjective::positioning::undefined: break; 345 case adjective::positioning::undefined: break;
339 } 346 }
340 347
348 if (!_stress.empty())
349 {
350 std::stringstream cond;
351 if (_stress.get_notlogic())
352 {
353 cond << "adjective_id NOT IN";
354 } else {
355 cond << "adjective_id IN";
356 }
357
358 cond << "(SELECT adjective_id FROM adjective_pronunciations WHERE ";
359
360 std::function<std::string (filter<std::vector<bool>>, bool)> recur = [&] (filter<std::vector<bool>> f, bool notlogic) -> std::string {
361 switch (f.get_type())
362 {
363 case filter<std::vector<bool>>::type::singleton:
364 {
365 std::ostringstream _val;
366 for (auto syl : f.get_elem())
367 {
368 if (syl)
369 {
370 _val << "1";
371 } else {
372 _val << "0";
373 }
374 }
375
376 bindings.emplace_back(_val.str());
377
378 if (notlogic == f.get_notlogic())
379 {
380 return "stress = ?";
381 } else {
382 return "stress != ?";
383 }
384 }
385
386 case filter<std::vector<bool>>::type::group:
387 {
388 bool truelogic = notlogic != f.get_notlogic();
389
390 std::list<std::string> clauses;
391 std::transform(std::begin(f), std::end(f), std::back_inserter(clauses), [&] (filter<std::vector<bool>> f2) {
392 return recur(f2, truelogic);
393 });
394
395 if (truelogic == f.get_orlogic())
396 {
397 return "(" + verbly::implode(std::begin(clauses), std::end(clauses), " AND ") + ")";
398 } else {
399 return "(" + verbly::implode(std::begin(clauses), std::end(clauses), " OR ") + ")";
400 }
401 }
402 }
403 };
404
405 cond << recur(_stress, _stress.get_notlogic());
406 cond << ")";
407 conditions.push_back(cond.str());
408 }
409
341 if (!_with_prefix.empty()) 410 if (!_with_prefix.empty())
342 { 411 {
343 std::function<std::string (filter<std::string>, bool)> recur = [&] (filter<std::string> f, bool notlogic) -> std::string { 412 std::function<std::string (filter<std::string>, bool)> recur = [&] (filter<std::string> f, bool notlogic) -> std::string {