diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2016-04-15 17:24:44 -0400 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2016-04-15 17:24:44 -0400 |
commit | 040ee58fecdc9c478004bc2e554e1ae126ec4602 (patch) | |
tree | 672a75690952ba8055ab9765ba0a475e056e35d4 /lib/preposition.cpp | |
parent | 3a225f5eb709262b9d44d49519136ea9a2a71000 (diff) | |
download | verbly-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/preposition.cpp')
-rw-r--r-- | lib/preposition.cpp | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/lib/preposition.cpp b/lib/preposition.cpp index c619bbf..8df13aa 100644 --- a/lib/preposition.cpp +++ b/lib/preposition.cpp | |||
@@ -37,13 +37,19 @@ namespace verbly { | |||
37 | { | 37 | { |
38 | std::stringstream construct; | 38 | std::stringstream construct; |
39 | construct << "SELECT form FROM prepositions"; | 39 | construct << "SELECT form FROM prepositions"; |
40 | std::list<binding> bindings; | ||
40 | 41 | ||
41 | if (!_in_group.empty()) | 42 | if (!_in_group.empty()) |
42 | { | 43 | { |
43 | std::list<std::string> clauses(_in_group.size(), "groupname = @GNAME"); | 44 | std::list<std::string> clauses(_in_group.size(), "groupname = ?"); |
44 | construct << " WHERE preposition_id IN (SELECT preposition_id FROM preposition_groups WHERE "; | 45 | construct << " WHERE preposition_id IN (SELECT preposition_id FROM preposition_groups WHERE "; |
45 | construct << verbly::implode(std::begin(clauses), std::end(clauses), " OR "); | 46 | construct << verbly::implode(std::begin(clauses), std::end(clauses), " OR "); |
46 | construct << ")"; | 47 | construct << ")"; |
48 | |||
49 | for (auto g : _in_group) | ||
50 | { | ||
51 | bindings.emplace_back(g); | ||
52 | } | ||
47 | } | 53 | } |
48 | 54 | ||
49 | if (_random) | 55 | if (_random) |
@@ -63,9 +69,27 @@ namespace verbly { | |||
63 | throw std::runtime_error(sqlite3_errmsg(_data.ppdb)); | 69 | throw std::runtime_error(sqlite3_errmsg(_data.ppdb)); |
64 | } | 70 | } |
65 | 71 | ||
66 | for (auto& group : _in_group) | 72 | int i = 1; |
73 | for (auto& binding : bindings) | ||
67 | { | 74 | { |
68 | sqlite3_bind_text(ppstmt, sqlite3_bind_parameter_index(ppstmt, "@GNAME"), group.c_str(), group.length(), SQLITE_STATIC); | 75 | switch (binding.get_type()) |
76 | { | ||
77 | case binding::type::integer: | ||
78 | { | ||
79 | sqlite3_bind_int(ppstmt, i, binding.get_integer()); | ||
80 | |||
81 | break; | ||
82 | } | ||
83 | |||
84 | case binding::type::string: | ||
85 | { | ||
86 | sqlite3_bind_text(ppstmt, i, binding.get_string().c_str(), binding.get_string().length(), SQLITE_STATIC); | ||
87 | |||
88 | break; | ||
89 | } | ||
90 | } | ||
91 | |||
92 | i++; | ||
69 | } | 93 | } |
70 | 94 | ||
71 | std::list<preposition> output; | 95 | std::list<preposition> output; |