From 6746da6edd7d9d50efe374eabbb79a3cac882d81 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Mon, 16 Jan 2017 18:02:50 -0500 Subject: Started structural rewrite The new object structure was designed to build on the existing WordNet structure, while also adding in all of the data that we get from other sources. More information about this can be found on the project wiki. The generator has already been completely rewritten to generate a datafile that uses the new structure. In addition, a number of indexes are created, which does double the size of the datafile, but also allows for much faster lookups. Finally, the new generator is written modularly and is a lot more readable than the old one. The verbly interface to the new object structure has mostly been completed, but has not been tested fully. There is a completely new search API which utilizes a lot of operator overloading; documentation on how to use it should go up at some point. Token processing and verb frames are currently unimplemented. Source for these have been left in the repository for now. --- lib/word.h | 193 ++++++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 159 insertions(+), 34 deletions(-) (limited to 'lib/word.h') diff --git a/lib/word.h b/lib/word.h index 08797a3..f71dad9 100644 --- a/lib/word.h +++ b/lib/word.h @@ -1,48 +1,173 @@ -#ifndef WORD_H_8FC89498 -#define WORD_H_8FC89498 +#ifndef WORD_H_DF91B1B4 +#define WORD_H_DF91B1B4 + +#include +#include +#include "field.h" +#include "filter.h" +#include "notion.h" +#include "lemma.h" +#include "group.h" + +struct sqlite3_stmt; namespace verbly { - class rhyme { - public: - rhyme(std::string prerhyme, std::string phonemes); + class database; + + class word { + public: + + // Default constructor + + word() = default; + + // Construct from database + + word(const database& db, sqlite3_stmt* row); + + // Accessors + + operator bool() const + { + return valid_; + } + + int getId() const + { + if (!valid_) + { + throw std::domain_error("Bad access to uninitialized word"); + } - std::string get_prerhyme() const; - std::string get_rhyme() const; + return id_; + } + + bool hasTagCount() const + { + if (!valid_) + { + throw std::domain_error("Bad access to uninitialized word"); + } - bool operator==(const rhyme& other) const; + return hasTagCount_; + } + + int getTagCount() const + { + if (!valid_) + { + throw std::domain_error("Bad access to uninitialized word"); + } - private: - std::string _prerhyme; - std::string _rhyme; - }; - - class word { - protected: - const data* _data; - int _id; - bool _valid = false; + if (!hasTagCount_) + { + throw std::domain_error("Word has no tag count"); + } - std::list> pronunciations; - std::list rhymes; + return tagCount_; + } + + bool hasAdjectivePositioning() const + { + if (!valid_) + { + throw std::domain_error("Bad access to uninitialized word"); + } - word(); - word(const data& _data, int _id); + return (adjectivePosition_ != positioning::undefined); + } + + positioning getAdjectivePosition() const + { + if (!valid_) + { + throw std::domain_error("Bad access to uninitialized word"); + } - friend class adjective_query; - friend class verb_query; - friend class noun_query; - friend class adverb_query; - friend class frame_query; - friend class preposition_query; - - public: - virtual std::string base_form() const = 0; + if (adjectivePosition_ == positioning::undefined) + { + throw std::domain_error("Word has no adjective position"); + } - std::list get_rhymes() const; - bool starts_with_vowel_sound() const; + return adjectivePosition_; + } + + const notion& getNotion() const; + + const lemma& getLemma() const; + + // Convenience accessors + + std::string getBaseForm() const; + + std::list getInflections(inflection infl) const; + + // Type info + + static const object objectType; + + static const std::list select; + + // Query fields + + static const field id; + static const field tagCount; + static const field adjectivePosition; + + operator filter() const + { + return (id == id_); + } + + // Relationships with other objects + + static const field notion; + static const field lemma; + static const field group; + + // Relationships with self + + static const field antonyms; + + static const field specifications; + static const field generalizations; + + static const field pertainyms; + static const field antiPertainyms; + + static const field mannernyms; + static const field antiMannernyms; + + static const field usageTerms; + static const field usageDomains; + + static const field topicalTerms; + static const field topicalDomains; + + static const field regionalTerms; + static const field regionalDomains; + + private: + bool valid_ = false; + + int id_; + bool hasTagCount_ = false; + int tagCount_; + positioning adjectivePosition_ = positioning::undefined; + int notionId_; + int lemmaId_; + bool hasGroup_ = false; + int groupId_; + + const database* db_; + + mutable class notion notion_; + mutable class lemma lemma_; + mutable class group group_; + }; }; -#endif /* end of include guard: WORD_H_8FC89498 */ +#endif /* end of include guard: WORD_H_DF91B1B4 */ -- cgit 1.4.1