diff options
| author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2016-03-10 21:34:55 -0500 |
|---|---|---|
| committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2016-03-10 21:34:55 -0500 |
| commit | e1be2716746e75cf6ed37e86461a7f580a964564 (patch) | |
| tree | 38a69a8cbd690f27f1ee8c2ce43eeb0333753d52 /verbly/data.h | |
| parent | 41decb9a671e4d0fbbe12533372435ec6ede2246 (diff) | |
| download | furries-e1be2716746e75cf6ed37e86461a7f580a964564.tar.gz furries-e1be2716746e75cf6ed37e86461a7f580a964564.tar.bz2 furries-e1be2716746e75cf6ed37e86461a7f580a964564.zip | |
Started implementing verbly data generator
Currently, the generator: - Uses AGID to create entries for verb words and their inflections - Uses WordNet to create entries for adjective, adverb, and noun senses
Diffstat (limited to 'verbly/data.h')
| -rw-r--r-- | verbly/data.h | 79 |
1 files changed, 77 insertions, 2 deletions
| diff --git a/verbly/data.h b/verbly/data.h index 2c23c15..e901cba 100644 --- a/verbly/data.h +++ b/verbly/data.h | |||
| @@ -121,7 +121,7 @@ namespace verbly { | |||
| 121 | std::list<adjective> run() const | 121 | std::list<adjective> run() const |
| 122 | { | 122 | { |
| 123 | std::stringstream construct; | 123 | std::stringstream construct; |
| 124 | construct << "SELECT adjective_id, adjective FROM adjectives"; | 124 | construct << "SELECT adjective_id, form FROM adjectives"; |
| 125 | 125 | ||
| 126 | if (m_random) | 126 | if (m_random) |
| 127 | { | 127 | { |
| @@ -144,7 +144,77 @@ namespace verbly { | |||
| 144 | while (sqlite3_step(ppstmt) == SQLITE_ROW) | 144 | while (sqlite3_step(ppstmt) == SQLITE_ROW) |
| 145 | { | 145 | { |
| 146 | adjective tnc {sqlite3_column_int(ppstmt, 0)}; | 146 | adjective tnc {sqlite3_column_int(ppstmt, 0)}; |
| 147 | tnc.value = std::string(reinterpret_cast<const char*>(sqlite3_column_text(ppstmt, 1))); | 147 | tnc.form = std::string(reinterpret_cast<const char*>(sqlite3_column_text(ppstmt, 1))); |
| 148 | |||
| 149 | output.push_back(tnc); | ||
| 150 | } | ||
| 151 | |||
| 152 | sqlite3_finalize(ppstmt); | ||
| 153 | |||
| 154 | return output; | ||
| 155 | } | ||
| 156 | |||
| 157 | }; | ||
| 158 | |||
| 159 | class adverb_query { | ||
| 160 | public: | ||
| 161 | const static int unlimited = -1; | ||
| 162 | |||
| 163 | private: | ||
| 164 | const data& database; | ||
| 165 | int m_limit = unlimited; | ||
| 166 | bool m_random = false; | ||
| 167 | |||
| 168 | public: | ||
| 169 | adverb_query(const data& database) : database(database) | ||
| 170 | { | ||
| 171 | |||
| 172 | } | ||
| 173 | |||
| 174 | adverb_query& limit(int m_limit) | ||
| 175 | { | ||
| 176 | if ((m_limit > 0) || (m_limit == unlimited)) | ||
| 177 | { | ||
| 178 | this->m_limit = m_limit; | ||
| 179 | } | ||
| 180 | |||
| 181 | return *this; | ||
| 182 | } | ||
| 183 | |||
| 184 | adverb_query& random(bool m_random) | ||
| 185 | { | ||
| 186 | this->m_random = m_random; | ||
| 187 | |||
| 188 | return *this; | ||
| 189 | } | ||
| 190 | |||
| 191 | std::list<adverb> run() const | ||
| 192 | { | ||
| 193 | std::stringstream construct; | ||
| 194 | construct << "SELECT adverb_id, form FROM adverbs"; | ||
| 195 | |||
| 196 | if (m_random) | ||
| 197 | { | ||
| 198 | construct << " ORDER BY RANDOM()"; | ||
| 199 | } | ||
| 200 | |||
| 201 | if (m_limit != unlimited) | ||
| 202 | { | ||
| 203 | construct << " LIMIT " << m_limit; | ||
| 204 | } | ||
| 205 | |||
| 206 | sqlite3_stmt* ppstmt; | ||
| 207 | std::string query = construct.str(); | ||
| 208 | if (sqlite3_prepare_v2(database.ppdb, query.c_str(), query.length(), &ppstmt, NULL) != SQLITE_OK) | ||
| 209 | { | ||
| 210 | throw std::runtime_error(sqlite3_errmsg(database.ppdb)); | ||
| 211 | } | ||
| 212 | |||
| 213 | std::list<adverb> output; | ||
| 214 | while (sqlite3_step(ppstmt) == SQLITE_ROW) | ||
| 215 | { | ||
| 216 | adverb tnc {sqlite3_column_int(ppstmt, 0)}; | ||
| 217 | tnc.form = std::string(reinterpret_cast<const char*>(sqlite3_column_text(ppstmt, 1))); | ||
| 148 | 218 | ||
| 149 | output.push_back(tnc); | 219 | output.push_back(tnc); |
| 150 | } | 220 | } |
| @@ -194,6 +264,11 @@ namespace verbly { | |||
| 194 | return adjective_query(*this); | 264 | return adjective_query(*this); |
| 195 | } | 265 | } |
| 196 | 266 | ||
| 267 | adverb_query adverbs() const | ||
| 268 | { | ||
| 269 | return adverb_query(*this); | ||
| 270 | } | ||
| 271 | |||
| 197 | }; | 272 | }; |
| 198 | 273 | ||
| 199 | }; | 274 | }; |
