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/noun_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/noun_query.cpp')
-rw-r--r-- | lib/noun_query.cpp | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/lib/noun_query.cpp b/lib/noun_query.cpp index f4c832b..8648227 100644 --- a/lib/noun_query.cpp +++ b/lib/noun_query.cpp | |||
@@ -88,6 +88,13 @@ namespace verbly { | |||
88 | return *this; | 88 | return *this; |
89 | } | 89 | } |
90 | 90 | ||
91 | noun_query& noun_query::with_stress(filter<std::vector<bool>> _arg) | ||
92 | { | ||
93 | _stress = _arg; | ||
94 | |||
95 | return *this; | ||
96 | } | ||
97 | |||
91 | noun_query& noun_query::with_singular_form(std::string _arg) | 98 | noun_query& noun_query::with_singular_form(std::string _arg) |
92 | { | 99 | { |
93 | _with_singular_form.push_back(_arg); | 100 | _with_singular_form.push_back(_arg); |
@@ -555,6 +562,68 @@ namespace verbly { | |||
555 | { | 562 | { |
556 | conditions.push_back("noun_id IN (SELECT a.noun_id FROM nouns AS a INNER JOIN noun_pronunciations AS curp ON curp.noun_id = a.noun_id INNER JOIN verb_pronunciations AS rhmp ON rhmp.prerhyme != curp.prerhyme AND rhmp.rhyme = curp.rhyme)"); | 563 | conditions.push_back("noun_id IN (SELECT a.noun_id FROM nouns AS a INNER JOIN noun_pronunciations AS curp ON curp.noun_id = a.noun_id INNER JOIN verb_pronunciations AS rhmp ON rhmp.prerhyme != curp.prerhyme AND rhmp.rhyme = curp.rhyme)"); |
557 | } | 564 | } |
565 | |||
566 | if (!_stress.empty()) | ||
567 | { | ||
568 | std::stringstream cond; | ||
569 | if (_stress.get_notlogic()) | ||
570 | { | ||
571 | cond << "noun_id NOT IN"; | ||
572 | } else { | ||
573 | cond << "noun_id IN"; | ||
574 | } | ||
575 | |||
576 | cond << "(SELECT noun_id FROM noun_pronunciations WHERE "; | ||
577 | |||
578 | std::function<std::string (filter<std::vector<bool>>, bool)> recur = [&] (filter<std::vector<bool>> f, bool notlogic) -> std::string { | ||
579 | switch (f.get_type()) | ||
580 | { | ||
581 | case filter<std::vector<bool>>::type::singleton: | ||
582 | { | ||
583 | std::ostringstream _val; | ||
584 | for (auto syl : f.get_elem()) | ||
585 | { | ||
586 | if (syl) | ||
587 | { | ||
588 | _val << "1"; | ||
589 | } else { | ||
590 | _val << "0"; | ||
591 | } | ||
592 | } | ||
593 | |||
594 | bindings.emplace_back(_val.str()); | ||
595 | |||
596 | if (notlogic == f.get_notlogic()) | ||
597 | { | ||
598 | return "stress = ?"; | ||
599 | } else { | ||
600 | return "stress != ?"; | ||
601 | } | ||
602 | } | ||
603 | |||
604 | case filter<std::vector<bool>>::type::group: | ||
605 | { | ||
606 | bool truelogic = notlogic != f.get_notlogic(); | ||
607 | |||
608 | std::list<std::string> clauses; | ||
609 | std::transform(std::begin(f), std::end(f), std::back_inserter(clauses), [&] (filter<std::vector<bool>> f2) { | ||
610 | return recur(f2, truelogic); | ||
611 | }); | ||
612 | |||
613 | if (truelogic == f.get_orlogic()) | ||
614 | { | ||
615 | return "(" + verbly::implode(std::begin(clauses), std::end(clauses), " AND ") + ")"; | ||
616 | } else { | ||
617 | return "(" + verbly::implode(std::begin(clauses), std::end(clauses), " OR ") + ")"; | ||
618 | } | ||
619 | } | ||
620 | } | ||
621 | }; | ||
622 | |||
623 | cond << recur(_stress, _stress.get_notlogic()); | ||
624 | cond << ")"; | ||
625 | conditions.push_back(cond.str()); | ||
626 | } | ||
558 | 627 | ||
559 | for (auto except : _except) | 628 | for (auto except : _except) |
560 | { | 629 | { |