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/pronunciation.h | 163 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100644 lib/pronunciation.h (limited to 'lib/pronunciation.h') diff --git a/lib/pronunciation.h b/lib/pronunciation.h new file mode 100644 index 0000000..c7a1d4d --- /dev/null +++ b/lib/pronunciation.h @@ -0,0 +1,163 @@ +#ifndef PRONUNCIATION_H_C68F86B0 +#define PRONUNCIATION_H_C68F86B0 + +#include +#include +#include +#include "field.h" +#include "filter.h" + +struct sqlite3_stmt; + +namespace verbly { + + class form; + class lemma; + class word; + class database; + + class pronunciation { + public: + + // Default constructor + + pronunciation() = default; + + // Construct from database + + pronunciation(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 pronunciation"); + } + + return id_; + } + + const std::vector& getPhonemes() const + { + if (!valid_) + { + throw std::domain_error("Bad access to uninitialized pronunciation"); + } + + return phonemes_; + } + + int getSyllables() const + { + if (!valid_) + { + throw std::domain_error("Bad access to uninitialized pronunciation"); + } + + return syllables_; + } + + std::string getStress() const + { + if (!valid_) + { + throw std::domain_error("Bad access to uninitialized pronunciation"); + } + + return stress_; + } + + bool hasRhyme() const + { + if (!valid_) + { + throw std::domain_error("Bad access to uninitialized pronunciation"); + } + + return hasRhyme_; + } + + std::string getPrerhyme() const + { + if (!valid_) + { + throw std::domain_error("Bad access to uninitialized pronunciation"); + } + + if (!hasRhyme_) + { + throw std::domain_error("This pronunciation has no rhyme"); + } + + return prerhyme_; + } + + std::string getRhyme() const + { + if (!valid_) + { + throw std::domain_error("Bad access to uninitialized pronunciation"); + } + + if (!hasRhyme_) + { + throw std::domain_error("This pronunciation has no rhyme"); + } + + return rhyme_; + } + + // Type info + + static const object objectType; + + static const std::list select; + + // Query fields + + static const field id; + static const field numOfSyllables; + static const field stress; + + operator filter() const + { + return (id == id_); + } + + static filter rhymesWith(const pronunciation& arg); + static filter rhymesWith(const class form& arg); + static filter rhymesWith(const lemma& arg); + static filter rhymesWith(const word& arg); + + // Relationships to other objects + + static const field form; + + private: + bool valid_ = false; + + int id_; + std::vector phonemes_; + int syllables_; + std::string stress_; + bool hasRhyme_ = false; + std::string prerhyme_; + std::string rhyme_; + + const database* db_; + + static const field prerhyme; + static const field rhyme; + + }; + +}; + +#endif /* end of include guard: PRONUNCIATION_H_C68F86B0 */ -- cgit 1.4.1