From 3aceae8ab1eb5992110ea57a9479bbc3177feb21 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Wed, 16 Mar 2016 11:27:16 -0400 Subject: Added more inflections, word relationships, and pronunciations Nouns, adjectives, and adverbs now have inflected forms. A large number of WordNet word relationships (all noun-noun relationships, plus synonymy and antonymy for all word types except verbs) have been added. Additionally, CMUDICT is now being used to store word pronunciations for rhyming purposes. Verbly is now also a compiled library rather than being header-only due to the complexity of the query interface. --- verbly/data.h | 275 +++++----------------------------------------------------- 1 file changed, 24 insertions(+), 251 deletions(-) (limited to 'verbly/data.h') diff --git a/verbly/data.h b/verbly/data.h index e901cba..37092d7 100644 --- a/verbly/data.h +++ b/verbly/data.h @@ -1,273 +1,46 @@ #ifndef DATA_H_C4AEC3DD #define DATA_H_C4AEC3DD -#include "verb.h" #include #include namespace verbly { + class data; + class word; + class adjective; + class noun; + class verb; + class adverb; + class adjective_query; + class adverb_query; + class noun_query; + class verb_query; + class data { private: sqlite3* ppdb; - public: - class verb_query { - public: - const static int unlimited = -1; - - private: - const data& database; - int m_limit = unlimited; - bool m_random = false; - - public: - verb_query(const data& database) : database(database) - { - - } - - verb_query& limit(int m_limit) - { - if ((m_limit > 0) || (m_limit == unlimited)) - { - this->m_limit = m_limit; - } - - return *this; - } - - verb_query& random(bool m_random) - { - this->m_random = m_random; - - return *this; - } - - std::list run() const - { - std::stringstream construct; - construct << "SELECT verb_id, infinitive, past_tense, past_participle, ing_form, s_form FROM verbs"; - - 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) - { - verb tnc {sqlite3_column_int(ppstmt, 0)}; - tnc.infinitive = std::string(reinterpret_cast(sqlite3_column_text(ppstmt, 1))); - tnc.past_tense = std::string(reinterpret_cast(sqlite3_column_text(ppstmt, 2))); - tnc.past_participle = std::string(reinterpret_cast(sqlite3_column_text(ppstmt, 3))); - tnc.ing_form = std::string(reinterpret_cast(sqlite3_column_text(ppstmt, 4))); - tnc.s_form = std::string(reinterpret_cast(sqlite3_column_text(ppstmt, 5))); - - output.push_back(tnc); - } - - sqlite3_finalize(ppstmt); - - return output; - } - - }; - - class adjective_query { - public: - const static int unlimited = -1; - - private: - const data& database; - int m_limit = unlimited; - bool m_random = false; - - public: - adjective_query(const data& database) : database(database) - { - - } - - adjective_query& limit(int m_limit) - { - if ((m_limit > 0) || (m_limit == unlimited)) - { - this->m_limit = m_limit; - } - - return *this; - } - - adjective_query& random(bool m_random) - { - this->m_random = m_random; - - return *this; - } - - std::list run() const - { - std::stringstream construct; - construct << "SELECT adjective_id, form FROM adjectives"; - - 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) - { - adjective tnc {sqlite3_column_int(ppstmt, 0)}; - 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); - } - - sqlite3_finalize(ppstmt); - - return output; - } - - }; + friend class adjective_query; + friend class noun_query; + friend class verb_query; + friend class adverb_query; - data(std::string datafile) - { - if (sqlite3_open_v2(datafile.c_str(), &ppdb, SQLITE_OPEN_READONLY, NULL) != SQLITE_OK) - { - throw std::invalid_argument(sqlite3_errmsg(ppdb)); - } - } + public: + data(std::string datafile); data(const data& other) = delete; data& operator=(const data& other) = delete; - data(data&& other) - { - ppdb = other.ppdb; - } - - data& operator=(data&& other) - { - ppdb = other.ppdb; - - return *this; - } - - ~data() - { - sqlite3_close_v2(ppdb); - } - - verb_query verbs() const - { - return verb_query(*this); - } + data(data&& other); + data& operator=(data&& other); - adjective_query adjectives() const - { - return adjective_query(*this); - } + ~data(); - adverb_query adverbs() const - { - return adverb_query(*this); - } + verb_query verbs() const; + adjective_query adjectives() const; + adverb_query adverbs() const; + noun_query nouns() const; }; -- cgit 1.4.1