diff options
Diffstat (limited to 'lib/noun_query.cpp')
-rw-r--r-- | lib/noun_query.cpp | 339 |
1 files changed, 196 insertions, 143 deletions
diff --git a/lib/noun_query.cpp b/lib/noun_query.cpp index 04e567d..8f37bf6 100644 --- a/lib/noun_query.cpp +++ b/lib/noun_query.cpp | |||
@@ -33,7 +33,7 @@ namespace verbly { | |||
33 | 33 | ||
34 | noun_query& noun_query::rhymes_with(const word& _word) | 34 | noun_query& noun_query::rhymes_with(const word& _word) |
35 | { | 35 | { |
36 | for (auto rhyme : _word.rhyme_phonemes()) | 36 | for (auto rhyme : _word.get_rhymes()) |
37 | { | 37 | { |
38 | _rhymes.push_back(rhyme); | 38 | _rhymes.push_back(rhyme); |
39 | } | 39 | } |
@@ -53,6 +53,34 @@ namespace verbly { | |||
53 | return *this; | 53 | return *this; |
54 | } | 54 | } |
55 | 55 | ||
56 | noun_query& noun_query::has_rhyming_noun() | ||
57 | { | ||
58 | _has_rhyming_noun = true; | ||
59 | |||
60 | return *this; | ||
61 | } | ||
62 | |||
63 | noun_query& noun_query::has_rhyming_adjective() | ||
64 | { | ||
65 | _has_rhyming_adjective = true; | ||
66 | |||
67 | return *this; | ||
68 | } | ||
69 | |||
70 | noun_query& noun_query::has_rhyming_adverb() | ||
71 | { | ||
72 | _has_rhyming_adverb = true; | ||
73 | |||
74 | return *this; | ||
75 | } | ||
76 | |||
77 | noun_query& noun_query::has_rhyming_verb() | ||
78 | { | ||
79 | _has_rhyming_verb = true; | ||
80 | |||
81 | return *this; | ||
82 | } | ||
83 | |||
56 | noun_query& noun_query::with_singular_form(std::string _arg) | 84 | noun_query& noun_query::with_singular_form(std::string _arg) |
57 | { | 85 | { |
58 | _with_singular_form.push_back(_arg); | 86 | _with_singular_form.push_back(_arg); |
@@ -377,6 +405,21 @@ namespace verbly { | |||
377 | 405 | ||
378 | return *this; | 406 | return *this; |
379 | } | 407 | } |
408 | |||
409 | noun_query& noun_query::at_least_n_images(int _arg) | ||
410 | { | ||
411 | _at_least_n_images = _arg; | ||
412 | |||
413 | return *this; | ||
414 | } | ||
415 | |||
416 | noun_query& noun_query::with_wnid(int _arg) | ||
417 | { | ||
418 | _with_wnid.insert(_arg); | ||
419 | |||
420 | return *this; | ||
421 | } | ||
422 | |||
380 | /* | 423 | /* |
381 | noun_query& noun_query::derived_from(const word& _w) | 424 | noun_query& noun_query::derived_from(const word& _w) |
382 | { | 425 | { |
@@ -464,8 +507,9 @@ namespace verbly { | |||
464 | construct << " "; | 507 | construct << " "; |
465 | } | 508 | } |
466 | 509 | ||
467 | construct << "SELECT noun_id, singular, plural FROM nouns"; | 510 | construct << "SELECT noun_id, singular, plural, wnid FROM nouns"; |
468 | std::list<std::string> conditions; | 511 | std::list<std::string> conditions; |
512 | std::list<binding> bindings; | ||
469 | 513 | ||
470 | if (_has_prn) | 514 | if (_has_prn) |
471 | { | 515 | { |
@@ -474,21 +518,53 @@ namespace verbly { | |||
474 | 518 | ||
475 | if (!_rhymes.empty()) | 519 | if (!_rhymes.empty()) |
476 | { | 520 | { |
477 | std::list<std::string> clauses(_rhymes.size(), "pronunciation LIKE @RHMPRN"); | 521 | std::list<std::string> clauses(_rhymes.size(), "(prerhyme != ? AND rhyme = ?)"); |
478 | std::string cond = "noun_id IN (SELECT noun_id FROM noun_pronunciations WHERE " + verbly::implode(std::begin(clauses), std::end(clauses), " OR ") + ")"; | 522 | std::string cond = "noun_id IN (SELECT noun_id FROM noun_pronunciations WHERE " + verbly::implode(std::begin(clauses), std::end(clauses), " OR ") + ")"; |
479 | conditions.push_back(cond); | 523 | conditions.push_back(cond); |
524 | |||
525 | for (auto rhy : _rhymes) | ||
526 | { | ||
527 | bindings.emplace_back(rhy.get_prerhyme()); | ||
528 | bindings.emplace_back(rhy.get_rhyme()); | ||
529 | } | ||
480 | } | 530 | } |
481 | 531 | ||
532 | if (_has_rhyming_noun) | ||
533 | { | ||
534 | 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 noun_pronunciations AS rhmp ON rhmp.prerhyme != curp.prerhyme AND rhmp.rhyme = curp.rhyme AND rhmp.noun_id != curp.noun_id)"); | ||
535 | } | ||
536 | |||
537 | if (_has_rhyming_adjective) | ||
538 | { | ||
539 | 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 adjective_pronunciations AS rhmp ON rhmp.prerhyme != curp.prerhyme AND rhmp.rhyme = curp.rhyme)"); | ||
540 | } | ||
541 | |||
542 | if (_has_rhyming_adverb) | ||
543 | { | ||
544 | 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 adverb_pronunciations AS rhmp ON rhmp.prerhyme != curp.prerhyme AND rhmp.rhyme = curp.rhyme)"); | ||
545 | } | ||
546 | |||
547 | if (_has_rhyming_verb) | ||
548 | { | ||
549 | 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)"); | ||
550 | } | ||
551 | |||
482 | for (auto except : _except) | 552 | for (auto except : _except) |
483 | { | 553 | { |
484 | conditions.push_back("noun_id != @EXCID"); | 554 | conditions.push_back("noun_id != ?"); |
555 | bindings.emplace_back(except._id); | ||
485 | } | 556 | } |
486 | 557 | ||
487 | if (!_with_singular_form.empty()) | 558 | if (!_with_singular_form.empty()) |
488 | { | 559 | { |
489 | std::list<std::string> clauses(_with_singular_form.size(), "singular = @SFORM"); | 560 | std::list<std::string> clauses(_with_singular_form.size(), "singular = ?"); |
490 | std::string cond = "(" + verbly::implode(std::begin(clauses), std::end(clauses), " OR ") + ")"; | 561 | std::string cond = "(" + verbly::implode(std::begin(clauses), std::end(clauses), " OR ") + ")"; |
491 | conditions.push_back(cond); | 562 | conditions.push_back(cond); |
563 | |||
564 | for (auto form : _with_singular_form) | ||
565 | { | ||
566 | bindings.emplace_back(form); | ||
567 | } | ||
492 | } | 568 | } |
493 | 569 | ||
494 | if (_requires_plural_form) | 570 | if (_requires_plural_form) |
@@ -503,11 +579,13 @@ namespace verbly { | |||
503 | { | 579 | { |
504 | case filter<std::string>::type::singleton: | 580 | case filter<std::string>::type::singleton: |
505 | { | 581 | { |
582 | bindings.emplace_back(f.get_elem() + "%"); | ||
583 | |||
506 | if (notlogic == f.get_notlogic()) | 584 | if (notlogic == f.get_notlogic()) |
507 | { | 585 | { |
508 | return "singular LIKE @PREFIX"; | 586 | return "singular LIKE ?"; |
509 | } else { | 587 | } else { |
510 | return "singular NOT LIKE @PREFIX"; | 588 | return "singular NOT LIKE ?"; |
511 | } | 589 | } |
512 | } | 590 | } |
513 | 591 | ||
@@ -540,11 +618,13 @@ namespace verbly { | |||
540 | { | 618 | { |
541 | case filter<std::string>::type::singleton: | 619 | case filter<std::string>::type::singleton: |
542 | { | 620 | { |
621 | bindings.emplace_back("%" + f.get_elem()); | ||
622 | |||
543 | if (notlogic == f.get_notlogic()) | 623 | if (notlogic == f.get_notlogic()) |
544 | { | 624 | { |
545 | return "singular LIKE @SUFFIX"; | 625 | return "singular LIKE ?"; |
546 | } else { | 626 | } else { |
547 | return "singular NOT LIKE @SUFFIX"; | 627 | return "singular NOT LIKE ?"; |
548 | } | 628 | } |
549 | } | 629 | } |
550 | 630 | ||
@@ -572,7 +652,8 @@ namespace verbly { | |||
572 | 652 | ||
573 | if (_with_complexity != unlimited) | 653 | if (_with_complexity != unlimited) |
574 | { | 654 | { |
575 | conditions.push_back("complexity = @COMPLEX"); | 655 | conditions.push_back("complexity = ?"); |
656 | bindings.emplace_back(_with_complexity); | ||
576 | } | 657 | } |
577 | 658 | ||
578 | if (_is_hypernym) | 659 | if (_is_hypernym) |
@@ -597,11 +678,13 @@ namespace verbly { | |||
597 | { | 678 | { |
598 | case filter<noun>::type::singleton: | 679 | case filter<noun>::type::singleton: |
599 | { | 680 | { |
681 | bindings.emplace_back(f.get_elem()._id); | ||
682 | |||
600 | if (notlogic == f.get_notlogic()) | 683 | if (notlogic == f.get_notlogic()) |
601 | { | 684 | { |
602 | return "hyponym_id = @HYPO"; | 685 | return "hyponym_id = ?"; |
603 | } else { | 686 | } else { |
604 | return "hyponym_id != @HYPO"; | 687 | return "hyponym_id != ?"; |
605 | } | 688 | } |
606 | } | 689 | } |
607 | 690 | ||
@@ -725,11 +808,13 @@ namespace verbly { | |||
725 | { | 808 | { |
726 | case filter<noun>::type::singleton: | 809 | case filter<noun>::type::singleton: |
727 | { | 810 | { |
811 | bindings.emplace_back(f.get_elem()._id); | ||
812 | |||
728 | if (notlogic == f.get_notlogic()) | 813 | if (notlogic == f.get_notlogic()) |
729 | { | 814 | { |
730 | return "hypernym_id = @HYPER"; | 815 | return "hypernym_id = ?"; |
731 | } else { | 816 | } else { |
732 | return "hypernym_id != @HYPER"; | 817 | return "hypernym_id != ?"; |
733 | } | 818 | } |
734 | } | 819 | } |
735 | 820 | ||
@@ -779,11 +864,13 @@ namespace verbly { | |||
779 | { | 864 | { |
780 | case filter<noun>::type::singleton: | 865 | case filter<noun>::type::singleton: |
781 | { | 866 | { |
867 | bindings.emplace_back(f.get_elem()._id); | ||
868 | |||
782 | if (notlogic == f.get_notlogic()) | 869 | if (notlogic == f.get_notlogic()) |
783 | { | 870 | { |
784 | return "holonym_id = @PHOLO"; | 871 | return "holonym_id = ?"; |
785 | } else { | 872 | } else { |
786 | return "holonym_id != @PHOLO"; | 873 | return "holonym_id != ?"; |
787 | } | 874 | } |
788 | } | 875 | } |
789 | 876 | ||
@@ -870,11 +957,13 @@ namespace verbly { | |||
870 | { | 957 | { |
871 | case filter<noun>::type::singleton: | 958 | case filter<noun>::type::singleton: |
872 | { | 959 | { |
960 | bindings.emplace_back(f.get_elem()._id); | ||
961 | |||
873 | if (notlogic == f.get_notlogic()) | 962 | if (notlogic == f.get_notlogic()) |
874 | { | 963 | { |
875 | return "meronym_id = @PMERO"; | 964 | return "meronym_id = ?"; |
876 | } else { | 965 | } else { |
877 | return "meronym_id != @PMERO"; | 966 | return "meronym_id != ?"; |
878 | } | 967 | } |
879 | } | 968 | } |
880 | 969 | ||
@@ -961,11 +1050,13 @@ namespace verbly { | |||
961 | { | 1050 | { |
962 | case filter<noun>::type::singleton: | 1051 | case filter<noun>::type::singleton: |
963 | { | 1052 | { |
1053 | bindings.emplace_back(f.get_elem()._id); | ||
1054 | |||
964 | if (notlogic == f.get_notlogic()) | 1055 | if (notlogic == f.get_notlogic()) |
965 | { | 1056 | { |
966 | return "holonym_id = @SHOLO"; | 1057 | return "holonym_id = ?"; |
967 | } else { | 1058 | } else { |
968 | return "holonym_id != @SHOLO"; | 1059 | return "holonym_id != ?"; |
969 | } | 1060 | } |
970 | } | 1061 | } |
971 | 1062 | ||
@@ -1052,11 +1143,13 @@ namespace verbly { | |||
1052 | { | 1143 | { |
1053 | case filter<noun>::type::singleton: | 1144 | case filter<noun>::type::singleton: |
1054 | { | 1145 | { |
1146 | bindings.emplace_back(f.get_elem()._id); | ||
1147 | |||
1055 | if (notlogic == f.get_notlogic()) | 1148 | if (notlogic == f.get_notlogic()) |
1056 | { | 1149 | { |
1057 | return "meronym_id = @SMERO"; | 1150 | return "meronym_id = ?"; |
1058 | } else { | 1151 | } else { |
1059 | return "meronym_id != @SMERO"; | 1152 | return "meronym_id != ?"; |
1060 | } | 1153 | } |
1061 | } | 1154 | } |
1062 | 1155 | ||
@@ -1143,11 +1236,13 @@ namespace verbly { | |||
1143 | { | 1236 | { |
1144 | case filter<noun>::type::singleton: | 1237 | case filter<noun>::type::singleton: |
1145 | { | 1238 | { |
1239 | bindings.emplace_back(f.get_elem()._id); | ||
1240 | |||
1146 | if (notlogic == f.get_notlogic()) | 1241 | if (notlogic == f.get_notlogic()) |
1147 | { | 1242 | { |
1148 | return "holonym_id = @MHOLO"; | 1243 | return "holonym_id = ?"; |
1149 | } else { | 1244 | } else { |
1150 | return "holonym_id != @MHOLO"; | 1245 | return "holonym_id != ?"; |
1151 | } | 1246 | } |
1152 | } | 1247 | } |
1153 | 1248 | ||
@@ -1234,11 +1329,13 @@ namespace verbly { | |||
1234 | { | 1329 | { |
1235 | case filter<noun>::type::singleton: | 1330 | case filter<noun>::type::singleton: |
1236 | { | 1331 | { |
1332 | bindings.emplace_back(f.get_elem()._id); | ||
1333 | |||
1237 | if (notlogic == f.get_notlogic()) | 1334 | if (notlogic == f.get_notlogic()) |
1238 | { | 1335 | { |
1239 | return "meronym_id = @MMERO"; | 1336 | return "meronym_id = ?"; |
1240 | } else { | 1337 | } else { |
1241 | return "meronym_id != @MMERO"; | 1338 | return "meronym_id != ?"; |
1242 | } | 1339 | } |
1243 | } | 1340 | } |
1244 | 1341 | ||
@@ -1335,11 +1432,13 @@ namespace verbly { | |||
1335 | { | 1432 | { |
1336 | case filter<noun>::type::singleton: | 1433 | case filter<noun>::type::singleton: |
1337 | { | 1434 | { |
1435 | bindings.emplace_back(f.get_elem()._id); | ||
1436 | |||
1338 | if (notlogic == f.get_notlogic()) | 1437 | if (notlogic == f.get_notlogic()) |
1339 | { | 1438 | { |
1340 | return "class_id = @CLSID"; | 1439 | return "class_id = ?"; |
1341 | } else { | 1440 | } else { |
1342 | return "class_id != @CLSID"; | 1441 | return "class_id != ?"; |
1343 | } | 1442 | } |
1344 | } | 1443 | } |
1345 | 1444 | ||
@@ -1389,11 +1488,13 @@ namespace verbly { | |||
1389 | { | 1488 | { |
1390 | case filter<noun>::type::singleton: | 1489 | case filter<noun>::type::singleton: |
1391 | { | 1490 | { |
1491 | bindings.emplace_back(f.get_elem()._id); | ||
1492 | |||
1392 | if (notlogic == f.get_notlogic()) | 1493 | if (notlogic == f.get_notlogic()) |
1393 | { | 1494 | { |
1394 | return "instance_id = @INSID"; | 1495 | return "instance_id = ?"; |
1395 | } else { | 1496 | } else { |
1396 | return "instance_id != @INSID"; | 1497 | return "instance_id != ?"; |
1397 | } | 1498 | } |
1398 | } | 1499 | } |
1399 | 1500 | ||
@@ -1443,11 +1544,13 @@ namespace verbly { | |||
1443 | { | 1544 | { |
1444 | case filter<noun>::type::singleton: | 1545 | case filter<noun>::type::singleton: |
1445 | { | 1546 | { |
1547 | bindings.emplace_back(f.get_elem()._id); | ||
1548 | |||
1446 | if (notlogic == f.get_notlogic()) | 1549 | if (notlogic == f.get_notlogic()) |
1447 | { | 1550 | { |
1448 | return "noun_1_id = @SYNID"; | 1551 | return "noun_1_id = ?"; |
1449 | } else { | 1552 | } else { |
1450 | return "noun_1_id != @SYNID"; | 1553 | return "noun_1_id != ?"; |
1451 | } | 1554 | } |
1452 | } | 1555 | } |
1453 | 1556 | ||
@@ -1497,11 +1600,13 @@ namespace verbly { | |||
1497 | { | 1600 | { |
1498 | case filter<noun>::type::singleton: | 1601 | case filter<noun>::type::singleton: |
1499 | { | 1602 | { |
1603 | bindings.emplace_back(f.get_elem()._id); | ||
1604 | |||
1500 | if (notlogic == f.get_notlogic()) | 1605 | if (notlogic == f.get_notlogic()) |
1501 | { | 1606 | { |
1502 | return "noun_1_id = @ANTID"; | 1607 | return "noun_1_id = ?"; |
1503 | } else { | 1608 | } else { |
1504 | return "noun_1_id != @ANTID"; | 1609 | return "noun_1_id != ?"; |
1505 | } | 1610 | } |
1506 | } | 1611 | } |
1507 | 1612 | ||
@@ -1551,11 +1656,13 @@ namespace verbly { | |||
1551 | { | 1656 | { |
1552 | case filter<adjective>::type::singleton: | 1657 | case filter<adjective>::type::singleton: |
1553 | { | 1658 | { |
1659 | bindings.emplace_back(f.get_elem()._id); | ||
1660 | |||
1554 | if (notlogic == f.get_notlogic()) | 1661 | if (notlogic == f.get_notlogic()) |
1555 | { | 1662 | { |
1556 | return "pertainym_id = @PERID"; | 1663 | return "pertainym_id = ?"; |
1557 | } else { | 1664 | } else { |
1558 | return "pertainym_id != @PERID"; | 1665 | return "pertainym_id != ?"; |
1559 | } | 1666 | } |
1560 | } | 1667 | } |
1561 | 1668 | ||
@@ -1605,11 +1712,13 @@ namespace verbly { | |||
1605 | { | 1712 | { |
1606 | case filter<adjective>::type::singleton: | 1713 | case filter<adjective>::type::singleton: |
1607 | { | 1714 | { |
1715 | bindings.emplace_back(f.get_elem()._id); | ||
1716 | |||
1608 | if (notlogic == f.get_notlogic()) | 1717 | if (notlogic == f.get_notlogic()) |
1609 | { | 1718 | { |
1610 | return "adjective_id = @VALID"; | 1719 | return "adjective_id = ?"; |
1611 | } else { | 1720 | } else { |
1612 | return "adjective_id != @VALID"; | 1721 | return "adjective_id != ?"; |
1613 | } | 1722 | } |
1614 | } | 1723 | } |
1615 | 1724 | ||
@@ -1636,6 +1745,25 @@ namespace verbly { | |||
1636 | cond << ")"; | 1745 | cond << ")"; |
1637 | conditions.push_back(cond.str()); | 1746 | conditions.push_back(cond.str()); |
1638 | } | 1747 | } |
1748 | |||
1749 | if (_at_least_n_images != unlimited) | ||
1750 | { | ||
1751 | conditions.push_back("images >= ?"); | ||
1752 | bindings.emplace_back(_at_least_n_images); | ||
1753 | } | ||
1754 | |||
1755 | if (!_with_wnid.empty()) | ||
1756 | { | ||
1757 | std::vector<std::string> clauses(_with_wnid.size(), "wnid = ?"); | ||
1758 | std::string cond = verbly::implode(std::begin(clauses), std::end(clauses), " OR "); | ||
1759 | conditions.push_back("(" + cond + ")"); | ||
1760 | |||
1761 | for (auto wnid : _with_wnid) | ||
1762 | { | ||
1763 | bindings.emplace_back(wnid); | ||
1764 | } | ||
1765 | } | ||
1766 | |||
1639 | /* | 1767 | /* |
1640 | if (!_derived_from_adjective.empty()) | 1768 | if (!_derived_from_adjective.empty()) |
1641 | { | 1769 | { |
@@ -1701,115 +1829,30 @@ namespace verbly { | |||
1701 | { | 1829 | { |
1702 | throw std::runtime_error(sqlite3_errmsg(_data.ppdb)); | 1830 | throw std::runtime_error(sqlite3_errmsg(_data.ppdb)); |
1703 | } | 1831 | } |
1704 | 1832 | ||
1705 | if (!_rhymes.empty()) | 1833 | int i = 1; |
1834 | for (auto& binding : bindings) | ||
1706 | { | 1835 | { |
1707 | int i = 0; | 1836 | switch (binding.get_type()) |
1708 | for (auto rhyme : _rhymes) | ||
1709 | { | 1837 | { |
1710 | std::string rhymer = "%" + rhyme; | 1838 | case binding::type::integer: |
1711 | sqlite3_bind_text(ppstmt, sqlite3_bind_parameter_index(ppstmt, "@RHMPRN"), rhymer.c_str(), rhymer.length(), SQLITE_STATIC); | 1839 | { |
1840 | sqlite3_bind_int(ppstmt, i, binding.get_integer()); | ||
1841 | |||
1842 | break; | ||
1843 | } | ||
1712 | 1844 | ||
1713 | i++; | 1845 | case binding::type::string: |
1846 | { | ||
1847 | sqlite3_bind_text(ppstmt, i, binding.get_string().c_str(), binding.get_string().length(), SQLITE_TRANSIENT); | ||
1848 | |||
1849 | break; | ||
1850 | } | ||
1714 | } | 1851 | } |
1852 | |||
1853 | i++; | ||
1715 | } | 1854 | } |
1716 | 1855 | ||
1717 | for (auto except : _except) | ||
1718 | { | ||
1719 | sqlite3_bind_int(ppstmt, sqlite3_bind_parameter_index(ppstmt, "@EXCID"), except._id); | ||
1720 | } | ||
1721 | |||
1722 | for (auto sform : _with_singular_form) | ||
1723 | { | ||
1724 | sqlite3_bind_text(ppstmt, sqlite3_bind_parameter_index(ppstmt, "@SFORM"), sform.c_str(), sform.size(), SQLITE_STATIC); | ||
1725 | } | ||
1726 | |||
1727 | for (auto prefix : _with_prefix.inorder_flatten()) | ||
1728 | { | ||
1729 | std::string pfat = prefix + "%"; | ||
1730 | sqlite3_bind_text(ppstmt, sqlite3_bind_parameter_index(ppstmt, "@PREFIX"), pfat.c_str(), pfat.length(), SQLITE_STATIC); | ||
1731 | } | ||
1732 | |||
1733 | for (auto suffix : _with_suffix.inorder_flatten()) | ||
1734 | { | ||
1735 | std::string pfat = "%" + suffix; | ||
1736 | sqlite3_bind_text(ppstmt, sqlite3_bind_parameter_index(ppstmt, "@SUFFIX"), pfat.c_str(), pfat.length(), SQLITE_STATIC); | ||
1737 | } | ||
1738 | |||
1739 | if (_with_complexity != unlimited) | ||
1740 | { | ||
1741 | sqlite3_bind_int(ppstmt, sqlite3_bind_parameter_index(ppstmt, "@COMPLEX"), _with_complexity); | ||
1742 | } | ||
1743 | |||
1744 | for (auto hyponym : _hypernym_of.inorder_flatten()) | ||
1745 | { | ||
1746 | sqlite3_bind_int(ppstmt, sqlite3_bind_parameter_index(ppstmt, "@HYPO"), hyponym._id); | ||
1747 | } | ||
1748 | |||
1749 | for (auto hypernym : _hyponym_of.inorder_flatten()) | ||
1750 | { | ||
1751 | sqlite3_bind_int(ppstmt, sqlite3_bind_parameter_index(ppstmt, "@HYPER"), hypernym._id); | ||
1752 | } | ||
1753 | |||
1754 | for (auto holonym : _part_meronym_of.inorder_flatten()) | ||
1755 | { | ||
1756 | sqlite3_bind_int(ppstmt, sqlite3_bind_parameter_index(ppstmt, "@PHOLO"), holonym._id); | ||
1757 | } | ||
1758 | |||
1759 | for (auto meronym : _part_holonym_of.inorder_flatten()) | ||
1760 | { | ||
1761 | sqlite3_bind_int(ppstmt, sqlite3_bind_parameter_index(ppstmt, "@PMERO"), meronym._id); | ||
1762 | } | ||
1763 | |||
1764 | for (auto holonym : _substance_meronym_of.inorder_flatten()) | ||
1765 | { | ||
1766 | sqlite3_bind_int(ppstmt, sqlite3_bind_parameter_index(ppstmt, "@SHOLO"), holonym._id); | ||
1767 | } | ||
1768 | |||
1769 | for (auto meronym : _substance_holonym_of.inorder_flatten()) | ||
1770 | { | ||
1771 | sqlite3_bind_int(ppstmt, sqlite3_bind_parameter_index(ppstmt, "@SMERO"), meronym._id); | ||
1772 | } | ||
1773 | |||
1774 | for (auto holonym : _member_meronym_of.inorder_flatten()) | ||
1775 | { | ||
1776 | sqlite3_bind_int(ppstmt, sqlite3_bind_parameter_index(ppstmt, "@MHOLO"), holonym._id); | ||
1777 | } | ||
1778 | |||
1779 | for (auto meronym : _member_holonym_of.inorder_flatten()) | ||
1780 | { | ||
1781 | sqlite3_bind_int(ppstmt, sqlite3_bind_parameter_index(ppstmt, "@MMERO"), meronym._id); | ||
1782 | } | ||
1783 | |||
1784 | for (auto cls : _instance_of.inorder_flatten()) | ||
1785 | { | ||
1786 | sqlite3_bind_int(ppstmt, sqlite3_bind_parameter_index(ppstmt, "@CLSID"), cls._id); | ||
1787 | } | ||
1788 | |||
1789 | for (auto inst : _class_of.inorder_flatten()) | ||
1790 | { | ||
1791 | sqlite3_bind_int(ppstmt, sqlite3_bind_parameter_index(ppstmt, "@INSID"), inst._id); | ||
1792 | } | ||
1793 | |||
1794 | for (auto synonym : _synonym_of.inorder_flatten()) | ||
1795 | { | ||
1796 | sqlite3_bind_int(ppstmt, sqlite3_bind_parameter_index(ppstmt, "@SYNID"), synonym._id); | ||
1797 | } | ||
1798 | |||
1799 | for (auto antonym : _antonym_of.inorder_flatten()) | ||
1800 | { | ||
1801 | sqlite3_bind_int(ppstmt, sqlite3_bind_parameter_index(ppstmt, "@ANTID"), antonym._id); | ||
1802 | } | ||
1803 | |||
1804 | for (auto pertainym : _anti_pertainym_of.inorder_flatten()) | ||
1805 | { | ||
1806 | sqlite3_bind_int(ppstmt, sqlite3_bind_parameter_index(ppstmt, "@PERID"), pertainym._id); | ||
1807 | } | ||
1808 | |||
1809 | for (auto value : _attribute_of.inorder_flatten()) | ||
1810 | { | ||
1811 | sqlite3_bind_int(ppstmt, sqlite3_bind_parameter_index(ppstmt, "@VALID"), value._id); | ||
1812 | } | ||
1813 | /* | 1856 | /* |
1814 | for (auto adj : _derived_from_adjective) | 1857 | for (auto adj : _derived_from_adjective) |
1815 | { | 1858 | { |
@@ -1851,6 +1894,8 @@ namespace verbly { | |||
1851 | { | 1894 | { |
1852 | tnc._plural = std::string(reinterpret_cast<const char*>(sqlite3_column_text(ppstmt, 2))); | 1895 | tnc._plural = std::string(reinterpret_cast<const char*>(sqlite3_column_text(ppstmt, 2))); |
1853 | } | 1896 | } |
1897 | |||
1898 | tnc._wnid = sqlite3_column_int(ppstmt, 3); | ||
1854 | 1899 | ||
1855 | output.push_back(tnc); | 1900 | output.push_back(tnc); |
1856 | } | 1901 | } |
@@ -1859,7 +1904,7 @@ namespace verbly { | |||
1859 | 1904 | ||
1860 | for (auto& noun : output) | 1905 | for (auto& noun : output) |
1861 | { | 1906 | { |
1862 | query = "SELECT pronunciation FROM noun_pronunciations WHERE noun_id = ?"; | 1907 | query = "SELECT pronunciation, prerhyme, rhyme FROM noun_pronunciations WHERE noun_id = ?"; |
1863 | if (sqlite3_prepare_v2(_data.ppdb, query.c_str(), query.length(), &ppstmt, NULL) != SQLITE_OK) | 1908 | if (sqlite3_prepare_v2(_data.ppdb, query.c_str(), query.length(), &ppstmt, NULL) != SQLITE_OK) |
1864 | { | 1909 | { |
1865 | throw std::runtime_error(sqlite3_errmsg(_data.ppdb)); | 1910 | throw std::runtime_error(sqlite3_errmsg(_data.ppdb)); |
@@ -1873,6 +1918,14 @@ namespace verbly { | |||
1873 | auto phonemes = verbly::split<std::list<std::string>>(pronunciation, " "); | 1918 | auto phonemes = verbly::split<std::list<std::string>>(pronunciation, " "); |
1874 | 1919 | ||
1875 | noun.pronunciations.push_back(phonemes); | 1920 | noun.pronunciations.push_back(phonemes); |
1921 | |||
1922 | if ((sqlite3_column_type(ppstmt, 1) != SQLITE_NULL) && (sqlite3_column_type(ppstmt, 2) != SQLITE_NULL)) | ||
1923 | { | ||
1924 | std::string prerhyme(reinterpret_cast<const char*>(sqlite3_column_text(ppstmt, 1))); | ||
1925 | std::string rhyming(reinterpret_cast<const char*>(sqlite3_column_text(ppstmt, 2))); | ||
1926 | |||
1927 | noun.rhymes.emplace_back(prerhyme, rhyming); | ||
1928 | } | ||
1876 | } | 1929 | } |
1877 | 1930 | ||
1878 | sqlite3_finalize(ppstmt); | 1931 | sqlite3_finalize(ppstmt); |