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/adjective_query.cpp | 69 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) (limited to 'lib/adjective_query.cpp') 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 { return *this; } + adjective_query& adjective_query::with_stress(filter> _arg) + { + _stress = _arg; + + return *this; + } + adjective_query& adjective_query::with_prefix(filter _f) { _f.clean(); @@ -338,6 +345,68 @@ namespace verbly { case adjective::positioning::undefined: break; } + if (!_stress.empty()) + { + std::stringstream cond; + if (_stress.get_notlogic()) + { + cond << "adjective_id NOT IN"; + } else { + cond << "adjective_id IN"; + } + + cond << "(SELECT adjective_id FROM adjective_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()); + } + if (!_with_prefix.empty()) { std::function, bool)> recur = [&] (filter f, bool notlogic) -> std::string { -- cgit 1.4.1