summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt1
-rw-r--r--generator/generator.cpp49
-rw-r--r--generator/schema.sql8
-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
11 files changed, 330 insertions, 12 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 8af6cff..03ce05b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt
@@ -8,3 +8,4 @@ include_directories(vendor/json/src)
8add_library(verbly lib/data.cpp lib/adjective.cpp lib/noun.cpp lib/verb.cpp lib/adverb.cpp lib/token.cpp lib/word.cpp lib/frame.cpp lib/preposition.cpp lib/adjective_query.cpp lib/adverb_query.cpp lib/noun_query.cpp lib/verb_query.cpp lib/frame_query.cpp) 8add_library(verbly lib/data.cpp lib/adjective.cpp lib/noun.cpp lib/verb.cpp lib/adverb.cpp lib/token.cpp lib/word.cpp lib/frame.cpp lib/preposition.cpp lib/adjective_query.cpp lib/adverb_query.cpp lib/noun_query.cpp lib/verb_query.cpp lib/frame_query.cpp)
9set_property(TARGET verbly PROPERTY CXX_STANDARD 11) 9set_property(TARGET verbly PROPERTY CXX_STANDARD 11)
10set_property(TARGET verbly PROPERTY CXX_STANDARD_REQUIRED ON) 10set_property(TARGET verbly PROPERTY CXX_STANDARD_REQUIRED ON)
11target_link_libraries(verbly ${sqlite3_LIBRARIES})
diff --git a/generator/generator.cpp b/generator/generator.cpp index 3201154..6a16467 100644 --- a/generator/generator.cpp +++ b/generator/generator.cpp
@@ -80,6 +80,8 @@ struct pronunciation_t {
80 std::string phonemes; 80 std::string phonemes;
81 std::string prerhyme; 81 std::string prerhyme;
82 std::string rhyme; 82 std::string rhyme;
83 int syllables = 0;
84 std::string stress;
83 85
84 bool operator<(const pronunciation_t& other) const 86 bool operator<(const pronunciation_t& other) const
85 { 87 {
@@ -609,6 +611,8 @@ int main(int argc, char** argv)
609 611
610 pronunciation_t p; 612 pronunciation_t p;
611 p.phonemes = phonemes; 613 p.phonemes = phonemes;
614
615 // Rhyme detection
612 if (phemstrt != std::end(phoneme_set)) 616 if (phemstrt != std::end(phoneme_set))
613 { 617 {
614 std::stringstream rhymer; 618 std::stringstream rhymer;
@@ -641,6 +645,23 @@ int main(int argc, char** argv)
641 p.rhyme = ""; 645 p.rhyme = "";
642 } 646 }
643 647
648 // Syllable/stress
649 for (auto phm : phoneme_set)
650 {
651 if (isdigit(phm.back()))
652 {
653 // It's a vowel!
654 p.syllables++;
655
656 if (phm.back() == '1')
657 {
658 p.stress.push_back('1');
659 } else {
660 p.stress.push_back('0');
661 }
662 }
663 }
664
644 pronunciations[canonical].insert(p); 665 pronunciations[canonical].insert(p);
645 } 666 }
646 } 667 }
@@ -864,9 +885,9 @@ int main(int argc, char** argv)
864 { 885 {
865 if (!pronunciation.rhyme.empty()) 886 if (!pronunciation.rhyme.empty())
866 { 887 {
867 query = "INSERT INTO verb_pronunciations (verb_id, pronunciation, prerhyme, rhyme) VALUES (?, ?, ?, ?)"; 888 query = "INSERT INTO verb_pronunciations (verb_id, pronunciation, syllables, stress, prerhyme, rhyme) VALUES (?, ?, ?, ?, ?, ?)";
868 } else { 889 } else {
869 query = "INSERT INTO verb_pronunciations (verb_id, pronunciation) VALUES (?, ?)"; 890 query = "INSERT INTO verb_pronunciations (verb_id, pronunciation, syllables, stress) VALUES (?, ?, ?, ?)";
870 } 891 }
871 892
872 if (sqlite3_prepare_v2(ppdb, query.c_str(), query.length(), &ppstmt, NULL) != SQLITE_OK) 893 if (sqlite3_prepare_v2(ppdb, query.c_str(), query.length(), &ppstmt, NULL) != SQLITE_OK)
@@ -876,11 +897,13 @@ int main(int argc, char** argv)
876 897
877 sqlite3_bind_int(ppstmt, 1, rowid); 898 sqlite3_bind_int(ppstmt, 1, rowid);
878 sqlite3_bind_text(ppstmt, 2, pronunciation.phonemes.c_str(), pronunciation.phonemes.length(), SQLITE_TRANSIENT); 899 sqlite3_bind_text(ppstmt, 2, pronunciation.phonemes.c_str(), pronunciation.phonemes.length(), SQLITE_TRANSIENT);
900 sqlite3_bind_int(ppstmt, 3, pronunciation.syllables);
901 sqlite3_bind_text(ppstmt, 4, pronunciation.stress.c_str(), pronunciation.stress.length(), SQLITE_TRANSIENT);
879 902
880 if (!pronunciation.rhyme.empty()) 903 if (!pronunciation.rhyme.empty())
881 { 904 {
882 sqlite3_bind_text(ppstmt, 3, pronunciation.prerhyme.c_str(), pronunciation.prerhyme.length(), SQLITE_TRANSIENT); 905 sqlite3_bind_text(ppstmt, 5, pronunciation.prerhyme.c_str(), pronunciation.prerhyme.length(), SQLITE_TRANSIENT);
883 sqlite3_bind_text(ppstmt, 4, pronunciation.rhyme.c_str(), pronunciation.rhyme.length(), SQLITE_TRANSIENT); 906 sqlite3_bind_text(ppstmt, 6, pronunciation.rhyme.c_str(), pronunciation.rhyme.length(), SQLITE_TRANSIENT);
884 } 907 }
885 908
886 if (sqlite3_step(ppstmt) != SQLITE_DONE) 909 if (sqlite3_step(ppstmt) != SQLITE_DONE)
@@ -1243,9 +1266,9 @@ int main(int argc, char** argv)
1243 { 1266 {
1244 if (!pronunciation.rhyme.empty()) 1267 if (!pronunciation.rhyme.empty())
1245 { 1268 {
1246 query = "INSERT INTO noun_pronunciations (noun_id, pronunciation, prerhyme, rhyme) VALUES (?, ?, ?, ?)"; 1269 query = "INSERT INTO noun_pronunciations (noun_id, pronunciation, syllables, stress, prerhyme, rhyme) VALUES (?, ?, ?, ?, ?, ?)";
1247 } else { 1270 } else {
1248 query = "INSERT INTO noun_pronunciations (noun_id, pronunciation) VALUES (?, ?)"; 1271 query = "INSERT INTO noun_pronunciations (noun_id, pronunciation, syllables, stress) VALUES (?, ?, ?, ?)";
1249 } 1272 }
1250 1273
1251 break; 1274 break;
@@ -1255,9 +1278,9 @@ int main(int argc, char** argv)
1255 { 1278 {
1256 if (!pronunciation.rhyme.empty()) 1279 if (!pronunciation.rhyme.empty())
1257 { 1280 {
1258 query = "INSERT INTO adjective_pronunciations (adjective_id, pronunciation, prerhyme, rhyme) VALUES (?, ?, ?, ?)"; 1281 query = "INSERT INTO adjective_pronunciations (adjective_id, pronunciation, syllables, stress, prerhyme, rhyme) VALUES (?, ?, ?, ?, ?, ?)";
1259 } else { 1282 } else {
1260 query = "INSERT INTO adjective_pronunciations (adjective_id, pronunciation) VALUES (?, ?)"; 1283 query = "INSERT INTO adjective_pronunciations (adjective_id, pronunciation, syllables, stress) VALUES (?, ?, ?, ?)";
1261 } 1284 }
1262 1285
1263 break; 1286 break;
@@ -1267,9 +1290,9 @@ int main(int argc, char** argv)
1267 { 1290 {
1268 if (!pronunciation.rhyme.empty()) 1291 if (!pronunciation.rhyme.empty())
1269 { 1292 {
1270 query = "INSERT INTO adverb_pronunciations (adverb_id, pronunciation, prerhyme, rhyme) VALUES (?, ?, ?, ?)"; 1293 query = "INSERT INTO adverb_pronunciations (adverb_id, pronunciation, syllables, stress, prerhyme, rhyme) VALUES (?, ?, ?, ?, ?, ?)";
1271 } else { 1294 } else {
1272 query = "INSERT INTO adverb_pronunciations (adverb_id, pronunciation) VALUES (?, ?)"; 1295 query = "INSERT INTO adverb_pronunciations (adverb_id, pronunciation, syllables, stress) VALUES (?, ?, ?, ?)";
1273 } 1296 }
1274 1297
1275 break; 1298 break;
@@ -1283,11 +1306,13 @@ int main(int argc, char** argv)
1283 1306
1284 sqlite3_bind_int(ppstmt, 1, rowid); 1307 sqlite3_bind_int(ppstmt, 1, rowid);
1285 sqlite3_bind_text(ppstmt, 2, pronunciation.phonemes.c_str(), pronunciation.phonemes.length(), SQLITE_TRANSIENT); 1308 sqlite3_bind_text(ppstmt, 2, pronunciation.phonemes.c_str(), pronunciation.phonemes.length(), SQLITE_TRANSIENT);
1309 sqlite3_bind_int(ppstmt, 3, pronunciation.syllables);
1310 sqlite3_bind_text(ppstmt, 4, pronunciation.stress.c_str(), pronunciation.stress.length(), SQLITE_TRANSIENT);
1286 1311
1287 if (!pronunciation.rhyme.empty()) 1312 if (!pronunciation.rhyme.empty())
1288 { 1313 {
1289 sqlite3_bind_text(ppstmt, 3, pronunciation.prerhyme.c_str(), pronunciation.prerhyme.length(), SQLITE_TRANSIENT); 1314 sqlite3_bind_text(ppstmt, 5, pronunciation.prerhyme.c_str(), pronunciation.prerhyme.length(), SQLITE_TRANSIENT);
1290 sqlite3_bind_text(ppstmt, 4, pronunciation.rhyme.c_str(), pronunciation.rhyme.length(), SQLITE_TRANSIENT); 1315 sqlite3_bind_text(ppstmt, 6, pronunciation.rhyme.c_str(), pronunciation.rhyme.length(), SQLITE_TRANSIENT);
1291 } 1316 }
1292 1317
1293 if (sqlite3_step(ppstmt) != SQLITE_DONE) 1318 if (sqlite3_step(ppstmt) != SQLITE_DONE)
diff --git a/generator/schema.sql b/generator/schema.sql index 1836c62..410b536 100644 --- a/generator/schema.sql +++ b/generator/schema.sql
@@ -186,6 +186,8 @@ CREATE TABLE `noun_pronunciations` (
186 `pronunciation` VARCHAR(64) NOT NULL, 186 `pronunciation` VARCHAR(64) NOT NULL,
187 `prerhyme` VARCHAR(8), 187 `prerhyme` VARCHAR(8),
188 `rhyme` VARCHAR(64), 188 `rhyme` VARCHAR(64),
189 `syllables` INT NOT NULL,
190 `stress` VARCHAR(64) NOT NULL,
189 FOREIGN KEY (`noun_id`) REFERENCES `nouns`(`noun_id`) 191 FOREIGN KEY (`noun_id`) REFERENCES `nouns`(`noun_id`)
190); 192);
191 193
@@ -195,6 +197,8 @@ CREATE TABLE `verb_pronunciations` (
195 `pronunciation` VARCHAR(64) NOT NULL, 197 `pronunciation` VARCHAR(64) NOT NULL,
196 `prerhyme` VARCHAR(8), 198 `prerhyme` VARCHAR(8),
197 `rhyme` VARCHAR(64), 199 `rhyme` VARCHAR(64),
200 `syllables` INT NOT NULL,
201 `stress` VARCHAR(64) NOT NULL,
198 FOREIGN KEY (`verb_id`) REFERENCES `verbs`(`verb_id`) 202 FOREIGN KEY (`verb_id`) REFERENCES `verbs`(`verb_id`)
199); 203);
200 204
@@ -204,6 +208,8 @@ CREATE TABLE `adjective_pronunciations` (
204 `pronunciation` VARCHAR(64) NOT NULL, 208 `pronunciation` VARCHAR(64) NOT NULL,
205 `prerhyme` VARCHAR(8), 209 `prerhyme` VARCHAR(8),
206 `rhyme` VARCHAR(64), 210 `rhyme` VARCHAR(64),
211 `syllables` INT NOT NULL,
212 `stress` VARCHAR(64) NOT NULL,
207 FOREIGN KEY (`adjective_id`) REFERENCES `adjectives`(`adjective_id`) 213 FOREIGN KEY (`adjective_id`) REFERENCES `adjectives`(`adjective_id`)
208); 214);
209 215
@@ -213,6 +219,8 @@ CREATE TABLE `adverb_pronunciations` (
213 `pronunciation` VARCHAR(64) NOT NULL, 219 `pronunciation` VARCHAR(64) NOT NULL,
214 `prerhyme` VARCHAR(8), 220 `prerhyme` VARCHAR(8),
215 `rhyme` VARCHAR(64), 221 `rhyme` VARCHAR(64),
222 `syllables` INT NOT NULL,
223 `stress` VARCHAR(64) NOT NULL,
216 FOREIGN KEY (`adverb_id`) REFERENCES `adverbs`(`adverb_id`) 224 FOREIGN KEY (`adverb_id`) REFERENCES `adverbs`(`adverb_id`)
217); 225);
218 226
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};