From 6c2aca03c89b37e136ab4c7ea58b485dadc85bcd Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Mon, 30 May 2016 11:31:20 -0400 Subject: Added pronunciation syllable count and stress structure Also updated CMakeLists.txt such that including projects don't have to include sqlite3. --- lib/verb_query.cpp | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) (limited to 'lib/verb_query.cpp') diff --git a/lib/verb_query.cpp b/lib/verb_query.cpp index d871f83..4e6c253 100644 --- a/lib/verb_query.cpp +++ b/lib/verb_query.cpp @@ -88,6 +88,13 @@ namespace verbly { return *this; } + verb_query& verb_query::with_stress(filter> _arg) + { + _stress = _arg; + + return *this; + } + verb_query& verb_query::has_frames() { this->_has_frames = true; @@ -140,6 +147,68 @@ namespace verbly { conditions.push_back("verb_id IN (SELECT a.verb_id FROM verbs AS a INNER JOIN verb_pronunciations AS curp ON curp.noun_id = a.adverb_id INNER JOIN verb_pronunciations AS rhmp ON rhmp.prerhyme != curp.prerhyme AND rhmp.rhyme = curp.rhyme AND rhmp.verb_id != curp.verb_id)"); } + if (!_stress.empty()) + { + std::stringstream cond; + if (_stress.get_notlogic()) + { + cond << "verb_id NOT IN"; + } else { + cond << "verb_id IN"; + } + + cond << "(SELECT verb_id FROM verb_pronunciations WHERE "; + + std::function>, bool)> recur = [&] (filter> f, bool notlogic) -> std::string { + switch (f.get_type()) + { + case filter>::type::singleton: + { + std::ostringstream _val; + for (auto syl : f.get_elem()) + { + if (syl) + { + _val << "1"; + } else { + _val << "0"; + } + } + + bindings.emplace_back(_val.str()); + + if (notlogic == f.get_notlogic()) + { + return "stress = ?"; + } else { + return "stress != ?"; + } + } + + case filter>::type::group: + { + bool truelogic = notlogic != f.get_notlogic(); + + std::list clauses; + std::transform(std::begin(f), std::end(f), std::back_inserter(clauses), [&] (filter> f2) { + return recur(f2, truelogic); + }); + + if (truelogic == f.get_orlogic()) + { + return "(" + verbly::implode(std::begin(clauses), std::end(clauses), " AND ") + ")"; + } else { + return "(" + verbly::implode(std::begin(clauses), std::end(clauses), " OR ") + ")"; + } + } + } + }; + + cond << recur(_stress, _stress.get_notlogic()); + cond << ")"; + conditions.push_back(cond.str()); + } + for (auto except : _except) { conditions.push_back("verb_id != ?"); -- cgit 1.4.1