diff options
| author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2016-03-24 23:16:07 -0400 |
|---|---|---|
| committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2016-03-24 23:16:07 -0400 |
| commit | eef5de613c75661e5d94baa086f6f2ddc26c7ed0 (patch) | |
| tree | 180230f6a245c5bca94d894273f5d2b93ded3f04 /lib/preposition.cpp | |
| parent | d5ee4e39e5b5b3b8daa85cd972802195ad35e965 (diff) | |
| download | verbly-eef5de613c75661e5d94baa086f6f2ddc26c7ed0.tar.gz verbly-eef5de613c75661e5d94baa086f6f2ddc26c7ed0.tar.bz2 verbly-eef5de613c75661e5d94baa086f6f2ddc26c7ed0.zip | |
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.
Diffstat (limited to 'lib/preposition.cpp')
| -rw-r--r-- | lib/preposition.cpp | 83 |
1 files changed, 83 insertions, 0 deletions
| 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 @@ | |||
| 1 | #include "verbly.h" | ||
| 2 | |||
| 3 | namespace verbly { | ||
| 4 | |||
| 5 | std::string preposition::get_form() const | ||
| 6 | { | ||
| 7 | return form; | ||
| 8 | } | ||
| 9 | |||
| 10 | preposition_query::preposition_query(const data& _data) : _data(_data) | ||
| 11 | { | ||
| 12 | |||
| 13 | } | ||
| 14 | |||
| 15 | preposition_query& preposition_query::limit(int _limit) | ||
| 16 | { | ||
| 17 | this->_limit = _limit; | ||
| 18 | |||
| 19 | return *this; | ||
| 20 | } | ||
| 21 | |||
| 22 | preposition_query& preposition_query::random() | ||
| 23 | { | ||
| 24 | _random = true; | ||
| 25 | |||
| 26 | return *this; | ||
| 27 | } | ||
| 28 | |||
| 29 | preposition_query& preposition_query::in_group(std::string _arg) | ||
| 30 | { | ||
| 31 | _in_group.push_back(_arg); | ||
| 32 | |||
| 33 | return *this; | ||
| 34 | } | ||
| 35 | |||
| 36 | std::list<preposition> preposition_query::run() const | ||
| 37 | { | ||
| 38 | std::stringstream construct; | ||
| 39 | construct << "SELECT form FROM prepositions"; | ||
| 40 | |||
| 41 | if (!_in_group.empty()) | ||
| 42 | { | ||
| 43 | std::list<std::string> clauses(_in_group.size(), "groupname = @GNAME"); | ||
| 44 | 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 << ")"; | ||
| 47 | } | ||
| 48 | |||
| 49 | if (_random) | ||
| 50 | { | ||
| 51 | construct << " ORDER BY RANDOM()"; | ||
| 52 | } | ||
| 53 | |||
| 54 | if (_limit != unlimited) | ||
| 55 | { | ||
| 56 | construct << " LIMIT " << _limit; | ||
| 57 | } | ||
| 58 | |||
| 59 | sqlite3_stmt* ppstmt; | ||
| 60 | std::string query = construct.str(); | ||
| 61 | if (sqlite3_prepare_v2(_data.ppdb, query.c_str(), query.length(), &ppstmt, NULL) != SQLITE_OK) | ||
| 62 | { | ||
| 63 | throw std::runtime_error(sqlite3_errmsg(_data.ppdb)); | ||
| 64 | } | ||
| 65 | |||
| 66 | for (auto& group : _in_group) | ||
| 67 | { | ||
| 68 | sqlite3_bind_text(ppstmt, sqlite3_bind_parameter_index(ppstmt, "@GNAME"), group.c_str(), group.length(), SQLITE_STATIC); | ||
| 69 | } | ||
| 70 | |||
| 71 | std::list<preposition> output; | ||
| 72 | while (sqlite3_step(ppstmt) == SQLITE_ROW) | ||
| 73 | { | ||
| 74 | preposition pp; | ||
| 75 | pp.form = std::string(reinterpret_cast<const char*>(sqlite3_column_text(ppstmt, 0))); | ||
| 76 | |||
| 77 | output.push_back(pp); | ||
| 78 | } | ||
| 79 | |||
| 80 | return output; | ||
| 81 | } | ||
| 82 | |||
| 83 | }; | ||
