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 --- adjective.h | 2 +- adverb.h | 21 ++++++++++++++++ data.h | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- token.h | 21 +++++----------- verbly.h | 1 + 5 files changed, 106 insertions(+), 18 deletions(-) create mode 100644 adverb.h diff --git a/adjective.h b/adjective.h index 58c490e..9d7883f 100644 --- a/adjective.h +++ b/adjective.h @@ -8,7 +8,7 @@ namespace verbly { int id; public: - std::string value; + std::string form; adjective(int id) : id(id) { diff --git a/adverb.h b/adverb.h new file mode 100644 index 0000000..6d2466e --- /dev/null +++ b/adverb.h @@ -0,0 +1,21 @@ +#ifndef ADVERB_H_86F8302F +#define ADVERB_H_86F8302F + +namespace verbly { + + class adverb { + private: + int id; + + public: + std::string form; + + adverb(int id) : id(id) + { + + } + }; + +}; + +#endif /* end of include guard: ADVERB_H_86F8302F */ 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); + } + }; }; diff --git a/token.h b/token.h index bbe7c2d..2848fd0 100644 --- a/token.h +++ b/token.h @@ -24,7 +24,8 @@ namespace verbly { enum class fillin_type { noun_phrase, participle_phrase, - adjective + adjective, + adverb }; class token { @@ -128,14 +129,14 @@ namespace verbly { return it != other.it; } - token* operator*() + token& operator*() { - return *it->get(); + return **it; } - token* operator->() + token& operator->() { - return *it->get(); + return **it; } };*/ @@ -189,16 +190,6 @@ namespace verbly { return std::end(utterance); } - const iterator begin() const - { - return std::begin(utterance); - } - - const iterator end() const - { - return std::end(utterance); - } - void erase(iterator it) { utterance.erase(it); diff --git a/verbly.h b/verbly.h index 139d8f8..44fd3a8 100644 --- a/verbly.h +++ b/verbly.h @@ -5,6 +5,7 @@ #include "token.h" #include "verb.h" #include "adjective.h" +#include "adverb.h" #include "data.h" #endif /* end of include guard: VERBLY_H_5B39CE50 */ -- cgit 1.4.1