summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2016-05-30 11:31:20 -0400
committerKelly Rauchenberger <fefferburbia@gmail.com>2016-05-30 11:31:20 -0400
commit6c2aca03c89b37e136ab4c7ea58b485dadc85bcd (patch)
treea9e562aa7e55b02d789755c61bbc4e5c1a8fb383 /lib
parentf94d32242380b23b361f66eb021cad17c35acd8c (diff)
downloadverbly-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')
-rw-r--r--lib/adjective_query.cpp69
-rw-r--r--lib/adjective_query.h2
-rw-r--r--lib/adverb_query.cpp69
-rw-r--r--lib/adverb_query.h2
-rw-r--r--lib/noun_query.cpp69
-rw-r--r--lib/noun_query.h2
-rw-r--r--lib/verb_query.cpp69
-rw-r--r--lib/verb_query.h2
8 files changed, 284 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 {
diff --git a/lib/adjective_query.h b/lib/adjective_query.h index 945e6bd..e6a6609 100644 --- a/lib/adjective_query.h +++ b/lib/adjective_query.h
@@ -17,6 +17,7 @@ namespace verbly {
17 adjective_query& has_rhyming_adjective(); 17 adjective_query& has_rhyming_adjective();
18 adjective_query& has_rhyming_adverb(); 18 adjective_query& has_rhyming_adverb();
19 adjective_query& has_rhyming_verb(); 19 adjective_query& has_rhyming_verb();
20 adjective_query& with_stress(filter<std::vector<bool>> _arg);
20 21
21 adjective_query& requires_comparative_form(); 22 adjective_query& requires_comparative_form();
22 adjective_query& requires_superlative_form(); 23 adjective_query& requires_superlative_form();
@@ -66,6 +67,7 @@ namespace verbly {
66 bool _has_rhyming_adjective = false; 67 bool _has_rhyming_adjective = false;
67 bool _has_rhyming_adverb = false; 68 bool _has_rhyming_adverb = false;
68 bool _has_rhyming_verb = false; 69 bool _has_rhyming_verb = false;
70 filter<std::vector<bool>> _stress;
69 71
70 bool _requires_comparative_form = false; 72 bool _requires_comparative_form = false;
71 bool _requires_superlative_form = false; 73 bool _requires_superlative_form = false;
diff --git a/lib/adverb_query.cpp b/lib/adverb_query.cpp index 1c22712..3e62bb7 100644 --- a/lib/adverb_query.cpp +++ b/lib/adverb_query.cpp
@@ -102,6 +102,13 @@ namespace verbly {
102 return *this; 102 return *this;
103 } 103 }
104 104
105 adverb_query& adverb_query::with_stress(filter<std::vector<bool>> _arg)
106 {
107 _stress = _arg;
108
109 return *this;
110 }
111
105 adverb_query& adverb_query::with_prefix(filter<std::string> _f) 112 adverb_query& adverb_query::with_prefix(filter<std::string> _f)
106 { 113 {
107 _f.clean(); 114 _f.clean();
@@ -263,6 +270,68 @@ namespace verbly {
263 conditions.push_back("superlative IS NOT NULL"); 270 conditions.push_back("superlative IS NOT NULL");
264 } 271 }
265 272
273 if (!_stress.empty())
274 {
275 std::stringstream cond;
276 if (_stress.get_notlogic())
277 {
278 cond << "adverb_id NOT IN";
279 } else {
280 cond << "adverb_id IN";
281 }
282
283 cond << "(SELECT adverb_id FROM adverb_pronunciations WHERE ";
284
285 std::function<std::string (filter<std::vector<bool>>, bool)> recur = [&] (filter<std::vector<bool>> f, bool notlogic) -> std::string {
286 switch (f.get_type())
287 {
288 case filter<std::vector<bool>>::type::singleton:
289 {
290 std::ostringstream _val;
291 for (auto syl : f.get_elem())
292 {
293 if (syl)
294 {
295 _val << "1";
296 } else {
297 _val << "0";
298 }
299 }
300
301 bindings.emplace_back(_val.str());
302
303 if (notlogic == f.get_notlogic())
304 {
305 return "stress = ?";
306 } else {
307 return "stress != ?";
308 }
309 }
310
311 case filter<std::vector<bool>>::type::group:
312 {
313 bool truelogic = notlogic != f.get_notlogic();
314
315 std::list<std::string> clauses;
316 std::transform(std::begin(f), std::end(f), std::back_inserter(clauses), [&] (filter<std::vector<bool>> f2) {
317 return recur(f2, truelogic);
318 });
319
320 if (truelogic == f.get_orlogic())
321 {
322 return "(" + verbly::implode(std::begin(clauses), std::end(clauses), " AND ") + ")";
323 } else {
324 return "(" + verbly::implode(std::begin(clauses), std::end(clauses), " OR ") + ")";
325 }
326 }
327 }
328 };
329
330 cond << recur(_stress, _stress.get_notlogic());
331 cond << ")";
332 conditions.push_back(cond.str());
333 }
334
266 if (!_with_prefix.empty()) 335 if (!_with_prefix.empty())
267 { 336 {
268 std::function<std::string (filter<std::string>, bool)> recur = [&] (filter<std::string> f, bool notlogic) -> std::string { 337 std::function<std::string (filter<std::string>, bool)> recur = [&] (filter<std::string> f, bool notlogic) -> std::string {
diff --git a/lib/adverb_query.h b/lib/adverb_query.h index cf6c046..30e7400 100644 --- a/lib/adverb_query.h +++ b/lib/adverb_query.h
@@ -17,6 +17,7 @@ namespace verbly {
17 adverb_query& has_rhyming_adjective(); 17 adverb_query& has_rhyming_adjective();
18 adverb_query& has_rhyming_adverb(); 18 adverb_query& has_rhyming_adverb();
19 adverb_query& has_rhyming_verb(); 19 adverb_query& has_rhyming_verb();
20 adverb_query& with_stress(filter<std::vector<bool>> _arg);
20 21
21 adverb_query& requires_comparative_form(); 22 adverb_query& requires_comparative_form();
22 adverb_query& requires_superlative_form(); 23 adverb_query& requires_superlative_form();
@@ -53,6 +54,7 @@ namespace verbly {
53 bool _has_rhyming_adjective = false; 54 bool _has_rhyming_adjective = false;
54 bool _has_rhyming_adverb = false; 55 bool _has_rhyming_adverb = false;
55 bool _has_rhyming_verb = false; 56 bool _has_rhyming_verb = false;
57 filter<std::vector<bool>> _stress;
56 58
57 bool _requires_comparative_form = false; 59 bool _requires_comparative_form = false;
58 bool _requires_superlative_form = false; 60 bool _requires_superlative_form = false;
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 {
diff --git a/lib/noun_query.h b/lib/noun_query.h index eb4a57c..74df260 100644 --- a/lib/noun_query.h +++ b/lib/noun_query.h
@@ -17,6 +17,7 @@ namespace verbly {
17 noun_query& has_rhyming_adjective(); 17 noun_query& has_rhyming_adjective();
18 noun_query& has_rhyming_adverb(); 18 noun_query& has_rhyming_adverb();
19 noun_query& has_rhyming_verb(); 19 noun_query& has_rhyming_verb();
20 noun_query& with_stress(filter<std::vector<bool>> _arg);
20 21
21 noun_query& with_singular_form(std::string _arg); 22 noun_query& with_singular_form(std::string _arg);
22 noun_query& with_prefix(filter<std::string> _f); 23 noun_query& with_prefix(filter<std::string> _f);
@@ -100,6 +101,7 @@ namespace verbly {
100 bool _has_rhyming_adjective = false; 101 bool _has_rhyming_adjective = false;
101 bool _has_rhyming_adverb = false; 102 bool _has_rhyming_adverb = false;
102 bool _has_rhyming_verb = false; 103 bool _has_rhyming_verb = false;
104 filter<std::vector<bool>> _stress;
103 105
104 std::list<std::string> _with_singular_form; 106 std::list<std::string> _with_singular_form;
105 filter<std::string> _with_prefix; 107 filter<std::string> _with_prefix;
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 != ?");
diff --git a/lib/verb_query.h b/lib/verb_query.h index 0ee5666..566ae37 100644 --- a/lib/verb_query.h +++ b/lib/verb_query.h
@@ -17,6 +17,7 @@ namespace verbly {
17 verb_query& has_rhyming_adjective(); 17 verb_query& has_rhyming_adjective();
18 verb_query& has_rhyming_adverb(); 18 verb_query& has_rhyming_adverb();
19 verb_query& has_rhyming_verb(); 19 verb_query& has_rhyming_verb();
20 verb_query& with_stress(filter<std::vector<bool>> _arg);
20 21
21 verb_query& has_frames(); 22 verb_query& has_frames();
22 23
@@ -36,6 +37,7 @@ namespace verbly {
36 bool _has_rhyming_adjective = false; 37 bool _has_rhyming_adjective = false;
37 bool _has_rhyming_adverb = false; 38 bool _has_rhyming_adverb = false;
38 bool _has_rhyming_verb = false; 39 bool _has_rhyming_verb = false;
40 filter<std::vector<bool>> _stress;
39 }; 41 };
40 42
41}; 43};