From e1be2716746e75cf6ed37e86461a7f580a964564 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 --- .gitignore | 11 +- CMakeLists.txt | 8 +- furries.cpp | 15 +- generator.cpp | 451 +++++++++++++++++++++++++++++++++++++++++++++++++++++ schema.sql | 121 +++++++++++++- verbly/adjective.h | 2 +- verbly/adverb.h | 21 +++ verbly/data.h | 79 +++++++++- verbly/token.h | 21 +-- verbly/verbly.h | 1 + 10 files changed, 707 insertions(+), 23 deletions(-) create mode 100644 generator.cpp create mode 100644 verbly/adverb.h diff --git a/.gitignore b/.gitignore index e9abc7f..461a080 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,10 @@ -config.yml \ No newline at end of file +config.yml +.DS_Store +CMakeCache.txt +CMakeFiles/ +Makefile +cmake_install.cmake +furries +furries.dSYM/ +generator +generator.dSYM/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 054c972..0b6d991 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,9 +6,15 @@ add_subdirectory(vendor/twitcurl/libtwitcurl) find_package(PkgConfig) pkg_check_modules(YamlCpp yaml-cpp REQUIRED) pkg_check_modules(sqlite3 sqlite3 REQUIRED) +find_package(libxml2 REQUIRED) -include_directories(vendor/twitcurl/libtwitcurl ${sqlite3_INCLUDE_DIR}) +include_directories(vendor/twitcurl/libtwitcurl ${LIBXML2_INCLUDE_DIR} ${sqlite3_INCLUDE_DIR}) add_executable(furries furries.cpp) set_property(TARGET furries PROPERTY CXX_STANDARD 11) set_property(TARGET furries PROPERTY CXX_STANDARD_REQUIRED ON) target_link_libraries(furries ${sqlite3_LIBRARIES} ${YamlCpp_LIBRARIES} twitcurl curl) + +add_executable(generator generator.cpp) +set_property(TARGET generator PROPERTY CXX_STANDARD 11) +set_property(TARGET generator PROPERTY CXX_STANDARD_REQUIRED ON) +target_link_libraries(generator ${sqlite3_LIBRARIES} ${LIBXML2_LIBRARIES}) diff --git a/furries.cpp b/furries.cpp index 2d0fb23..0cce8bd 100644 --- a/furries.cpp +++ b/furries.cpp @@ -62,7 +62,15 @@ class fill_blanks { case verbly::fillin_type::adjective: { const verbly::adjective& adj = database.adjectives().random(true).limit(1).run().front(); - it = std::make_unique(adj.value); + it = std::make_unique(adj.form); + + break; + } + + case verbly::fillin_type::adverb: + { + const verbly::adverb& adv = database.adverbs().random(true).limit(1).run().front(); + it = std::make_unique(adv.form); break; } @@ -110,6 +118,11 @@ int main(int argc, char** argv) new verbly::string_token("the furries are"), new verbly::fillin_token(verbly::fillin_type::adjective) }); + forms.push_back({ + new verbly::string_token("the furries are"), + new verbly::fillin_token(verbly::fillin_type::adverb), + new verbly::fillin_token(verbly::fillin_type::adjective) + }); verbly::data database {"data.sqlite3"}; fill_blanks yeah {database}; diff --git a/generator.cpp b/generator.cpp new file mode 100644 index 0000000..c389963 --- /dev/null +++ b/generator.cpp @@ -0,0 +1,451 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct verb { + std::string infinitive; + std::string past_tense; + std::string past_participle; + std::string ing_form; + std::string s_form; +}; + +struct group { + std::string id; + std::set members; +}; + +std::map groups; +std::map verbs; +std::map> wn; + +void print_usage() +{ + std::cout << "Verbly Datafile Generator" << std::endl; + std::cout << "-------------------------" << std::endl; + std::cout << "Requires exactly four arguments." << std::endl; + std::cout << "1. The path to a VerbNet data directory." << std::endl; + std::cout << "2. The path to a SemLink vnpbMappings file." << std::endl; + std::cout << "3. The path to an AGID infl.txt file." << std::endl; + std::cout << "4. The path to a WordNet prolog data directory." << std::endl; + std::cout << "5. Datafile output path." << std::endl; + + exit(1); +} +/* +void parse_group(xmlNodePtr top, std::string filename) +{ + xmlChar* key = xmlGetProp(top, (xmlChar*) "ID"); + if (key == 0) + { + std::cout << "Bad VerbNet file format: " << filename << std::endl; + print_usage(); + } + std::string vnid = key; + vnid = vnid.substr(vnid.find_first_of("-")+1); + xmlFree(key); + + group g; + g.id = vnid; + + for (xmlNodePtr node = top->xmlChildrenNode; node != nullptr; node = node->next) + { + if (!xmlStrcmp(node->name, (const xmlChar*) "MEMBERS")) + { + for (xmlNodePtr member = node->xmlChildrenNode; member != nullptr; member = member->next) + { + if (!xmlStrcmp(member->name, (const xmlChar*) "MEMBER")) + { + key = xmlGetProp(member, (xmlChar*) "name"); + g.members.insert(key); + xmlFree(key); + } + } + } else if (!xmlStrcmp(node->name, (const xmlChar*) "FRAMES")) + { + for (xmlNodePtr frame = node->xmlChildrenNode; frame != nullptr; frame = frame->next) + { + if (!xmlStrcmp(frame->name, (const xmlChar*) "FRAME")) + { + for (xmlNodePtr framenode = frame->xmlChildrenNode; framenode != nullptr; framenode = framenode->next) + { + + } + } + } + } + } +}*/ + +int main(int argc, char** argv) +{ + if (argc != 6) + { + print_usage(); + } + + /*DIR* dir; + if ((dir = opendir(argv[1])) == nullptr) + { + std::cout << "Invalid VerbNet data directory." << std::endl; + + print_usage(); + } + + struct dirent* ent; + while ((ent = readdir(dir)) != nullptr) + { + std::string filename(argv[1]); + if (filename.back() != '/') + { + filename += '/'; + } + + filename += ent->d_name; + //std::cout << ent->d_name << std::endl; + + if (filename.rfind(".xml") != filename.size() - 4) + { + continue; + } + + xmlDocPtr doc = xmlParseFile(filename.c_str()); + if (doc == nullptr) + { + std::cout << "Error opening " << filename << std::endl; + print_usage(); + } + + xmlNodePtr top = xmlDocGetRootElement(doc); + if ((top == nullptr) || (xmlStrcmp(top->name, (xmlChar*) "VNCLASS"))) + { + std::cout << "Bad VerbNet file format: " << filename << std::endl; + print_usage(); + } + + parse_group(top, filename); + } + + closedir(dir);*/ + + // Get verbs from AGID + std::cout << "Reading verb inflection..." << std::endl; + + std::ifstream agidfile(argv[3]); + if (!agidfile.is_open()) + { + std::cout << "Could not open AGID file: " << argv[3] << std::endl; + print_usage(); + } + + for (;;) + { + std::string line; + if (!getline(agidfile, line)) + { + break; + } + + if (line.back() == '\r') + { + line.pop_back(); + } + + int divider = line.find_first_of(" "); + std::string word = line.substr(0, divider); + line = line.substr(divider+1); + + if (line[0] != 'V') + { + continue; + } + + if (line[1] == '?') + { + line.erase(0, 4); + } else { + line.erase(0, 3); + } + + std::vector forms; + while (!line.empty()) + { + std::string inflection; + if ((divider = line.find(" | ")) != std::string::npos) + { + inflection = line.substr(0, divider); + line = line.substr(divider + 3); + } else { + inflection = line; + line = ""; + } + + if ((divider = inflection.find_first_of(",?")) != std::string::npos) + { + inflection = inflection.substr(0, divider); + } + + forms.push_back(inflection); + } + + verb v; + v.infinitive = word; + if (forms.size() == 4) + { + v.past_tense = forms[0]; + v.past_participle = forms[1]; + v.ing_form = forms[2]; + v.s_form = forms[3]; + } else if (forms.size() == 3) + { + v.past_tense = forms[0]; + v.past_participle = forms[0]; + v.ing_form = forms[1]; + v.s_form = forms[2]; + } else if (forms.size() == 8) + { + // As of AGID 2014.08.11, this is only "to be" + v.past_tense = forms[0]; + v.past_participle = forms[2]; + v.ing_form = forms[3]; + v.s_form = forms[4]; + } else { + // Words that don't fit the cases above as of AGID 2014.08.11: + // - may and shall do not conjugate the way we want them to + // - methinks only has a past tense and is an outlier + // - wit has five forms, and is archaic/obscure enough that we can ignore it for now + std::cout << "Ignoring verb \"" << word << "\" due to non-standard number of forms." << std::endl; + } + + verbs[word] = v; + } + + // Start writing output + std::cout << "Writing output..." << std::endl; + + sqlite3* ppdb; + if (sqlite3_open_v2(argv[5], &ppdb, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL) != SQLITE_OK) + { + std::cout << "Error opening output datafile: " << sqlite3_errmsg(ppdb) << std::endl; + print_usage(); + } + + std::ifstream schemafile("schema.sql"); + if (!schemafile.is_open()) + { + std::cout << "Could not find schema file" << std::endl; + print_usage(); + } + + std::stringstream schemabuilder; + for (;;) + { + std::string line; + if (!getline(schemafile, line)) + { + break; + } + + if (line.back() == '\r') + { + line.pop_back(); + } + + schemabuilder << line << std::endl; + } + + std::string schema = schemabuilder.str(); + while (!schema.empty()) + { + std::string query; + int divider = schema.find(";"); + if (divider != std::string::npos) + { + query = schema.substr(0, divider+1); + schema = schema.substr(divider+2); + } else { + break; + } + + sqlite3_stmt* schmstmt; + if (sqlite3_prepare_v2(ppdb, query.c_str(), query.length(), &schmstmt, NULL) != SQLITE_OK) + { + std::cout << "Error writing to output database: " << sqlite3_errmsg(ppdb) << std::endl; + sqlite3_close_v2(ppdb); + print_usage(); + } + + if (sqlite3_step(schmstmt) != SQLITE_DONE) + { + std::cout << "Error writing to output database: " << sqlite3_errmsg(ppdb) << std::endl; + sqlite3_close_v2(ppdb); + print_usage(); + } + + sqlite3_finalize(schmstmt); + } + + std::cout << "Writing verbs..." << std::endl; + for (auto& mapping : verbs) + { + sqlite3_stmt* ppstmt; + std::string query("INSERT INTO verbs (infinitive, past_tense, past_participle, ing_form, s_form) VALUES (?, ?, ?, ?, ?)"); + if (sqlite3_prepare_v2(ppdb, query.c_str(), query.length(), &ppstmt, NULL) != SQLITE_OK) + { + std::cout << "Error writing to output database: " << sqlite3_errmsg(ppdb) << std::endl; + sqlite3_close_v2(ppdb); + print_usage(); + } + + sqlite3_bind_text(ppstmt, 1, mapping.second.infinitive.c_str(), mapping.second.infinitive.length(), SQLITE_STATIC); + sqlite3_bind_text(ppstmt, 2, mapping.second.past_tense.c_str(), mapping.second.past_tense.length(), SQLITE_STATIC); + sqlite3_bind_text(ppstmt, 3, mapping.second.past_participle.c_str(), mapping.second.past_participle.length(), SQLITE_STATIC); + sqlite3_bind_text(ppstmt, 4, mapping.second.ing_form.c_str(), mapping.second.ing_form.length(), SQLITE_STATIC); + sqlite3_bind_text(ppstmt, 5, mapping.second.s_form.c_str(), mapping.second.s_form.length(), SQLITE_STATIC); + + if (sqlite3_step(ppstmt) != SQLITE_DONE) + { + std::cout << "Error writing to output database: " << sqlite3_errmsg(ppdb) << std::endl; + sqlite3_close_v2(ppdb); + print_usage(); + } + + sqlite3_finalize(ppstmt); + } + + // Get nouns/adjectives/adverbs from WordNet + // Useful relations: + // - s: master list + // - ant: antonymy (e.g. happy/sad, sad/happy, happiness/sadness) + // - at: variation (e.g. a measurement can be standard or nonstandard) + // - hyp: hypernymy/hyponymy (e.g. color/red, color/blue) + // - ins: instantiation (do we need this? let's see) + // - mm: member meronymy/holonymy (e.g. family/mother, family/child) + // - mp: part meronymy/holonymy (e.g. wheel/spoke, wheel/tire) + // - ms: substance meronymy/holonymy (e.g. tire/rubber, doorstop/rubber) + // - per: pertainymy (e.g. something that is Alaskan pertains to Alaska) + // mannernymy (e.g. something done quickly is done in a manner that is quick) + // - sa: specification (e.g. inaccurate (general) can mean imprecise or incorrect (specific)) + // - sim: synonymy (e.g. cheerful/happy, happy/cheerful) + // - syntax: positioning flags for some adjectives + std::string wnpref {argv[4]}; + if (wnpref.back() != '/') + { + wnpref += '/'; + } + + std::cout << "Reading words from WordNet..." << std::endl; + std::ifstream wnsfile(wnpref + "wn_s.pl"); + if (!wnsfile.is_open()) + { + std::cout << "Invalid WordNet data directory." << std::endl; + print_usage(); + } + + for (;;) + { + std::string line; + if (!getline(wnsfile, line)) + { + break; + } + + if (line.back() == '\r') + { + line.pop_back(); + } + + std::regex relation("^s\\(([134]\\d{8}),(\\d+),'([\\w ]+)',"); + std::smatch relation_data; + if (!std::regex_search(line, relation_data, relation)) + { + continue; + } + + int synset_id = stoi(relation_data[1]); + int wnum = stoi(relation_data[2]); + std::string word = relation_data[3]; + + std::string query; + switch (synset_id / 100000000) + { + case 1: // Noun + { + query = "INSERT INTO nouns (form) VALUES (?)"; + + break; + } + + case 2: // Verb + { + // Ignore + + break; + } + + case 3: // Adjective + { + query = "INSERT INTO adjectives (form) VALUES (?)"; + + break; + } + + case 4: // Adverb + { + query = "INSERT INTO adverbs (form) VALUES (?)"; + + break; + } + } + + sqlite3_stmt* ppstmt; + if (sqlite3_prepare_v2(ppdb, query.c_str(), query.length(), &ppstmt, NULL) != SQLITE_OK) + { + std::cout << "Error writing to output database: " << sqlite3_errmsg(ppdb) << std::endl; + sqlite3_close_v2(ppdb); + print_usage(); + } + + sqlite3_bind_text(ppstmt, 1, word.c_str(), word.length(), SQLITE_STATIC); + + if (sqlite3_step(ppstmt) != SQLITE_DONE) + { + std::cout << "Error writing to output database: " << sqlite3_errmsg(ppdb) << std::endl; + sqlite3_close_v2(ppdb); + print_usage(); + } + + sqlite3_finalize(ppstmt); + + query = "SELECT last_insert_rowid()"; + if (sqlite3_prepare_v2(ppdb, query.c_str(), query.length(), &ppstmt, NULL) != SQLITE_OK) + { + std::cout << "Error writing to output database: " << sqlite3_errmsg(ppdb) << std::endl; + sqlite3_close_v2(ppdb); + print_usage(); + } + + if (sqlite3_step(ppstmt) != SQLITE_ROW) + { + std::cout << "Error writing to output database: " << sqlite3_errmsg(ppdb) << std::endl; + sqlite3_close_v2(ppdb); + print_usage(); + } + + wn[synset_id][wnum] = sqlite3_column_int(ppstmt, 0); + + sqlite3_finalize(ppstmt); + } + + sqlite3_close_v2(ppdb); + + std::cout << "Done." << std::endl; +} \ No newline at end of file diff --git a/schema.sql b/schema.sql index 7c1b52c..62dd780 100644 --- a/schema.sql +++ b/schema.sql @@ -34,5 +34,122 @@ CREATE TABLE `verb_groups` ( DROP TABLE IF EXISTS `adjectives`; CREATE TABLE `adjectives` ( `adjective_id` INTEGER PRIMARY KEY, - `adjective` VARCHAR(32) NOT NULL -); \ No newline at end of file + `form` VARCHAR(32) NOT NULL, + `position` CHAR(1) +); + +DROP TABLE IF EXISTS `adverbs`; +CREATE TABLE `adverbs` ( + `adverb_id` INTEGER PRIMARY KEY, + `form` VARCHAR(32) NOT NULL +); + +DROP TABLE IF EXISTS `nouns`; +CREATE TABLE `nouns` ( + `noun_id` INTEGER PRIMARY KEY, + `form` VARCHAR(32) NOT NULL +); + +DROP TABLE IF EXISTS `hypernymy`; +CREATE TABLE `hypernymy` ( + `hypernym_id` INTEGER NOT NULL, + `hyponym_id` INTEGER NOT NULL, + FOREIGN KEY (`hypernym_id`) REFERENCES `nouns`(`noun_id`), + FOREIGN KEY (`hyponym_id`) REFERENCES `nouns`(`noun_id`) +); + +DROP TABLE IF EXISTS `instantiation`; +CREATE TABLE `instantiation` ( + `class_id` INTEGER NOT NULL, + `instance_id` INTEGER NOT NULL, + FOREIGN KEY (`class_id`) REFERENCES `nouns`(`noun_id`), + FOREIGN KEY (`instance_id`) REFERENCES `nouns`(`noun_id`) +); + +DROP TABLE IF EXISTS `member_meronymy`; +CREATE TABLE `member_meronymy` ( + `meronym_id` INTEGER NOT NULL, + `holonym_id` INTEGER NOT NULL, + FOREIGN KEY (`meronym_id`) REFERENCES `nouns`(`noun_id`), + FOREIGN KEY (`holonym_id`) REFERENCES `nouns`(`noun_id`) +); + +DROP TABLE IF EXISTS `part_meronymy`; +CREATE TABLE `part_meronymy` ( + `meronym_id` INTEGER NOT NULL, + `holonym_id` INTEGER NOT NULL, + FOREIGN KEY (`meronym_id`) REFERENCES `nouns`(`noun_id`), + FOREIGN KEY (`holonym_id`) REFERENCES `nouns`(`noun_id`) +); + +DROP TABLE IF EXISTS `substance_meronymy`; +CREATE TABLE `substance_meronymy` ( + `meronym_id` INTEGER NOT NULL, + `holonym_id` INTEGER NOT NULL, + FOREIGN KEY (`meronym_id`) REFERENCES `nouns`(`noun_id`), + FOREIGN KEY (`holonym_id`) REFERENCES `nouns`(`noun_id`) +); + +DROP TABLE IF EXISTS `variation`; +CREATE TABLE `variation` ( + `noun_id` INTEGER NOT NULL, + `adjective_id` INTEGER NOT NULL, + FOREIGN KEY (`noun_id`) REFERENCES `nouns`(`noun_id`), + FOREIGN KEY (`adjective_id`) REFERENCES `adjectives`(`adjective_id`) +); + +DROP TABLE IF EXISTS `noun_antonymy`; +CREATE TABLE `noun_antonymy` ( + `noun_1_id` INTEGER NOT NULL, + `noun_2_id` INTEGER NOT NULL, + FOREIGN KEY (`noun_1_id`) REFERENCES `nouns`(`noun_id`), + FOREIGN KEY (`noun_2_id`) REFERENCES `nouns`(`noun_id`) +); + +DROP TABLE IF EXISTS `adjective_antonymy`; +CREATE TABLE `adjective_antonymy` ( + `adjective_1_id` INTEGER NOT NULL, + `adjective_2_id` INTEGER NOT NULL, + FOREIGN KEY (`adjective_1_id`) REFERENCES `adjectives`(`adjective_id`), + FOREIGN KEY (`adjective_2_id`) REFERENCES `adjectives`(`adjective_id`) +); + +DROP TABLE IF EXISTS `adverb_antonymy`; +CREATE TABLE `adverb_antonymy` ( + `adverb_1_id` INTEGER NOT NULL, + `adverb_2_id` INTEGER NOT NULL, + FOREIGN KEY (`adverb_1_id`) REFERENCES `adverbs`(`adverb_id`), + FOREIGN KEY (`adverb_2_id`) REFERENCES `adverbs`(`adverb_id`) +); + +DROP TABLE IF EXISTS `specification`; +CREATE TABLE `specification` ( + `general_id` INTEGER NOT NULL, + `specific_id` INTEGER NOT NULL, + FOREIGN KEY (`general_id`) REFERENCES `adjectives`(`adjective_id`), + FOREIGN KEY (`specific_id`) REFERENCES `adjectives`(`adjective_id`) +); + +DROP TABLE IF EXISTS `pertainymy`; +CREATE TABLE `pertainymy` ( + `noun_id` INTEGER NOT NULL, + `pertainym_id` INTEGER NOT NULL, + FOREIGN KEY (`noun_id`) REFERENCES `nouns`(`noun_id`), + FOREIGN KEY (`pertainym_id`) REFERENCES `adjectives`(`adjective_id`) +); + +DROP TABLE IF EXISTS `mannernymy`; +CREATE TABLE `mannernymy` ( + `adjective_id` INTEGER NOT NULL, + `mannernym_id` INTEGER NOT NULL, + FOREIGN KEY (`adjective_id`) REFERENCES `adjectives`(`adjective_id`), + FOREIGN KEY (`mannernym_id`) REFERENCES `adverbs`(`adverb_id`) +); + +DROP TABLE IF EXISTS `synonymy`; +CREATE TABLE `synonymy` ( + `adjective_1_id` INTEGER NOT NULL, + `adjective_2_id` INTEGER NOT NULL, + FOREIGN KEY (`adjective_1_id`) REFERENCES `adjectives`(`adjective_id`), + FOREIGN KEY (`adjective_2_id`) REFERENCES `adjectives`(`adjective_id`) +); diff --git a/verbly/adjective.h b/verbly/adjective.h index 58c490e..9d7883f 100644 --- a/verbly/adjective.h +++ b/verbly/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/verbly/adverb.h b/verbly/adverb.h new file mode 100644 index 0000000..6d2466e --- /dev/null +++ b/verbly/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/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 { 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/verbly/token.h b/verbly/token.h index bbe7c2d..2848fd0 100644 --- a/verbly/token.h +++ b/verbly/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/verbly.h b/verbly/verbly.h index 139d8f8..44fd3a8 100644 --- a/verbly/verbly.h +++ b/verbly/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