From e5f284e6cf676fb0e712f568e560b5b8661506f4 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Thu, 10 Mar 2016 21:34:55 -0500 Subject: 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 --- data.h | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 77 insertions(+), 2 deletions(-) (limited to 'data.h') diff --git a/data.h b/data.h index 2c23c15..e901cba 100644 --- a/data.h +++ b/data.h @@ -121,7 +121,7 @@ namespace verbly { std::list run() const { std::stringstream construct; - construct << "SELECT adjective_id, adjective FROM adjectives"; + construct << "SELECT adjective_id, form FROM adjectives"; if (m_random) { @@ -144,7 +144,77 @@ namespace verbly { while (sqlite3_step(ppstmt) == SQLITE_ROW) { adjective tnc {sqlite3_column_int(ppstmt, 0)}; - tnc.value = std::string(reinterpret_cast(sqlite3_column_text(ppstmt, 1))); + tnc.form = std::string(reinterpret_cast(sqlite3_column_text(ppstmt, 1))); + + output.push_back(tnc); + } + + sqlite3_finalize(ppstmt); + + return output; + } + + }; + + class adverb_query { + public: + const static int unlimited = -1; + + private: + const data& database; + int m_limit = unlimited; + bool m_random = false; + + public: + adverb_query(const data& database) : database(database) + { + + } + + adverb_query& limit(int m_limit) + { + if ((m_limit > 0) || (m_limit == unlimited)) + { + this->m_limit = m_limit; + } + + return *this; + } + + adverb_query& random(bool m_random) + { + this->m_random = m_random; + + return *this; + } + + std::list run() const + { + std::stringstream construct; + construct << "SELECT adverb_id, form FROM adverbs"; + + if (m_random) + { + construct << " ORDER BY RANDOM()"; + } + + if (m_limit != unlimited) + { + construct << " LIMIT " << m_limit; + } + + sqlite3_stmt* ppstmt; + std::string query = construct.str(); + if (sqlite3_prepare_v2(database.ppdb, query.c_str(), query.length(), &ppstmt, NULL) != SQLITE_OK) + { + throw std::runtime_error(sqlite3_errmsg(database.ppdb)); + } + + std::list output; + while (sqlite3_step(ppstmt) == SQLITE_ROW) + { + adverb tnc {sqlite3_column_int(ppstmt, 0)}; + tnc.form = std::string(reinterpret_cast(sqlite3_column_text(ppstmt, 1))); output.push_back(tnc); } @@ -194,6 +264,11 @@ namespace verbly { return adjective_query(*this); } + adverb_query adverbs() const + { + return adverb_query(*this); + } + }; }; -- cgit 1.4.1