summary refs log tree commit diff stats
path: root/lib/adjective_query.cpp
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2016-04-15 17:24:44 -0400
committerKelly Rauchenberger <fefferburbia@gmail.com>2016-04-15 17:24:44 -0400
commit040ee58fecdc9c478004bc2e554e1ae126ec4602 (patch)
tree672a75690952ba8055ab9765ba0a475e056e35d4 /lib/adjective_query.cpp
parent3a225f5eb709262b9d44d49519136ea9a2a71000 (diff)
downloadverbly-040ee58fecdc9c478004bc2e554e1ae126ec4602.tar.gz
verbly-040ee58fecdc9c478004bc2e554e1ae126ec4602.tar.bz2
verbly-040ee58fecdc9c478004bc2e554e1ae126ec4602.zip
Added support for ImageNet and fixed bug with query interface
Datafile change: nouns now know how many images are associated with them on ImageNet, and also have their WordNet synset ID saved so that you can query for images of that noun via the ImageNet API. So far, verbly only exposes the ImageNet API URL, and doesn't actually interact with it itself. This may be changed in the future.

The query interface had a huge issue in which multiple instances of the same condition would overwrite each other. This has been fixed.
Diffstat (limited to 'lib/adjective_query.cpp')
-rw-r--r--lib/adjective_query.cpp147
1 files changed, 64 insertions, 83 deletions
diff --git a/lib/adjective_query.cpp b/lib/adjective_query.cpp index 283fdca..a7f915c 100644 --- a/lib/adjective_query.cpp +++ b/lib/adjective_query.cpp
@@ -218,6 +218,7 @@ namespace verbly {
218 std::stringstream construct; 218 std::stringstream construct;
219 construct << "SELECT adjective_id, base_form, comparative, superlative, position FROM adjectives"; 219 construct << "SELECT adjective_id, base_form, comparative, superlative, position FROM adjectives";
220 std::list<std::string> conditions; 220 std::list<std::string> conditions;
221 std::list<binding> bindings;
221 222
222 if (_has_prn) 223 if (_has_prn)
223 { 224 {
@@ -226,14 +227,20 @@ namespace verbly {
226 227
227 if (!_rhymes.empty()) 228 if (!_rhymes.empty())
228 { 229 {
229 std::list<std::string> clauses(_rhymes.size(), "pronunciation LIKE @RHMPRN"); 230 std::list<std::string> clauses(_rhymes.size(), "pronunciation LIKE ?");
230 std::string cond = "adjective_id IN (SELECT adjective_id FROM adjective_pronunciations WHERE " + verbly::implode(std::begin(clauses), std::end(clauses), " OR ") + ")"; 231 std::string cond = "adjective_id IN (SELECT adjective_id FROM adjective_pronunciations WHERE " + verbly::implode(std::begin(clauses), std::end(clauses), " OR ") + ")";
231 conditions.push_back(cond); 232 conditions.push_back(cond);
233
234 for (auto rhyme : _rhymes)
235 {
236 bindings.emplace_back("%" + rhyme);
237 }
232 } 238 }
233 239
234 for (auto except : _except) 240 for (auto except : _except)
235 { 241 {
236 conditions.push_back("adjective_id != @EXCID"); 242 conditions.push_back("adjective_id != ?");
243 bindings.emplace_back(except._id);
237 } 244 }
238 245
239 if (_requires_comparative_form) 246 if (_requires_comparative_form)
@@ -261,11 +268,13 @@ namespace verbly {
261 { 268 {
262 case filter<std::string>::type::singleton: 269 case filter<std::string>::type::singleton:
263 { 270 {
271 bindings.emplace_back(f.get_elem() + "%");
272
264 if (notlogic == f.get_notlogic()) 273 if (notlogic == f.get_notlogic())
265 { 274 {
266 return "base_form LIKE @PREFIX"; 275 return "base_form LIKE ?";
267 } else { 276 } else {
268 return "base_form NOT LIKE @PREFIX"; 277 return "base_form NOT LIKE ?";
269 } 278 }
270 } 279 }
271 280
@@ -298,11 +307,13 @@ namespace verbly {
298 { 307 {
299 case filter<std::string>::type::singleton: 308 case filter<std::string>::type::singleton:
300 { 309 {
310 bindings.emplace_back("%" + f.get_elem());
311
301 if (notlogic == f.get_notlogic()) 312 if (notlogic == f.get_notlogic())
302 { 313 {
303 return "base_form LIKE @SUFFIX"; 314 return "base_form LIKE ?";
304 } else { 315 } else {
305 return "base_form NOT LIKE @SUFFIX"; 316 return "base_form NOT LIKE ?";
306 } 317 }
307 } 318 }
308 319
@@ -330,7 +341,8 @@ namespace verbly {
330 341
331 if (_with_complexity != unlimited) 342 if (_with_complexity != unlimited)
332 { 343 {
333 conditions.push_back("complexity = @COMPLEX"); 344 conditions.push_back("complexity = ?");
345 bindings.emplace_back(_with_complexity);
334 } 346 }
335 347
336 if (_is_variant) 348 if (_is_variant)
@@ -355,11 +367,13 @@ namespace verbly {
355 { 367 {
356 case filter<noun>::type::singleton: 368 case filter<noun>::type::singleton:
357 { 369 {
370 bindings.emplace_back(f.get_elem()._id);
371
358 if (notlogic == f.get_notlogic()) 372 if (notlogic == f.get_notlogic())
359 { 373 {
360 return "noun_id = @ATTRID"; 374 return "noun_id = ?";
361 } else { 375 } else {
362 return "noun_id != @ATTRID"; 376 return "noun_id != ?";
363 } 377 }
364 } 378 }
365 379
@@ -409,11 +423,13 @@ namespace verbly {
409 { 423 {
410 case filter<adjective>::type::singleton: 424 case filter<adjective>::type::singleton:
411 { 425 {
426 bindings.emplace_back(f.get_elem()._id);
427
412 if (notlogic == f.get_notlogic()) 428 if (notlogic == f.get_notlogic())
413 { 429 {
414 return "adjective_1_id = @ANTID"; 430 return "adjective_1_id = ?";
415 } else { 431 } else {
416 return "adjective_1_id != @ANTID"; 432 return "adjective_1_id != ?";
417 } 433 }
418 } 434 }
419 435
@@ -463,11 +479,13 @@ namespace verbly {
463 { 479 {
464 case filter<adjective>::type::singleton: 480 case filter<adjective>::type::singleton:
465 { 481 {
482 bindings.emplace_back(f.get_elem()._id);
483
466 if (notlogic == f.get_notlogic()) 484 if (notlogic == f.get_notlogic())
467 { 485 {
468 return "adjective_1_id = @SYNID"; 486 return "adjective_1_id = ?";
469 } else { 487 } else {
470 return "adjective_1_id != @SYNID"; 488 return "adjective_1_id != ?";
471 } 489 }
472 } 490 }
473 491
@@ -517,11 +535,13 @@ namespace verbly {
517 { 535 {
518 case filter<adjective>::type::singleton: 536 case filter<adjective>::type::singleton:
519 { 537 {
538 bindings.emplace_back(f.get_elem()._id);
539
520 if (notlogic == f.get_notlogic()) 540 if (notlogic == f.get_notlogic())
521 { 541 {
522 return "specific_id = @SPECID"; 542 return "specific_id = ?";
523 } else { 543 } else {
524 return "specific_id != @SPECID"; 544 return "specific_id != ?";
525 } 545 }
526 } 546 }
527 547
@@ -571,11 +591,13 @@ namespace verbly {
571 { 591 {
572 case filter<adjective>::type::singleton: 592 case filter<adjective>::type::singleton:
573 { 593 {
594 bindings.emplace_back(f.get_elem()._id);
595
574 if (notlogic == f.get_notlogic()) 596 if (notlogic == f.get_notlogic())
575 { 597 {
576 return "general_id = @GENID"; 598 return "general_id = ?";
577 } else { 599 } else {
578 return "general_id != @GENID"; 600 return "general_id != ?";
579 } 601 }
580 } 602 }
581 603
@@ -625,11 +647,13 @@ namespace verbly {
625 { 647 {
626 case filter<noun>::type::singleton: 648 case filter<noun>::type::singleton:
627 { 649 {
650 bindings.emplace_back(f.get_elem()._id);
651
628 if (notlogic == f.get_notlogic()) 652 if (notlogic == f.get_notlogic())
629 { 653 {
630 return "noun_id = @APERID"; 654 return "noun_id = ?";
631 } else { 655 } else {
632 return "noun_id != @APERID"; 656 return "noun_id != ?";
633 } 657 }
634 } 658 }
635 659
@@ -679,11 +703,13 @@ namespace verbly {
679 { 703 {
680 case filter<adverb>::type::singleton: 704 case filter<adverb>::type::singleton:
681 { 705 {
706 bindings.emplace_back(f.get_elem()._id);
707
682 if (notlogic == f.get_notlogic()) 708 if (notlogic == f.get_notlogic())
683 { 709 {
684 return "mannernym_id = @MANID"; 710 return "mannernym_id = ?";
685 } else { 711 } else {
686 return "mannernym_id != @MANID"; 712 return "mannernym_id != ?";
687 } 713 }
688 } 714 }
689 715
@@ -776,74 +802,29 @@ namespace verbly {
776 throw std::runtime_error(sqlite3_errmsg(_data.ppdb)); 802 throw std::runtime_error(sqlite3_errmsg(_data.ppdb));
777 } 803 }
778 804
779 if (!_rhymes.empty()) 805 int i = 1;
806 for (auto& binding : bindings)
780 { 807 {
781 int i = 0; 808 switch (binding.get_type())
782 for (auto rhyme : _rhymes)
783 { 809 {
784 std::string rhymer = "%" + rhyme; 810 case binding::type::integer:
785 sqlite3_bind_text(ppstmt, sqlite3_bind_parameter_index(ppstmt, "@RHMPRN"), rhymer.c_str(), rhymer.length(), SQLITE_STATIC); 811 {
812 sqlite3_bind_int(ppstmt, i, binding.get_integer());
813
814 break;
815 }
786 816
787 i++; 817 case binding::type::string:
818 {
819 sqlite3_bind_text(ppstmt, i, binding.get_string().c_str(), binding.get_string().length(), SQLITE_STATIC);
820
821 break;
822 }
788 } 823 }
824
825 i++;
789 } 826 }
790 827
791 for (auto except : _except)
792 {
793 sqlite3_bind_int(ppstmt, sqlite3_bind_parameter_index(ppstmt, "@EXCID"), except._id);
794 }
795
796 for (auto prefix : _with_prefix.inorder_flatten())
797 {
798 std::string pfat = prefix + "%";
799 sqlite3_bind_text(ppstmt, sqlite3_bind_parameter_index(ppstmt, "@PREFIX"), pfat.c_str(), pfat.length(), SQLITE_STATIC);
800 }
801
802 for (auto suffix : _with_suffix.inorder_flatten())
803 {
804 std::string pfat = "%" + suffix;
805 sqlite3_bind_text(ppstmt, sqlite3_bind_parameter_index(ppstmt, "@SUFFIX"), pfat.c_str(), pfat.length(), SQLITE_STATIC);
806 }
807
808 if (_with_complexity != unlimited)
809 {
810 sqlite3_bind_int(ppstmt, sqlite3_bind_parameter_index(ppstmt, "@COMPLEX"), _with_complexity);
811 }
812
813 for (auto attribute : _variant_of.inorder_flatten())
814 {
815 sqlite3_bind_int(ppstmt, sqlite3_bind_parameter_index(ppstmt, "@ATTRID"), attribute._id);
816 }
817
818 for (auto antonym : _antonym_of.inorder_flatten())
819 {
820 sqlite3_bind_int(ppstmt, sqlite3_bind_parameter_index(ppstmt, "@ANTID"), antonym._id);
821 }
822
823 for (auto synonym : _synonym_of.inorder_flatten())
824 {
825 sqlite3_bind_int(ppstmt, sqlite3_bind_parameter_index(ppstmt, "@SYNID"), synonym._id);
826 }
827
828 for (auto specific : _generalization_of.inorder_flatten())
829 {
830 sqlite3_bind_int(ppstmt, sqlite3_bind_parameter_index(ppstmt, "@SPECID"), specific._id);
831 }
832
833 for (auto general : _specification_of.inorder_flatten())
834 {
835 sqlite3_bind_int(ppstmt, sqlite3_bind_parameter_index(ppstmt, "@GENID"), general._id);
836 }
837
838 for (auto n : _pertainym_of.inorder_flatten())
839 {
840 sqlite3_bind_int(ppstmt, sqlite3_bind_parameter_index(ppstmt, "@APERID"), n._id);
841 }
842
843 for (auto mannernym : _anti_mannernym_of.inorder_flatten())
844 {
845 sqlite3_bind_int(ppstmt, sqlite3_bind_parameter_index(ppstmt, "@MANID"), mannernym._id);
846 }
847 /* 828 /*
848 for (auto adj : _derived_from_adjective) 829 for (auto adj : _derived_from_adjective)
849 { 830 {