From eef5de613c75661e5d94baa086f6f2ddc26c7ed0 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Thu, 24 Mar 2016 23:16:07 -0400 Subject: Added verb frames In addition: - Added prepositions. - Rewrote a lot of the query interface. It now, for a lot of relationships, supports nested AND, OR, and NOT logic. - Rewrote the token class. It is now a union-like class instead of being polymorphic, which means smart pointers are no longer necessary. - Querying with regards to word derivation has been temporarily removed. - Sentinel values are now supported for all word types. - The VerbNet data retrieved from http://verbs.colorado.edu/~mpalmer/projects/verbnet/downloads.html was found to not be perfectly satisfactory in some regards, especially regarding adjective phrases. A patch file is now included in the repository describing the changes made to the VerbNet v3.2 download for the canonical verbly datafile. --- lib/preposition.cpp | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 lib/preposition.cpp (limited to 'lib/preposition.cpp') diff --git a/lib/preposition.cpp b/lib/preposition.cpp new file mode 100644 index 0000000..c619bbf --- /dev/null +++ b/lib/preposition.cpp @@ -0,0 +1,83 @@ +#include "verbly.h" + +namespace verbly { + + std::string preposition::get_form() const + { + return form; + } + + preposition_query::preposition_query(const data& _data) : _data(_data) + { + + } + + preposition_query& preposition_query::limit(int _limit) + { + this->_limit = _limit; + + return *this; + } + + preposition_query& preposition_query::random() + { + _random = true; + + return *this; + } + + preposition_query& preposition_query::in_group(std::string _arg) + { + _in_group.push_back(_arg); + + return *this; + } + + std::list preposition_query::run() const + { + std::stringstream construct; + construct << "SELECT form FROM prepositions"; + + if (!_in_group.empty()) + { + std::list clauses(_in_group.size(), "groupname = @GNAME"); + construct << " WHERE preposition_id IN (SELECT preposition_id FROM preposition_groups WHERE "; + construct << verbly::implode(std::begin(clauses), std::end(clauses), " OR "); + construct << ")"; + } + + if (_random) + { + construct << " ORDER BY RANDOM()"; + } + + if (_limit != unlimited) + { + construct << " LIMIT " << _limit; + } + + sqlite3_stmt* ppstmt; + std::string query = construct.str(); + if (sqlite3_prepare_v2(_data.ppdb, query.c_str(), query.length(), &ppstmt, NULL) != SQLITE_OK) + { + throw std::runtime_error(sqlite3_errmsg(_data.ppdb)); + } + + for (auto& group : _in_group) + { + sqlite3_bind_text(ppstmt, sqlite3_bind_parameter_index(ppstmt, "@GNAME"), group.c_str(), group.length(), SQLITE_STATIC); + } + + std::list output; + while (sqlite3_step(ppstmt) == SQLITE_ROW) + { + preposition pp; + pp.form = std::string(reinterpret_cast(sqlite3_column_text(ppstmt, 0))); + + output.push_back(pp); + } + + return output; + } + +}; -- cgit 1.4.1