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/verb_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/verb_query.cpp')
| -rw-r--r-- | lib/verb_query.cpp | 69 |
1 files changed, 69 insertions, 0 deletions
| 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 { | |||
| 88 | return *this; | 88 | return *this; |
| 89 | } | 89 | } |
| 90 | 90 | ||
| 91 | verb_query& verb_query::with_stress(filter<std::vector<bool>> _arg) | ||
| 92 | { | ||
| 93 | _stress = _arg; | ||
| 94 | |||
| 95 | return *this; | ||
| 96 | } | ||
| 97 | |||
| 91 | verb_query& verb_query::has_frames() | 98 | verb_query& verb_query::has_frames() |
| 92 | { | 99 | { |
| 93 | this->_has_frames = true; | 100 | this->_has_frames = true; |
| @@ -140,6 +147,68 @@ namespace verbly { | |||
| 140 | 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)"); | 147 | 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)"); |
| 141 | } | 148 | } |
| 142 | 149 | ||
| 150 | if (!_stress.empty()) | ||
| 151 | { | ||
| 152 | std::stringstream cond; | ||
| 153 | if (_stress.get_notlogic()) | ||
| 154 | { | ||
| 155 | cond << "verb_id NOT IN"; | ||
| 156 | } else { | ||
| 157 | cond << "verb_id IN"; | ||
| 158 | } | ||
| 159 | |||
| 160 | cond << "(SELECT verb_id FROM verb_pronunciations WHERE "; | ||
| 161 | |||
| 162 | std::function<std::string (filter<std::vector<bool>>, bool)> recur = [&] (filter<std::vector<bool>> f, bool notlogic) -> std::string { | ||
| 163 | switch (f.get_type()) | ||
| 164 | { | ||
| 165 | case filter<std::vector<bool>>::type::singleton: | ||
| 166 | { | ||
| 167 | std::ostringstream _val; | ||
| 168 | for (auto syl : f.get_elem()) | ||
| 169 | { | ||
| 170 | if (syl) | ||
| 171 | { | ||
| 172 | _val << "1"; | ||
| 173 | } else { | ||
| 174 | _val << "0"; | ||
| 175 | } | ||
| 176 | } | ||
| 177 | |||
| 178 | bindings.emplace_back(_val.str()); | ||
| 179 | |||
| 180 | if (notlogic == f.get_notlogic()) | ||
| 181 | { | ||
| 182 | return "stress = ?"; | ||
| 183 | } else { | ||
| 184 | return "stress != ?"; | ||
| 185 | } | ||
| 186 | } | ||
| 187 | |||
| 188 | case filter<std::vector<bool>>::type::group: | ||
| 189 | { | ||
| 190 | bool truelogic = notlogic != f.get_notlogic(); | ||
| 191 | |||
| 192 | std::list<std::string> clauses; | ||
| 193 | std::transform(std::begin(f), std::end(f), std::back_inserter(clauses), [&] (filter<std::vector<bool>> f2) { | ||
| 194 | return recur(f2, truelogic); | ||
| 195 | }); | ||
| 196 | |||
| 197 | if (truelogic == f.get_orlogic()) | ||
| 198 | { | ||
| 199 | return "(" + verbly::implode(std::begin(clauses), std::end(clauses), " AND ") + ")"; | ||
| 200 | } else { | ||
| 201 | return "(" + verbly::implode(std::begin(clauses), std::end(clauses), " OR ") + ")"; | ||
| 202 | } | ||
| 203 | } | ||
| 204 | } | ||
| 205 | }; | ||
| 206 | |||
| 207 | cond << recur(_stress, _stress.get_notlogic()); | ||
| 208 | cond << ")"; | ||
| 209 | conditions.push_back(cond.str()); | ||
| 210 | } | ||
| 211 | |||
| 143 | for (auto except : _except) | 212 | for (auto except : _except) |
| 144 | { | 213 | { |
| 145 | conditions.push_back("verb_id != ?"); | 214 | conditions.push_back("verb_id != ?"); |
