From 040ee58fecdc9c478004bc2e554e1ae126ec4602 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Fri, 15 Apr 2016 17:24:44 -0400 Subject: 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. --- lib/frame_query.cpp | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'lib/frame_query.cpp') diff --git a/lib/frame_query.cpp b/lib/frame_query.cpp index 6583da4..3c4a3e8 100644 --- a/lib/frame_query.cpp +++ b/lib/frame_query.cpp @@ -37,13 +37,19 @@ namespace verbly { { std::stringstream construct; construct << "SELECT frames.data, groups.data FROM frames INNER JOIN groups ON frames.group_id = groups.group_id"; + std::list bindings; if (!_for_verb.empty()) { - std::list clauses(_for_verb.size(), "verb_id = @VERID"); + std::list clauses(_for_verb.size(), "verb_id = ?"); construct << " WHERE frames.group_id IN (SELECT group_id FROM verb_groups WHERE "; construct << verbly::implode(std::begin(clauses), std::end(clauses), " OR "); construct << ")"; + + for (auto v : _for_verb) + { + bindings.emplace_back(v._id); + } } sqlite3_stmt* ppstmt; @@ -53,9 +59,27 @@ namespace verbly { throw std::runtime_error(sqlite3_errmsg(_data.ppdb)); } - for (auto verb : _for_verb) + int i = 1; + for (auto& binding : bindings) { - sqlite3_bind_int(ppstmt, sqlite3_bind_parameter_index(ppstmt, "@VERID"), verb._id); + switch (binding.get_type()) + { + case binding::type::integer: + { + sqlite3_bind_int(ppstmt, i, binding.get_integer()); + + break; + } + + case binding::type::string: + { + sqlite3_bind_text(ppstmt, i, binding.get_string().c_str(), binding.get_string().length(), SQLITE_STATIC); + + break; + } + } + + i++; } std::list output; -- cgit 1.4.1