From eef5de613c75661e5d94baa086f6f2ddc26c7ed0 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Thu, 24 Mar 2016 23:16:07 -0400 Subject: Added verb frames In addition: - Added prepositions. - Rewrote a lot of the query interface. It now, for a lot of relationships, supports nested AND, OR, and NOT logic. - Rewrote the token class. It is now a union-like class instead of being polymorphic, which means smart pointers are no longer necessary. - Querying with regards to word derivation has been temporarily removed. - Sentinel values are now supported for all word types. - The VerbNet data retrieved from http://verbs.colorado.edu/~mpalmer/projects/verbnet/downloads.html was found to not be perfectly satisfactory in some regards, especially regarding adjective phrases. A patch file is now included in the repository describing the changes made to the VerbNet v3.2 download for the canonical verbly datafile. --- lib/token.h | 413 ++++++++++++++++++++---------------------------------------- 1 file changed, 134 insertions(+), 279 deletions(-) (limited to 'lib/token.h') diff --git a/lib/token.h b/lib/token.h index b22032b..788a106 100644 --- a/lib/token.h +++ b/lib/token.h @@ -1,314 +1,169 @@ #ifndef TOKEN_H_AD62C505 #define TOKEN_H_AD62C505 -#include -#include -#include -#include - namespace verbly { - class verb; - - class selrestr { - }; - - class synrestr { - }; - - enum class fillin_type { - noun_phrase, - participle_phrase, - adjective, - adverb - }; - class token { public: enum class type { verb, + noun, + adjective, + adverb, + preposition, fillin, - string, - utterance + utterance, + string }; - protected: - // General - type _type; - - token(type _type); - - public: - enum type token_type() const; - - virtual bool complete() const = 0; - virtual std::string compile() const = 0; - virtual token* copy() const = 0; - }; - - class verb_token : public token { - public: - enum class inflection { + enum class verb_inflection { infinitive, past_tense, past_participle, - ing_form, - s_form + s_form, + ing_form }; - private: - // Verb - const verb* _verb; - inflection _inflection = inflection::infinitive; - - public: - verb_token(const verb& _verb); - - const verb& get_verb() const; - - verb_token& inflect(inflection infl); - - bool complete() const; - - std::string compile() const; - - token* copy() const; - }; - - class utterance_token : public token { - private: - // Utterance - std::list> utterance; - - public: - typedef std::list>::iterator iterator; - /*class iterator { - private: - friend class utterance_token; - - std::list>::iterator it; - - public: - iterator(std::list>::iterator it) : it(it) - { - - } - - iterator& operator++() - { - ++it; - return *this; - } - - iterator& operator--() - { - --it; - return *this; - } - - bool operator==(const iterator& other) const - { - return it == other.it; - } - - bool operator!=(const iterator& other) const - { - return it != other.it; - } - - token& operator*() - { - return **it; - } - - token& operator->() - { - return **it; - } - };*/ - - utterance_token(std::initializer_list tkns) : token(token::type::utterance) - { - for (auto tkn : tkns) - { - utterance.push_back(std::unique_ptr(tkn)); - } - } - - utterance_token(const utterance_token& other) : token(token::type::utterance) - { - for (auto& tkn : other.utterance) - { - utterance.push_back(std::unique_ptr(tkn->copy())); - } - } + enum class noun_inflection { + singular, + plural + }; - utterance_token(utterance_token&& other) : token(token::type::utterance), utterance(std::move(other.utterance)) - { - - } + enum class adjective_inflection { + base, + comparative, + superlative + }; - utterance_token& operator=(const utterance_token& other) - { - utterance.clear(); - - for (auto& tkn : other.utterance) - { - utterance.push_back(std::unique_ptr(tkn->copy())); - } - - return *this; - } + enum class adverb_inflection { + base, + comparative, + superlative + }; - utterance_token& operator=(utterance_token&& other) - { - utterance = std::move(other.utterance); - - return *this; - } + enum class fillin_type { + generic, + noun_phrase, + adjective_phrase, + adverb_phrase, + participle_phrase, + infinitive_phrase + }; - iterator begin() - { - return std::begin(utterance); - } + type get_type() const; - iterator end() - { - return std::end(utterance); - } + int get_extra() const; + void set_extra(int _arg); - void erase(iterator it) - { - utterance.erase(it); - } + token(const token& other); + token& operator=(const token& other); + ~token(); - bool complete() const - { - return std::all_of(std::begin(utterance), std::end(utterance), [] (const std::unique_ptr& tkn) { - return tkn->complete(); - }); - } + bool is_complete() const; + std::string compile() const; - std::string compile() const - { - std::stringstream result; - for (auto& t : utterance) - { - if (t->complete()) - { - result << t->compile() << " "; - } else { - return "Could not compile!"; - } - } - - std::string output = result.str(); - if (output != "") - { - output.pop_back(); - } - - return output; - } + // Verb + token(verb _verb); + token(verb _verb, verb_inflection _infl); + token& operator=(verb _verb); + verb get_verb() const; + void set_verb(verb _verb); + verb_inflection get_verb_inflection() const; + void set_verb_inflection(verb_inflection _infl); + + // Noun + token(noun _noun); + token(noun _noun, noun_inflection _infl); + token& operator=(noun _noun); + noun get_noun() const; + void set_noun(noun _noun); + noun_inflection get_noun_inflection() const; + void set_noun_inflection(noun_inflection _infl); + + // Adjective + token(adjective _adjective); + token(adjective _adjective, adjective_inflection _infl); + token& operator=(adjective _adjective); + adjective get_adjective() const; + void set_adjective(adjective _adjective); + adjective_inflection get_adjective_inflection() const; + void set_adjective_inflection(adjective_inflection _infl); + + // Adverb + token(adverb _adverb); + token(adverb _adverb, adverb_inflection _infl); + token& operator=(adverb _adverb); + adverb get_adverb() const; + void set_adverb(adverb _adverb); + adverb_inflection get_adverb_inflection() const; + void set_adverb_inflection(adverb_inflection _infl); + + // Preposition + token(preposition _preposition); + token& operator=(preposition _preposition); + preposition get_preposition() const; + void set_preposition(preposition _preposition); - token* copy() const - { - return new utterance_token(*this); - } - }; - - class fillin_token : public token { - private: // Fillin - std::string m_theme; - fillin_type m_fillin_type; - - public: - fillin_token(fillin_type ft) : token(token::type::fillin), m_fillin_type(ft) - { - - } - -/* void synrestrs(std::initializer_list ins) - { - m_synrestrs = std::set(ins); - } - - std::set& synrestrs() - { - return m_synrestrs; - } - - void selrestrs(std::initializer_list ins) - { - m_selrestrs = std::set(ins); - } - - std::set& selrestrs() - { - return m_selrestrs; - }*/ - - fillin_token theme(std::string theme) - { - m_theme = theme; - - return *this; - } + token(fillin_type _ft); + token& operator=(fillin_type _ft); + fillin_type get_fillin_type() const; + void set_fillin_type(fillin_type _ft); - std::string& theme() - { - return m_theme; - } - - fillin_type get_fillin_type() const - { - return m_fillin_type; - } - - bool complete() const - { - return false; - } - - std::string compile() const - { - return ""; - } + // Utterance + typedef std::list::iterator iterator; + + token(); + token(std::initializer_list _init); + iterator begin(); + iterator end(); + token& operator<<(token _tkn); + void push_back(token _tkn); + void insert(iterator before, token _tkn); + void replace(iterator torepl, token _tkn); + void erase(iterator toer); - token* copy() const - { - return new fillin_token(*this); - } - }; - - class string_token : public token { - private: // String - std::string str; - - public: - string_token(std::string str) : token(token::type::string), str(str) - { - - } - - bool complete() const - { - return true; - } + token(std::string _str); + token& operator=(std::string _str); + std::string get_string() const; + void set_string(std::string _str); - std::string compile() const - { - return str; - } - - token* copy() const - { - return new string_token(*this); - } + private: + type _type; + int _extra = 0; + union { + struct { + verb _verb; + verb_inflection _infl; + } _verb; + struct { + noun _noun; + noun_inflection _infl; + } _noun; + struct { + adjective _adjective; + adjective_inflection _infl; + } _adjective; + struct { + adverb _adverb; + adverb_inflection _infl; + } _adverb; + struct { + preposition _preposition; + } _preposition; + struct { + fillin_type _type; + } _fillin; + struct { + std::string _str; + } _string; + struct { + std::list _utterance; + } _utterance; + }; }; - + }; #endif /* end of include guard: TOKEN_H_AD62C505 */ -- cgit 1.4.1