diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2017-01-16 18:02:50 -0500 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2017-01-16 18:02:50 -0500 |
commit | 6746da6edd7d9d50efe374eabbb79a3cac882d81 (patch) | |
tree | ff20917e08b08d36b9541c1371106596e7bec442 /lib/preposition.cpp | |
parent | 4af7e55733098ca42f75a4ffaca1b0f6bab4dd36 (diff) | |
download | verbly-6746da6edd7d9d50efe374eabbb79a3cac882d81.tar.gz verbly-6746da6edd7d9d50efe374eabbb79a3cac882d81.tar.bz2 verbly-6746da6edd7d9d50efe374eabbb79a3cac882d81.zip |
Started structural rewrite
The new object structure was designed to build on the existing WordNet structure, while also adding in all of the data that we get from other sources. More information about this can be found on the project wiki. The generator has already been completely rewritten to generate a datafile that uses the new structure. In addition, a number of indexes are created, which does double the size of the datafile, but also allows for much faster lookups. Finally, the new generator is written modularly and is a lot more readable than the old one. The verbly interface to the new object structure has mostly been completed, but has not been tested fully. There is a completely new search API which utilizes a lot of operator overloading; documentation on how to use it should go up at some point. Token processing and verb frames are currently unimplemented. Source for these have been left in the repository for now.
Diffstat (limited to 'lib/preposition.cpp')
-rw-r--r-- | lib/preposition.cpp | 107 |
1 files changed, 0 insertions, 107 deletions
diff --git a/lib/preposition.cpp b/lib/preposition.cpp deleted file mode 100644 index cea9165..0000000 --- a/lib/preposition.cpp +++ /dev/null | |||
@@ -1,107 +0,0 @@ | |||
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 | std::list<binding> bindings; | ||
41 | |||
42 | if (!_in_group.empty()) | ||
43 | { | ||
44 | std::list<std::string> clauses(_in_group.size(), "groupname = ?"); | ||
45 | construct << " WHERE preposition_id IN (SELECT preposition_id FROM preposition_groups WHERE "; | ||
46 | construct << verbly::implode(std::begin(clauses), std::end(clauses), " OR "); | ||
47 | construct << ")"; | ||
48 | |||
49 | for (auto g : _in_group) | ||
50 | { | ||
51 | bindings.emplace_back(g); | ||
52 | } | ||
53 | } | ||
54 | |||
55 | if (_random) | ||
56 | { | ||
57 | construct << " ORDER BY RANDOM()"; | ||
58 | } | ||
59 | |||
60 | if (_limit != unlimited) | ||
61 | { | ||
62 | construct << " LIMIT " << _limit; | ||
63 | } | ||
64 | |||
65 | sqlite3_stmt* ppstmt; | ||
66 | std::string query = construct.str(); | ||
67 | if (sqlite3_prepare_v2(_data.ppdb, query.c_str(), query.length(), &ppstmt, NULL) != SQLITE_OK) | ||
68 | { | ||
69 | throw std::runtime_error(sqlite3_errmsg(_data.ppdb)); | ||
70 | } | ||
71 | |||
72 | int i = 1; | ||
73 | for (auto& binding : bindings) | ||
74 | { | ||
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_TRANSIENT); | ||
87 | |||
88 | break; | ||
89 | } | ||
90 | } | ||
91 | |||
92 | i++; | ||
93 | } | ||
94 | |||
95 | std::list<preposition> output; | ||
96 | while (sqlite3_step(ppstmt) == SQLITE_ROW) | ||
97 | { | ||
98 | preposition pp; | ||
99 | pp.form = std::string(reinterpret_cast<const char*>(sqlite3_column_text(ppstmt, 0))); | ||
100 | |||
101 | output.push_back(pp); | ||
102 | } | ||
103 | |||
104 | return output; | ||
105 | } | ||
106 | |||
107 | }; | ||