From 64f26d4a3b80969e08a607f80dde87d49ad5c2e3 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Fri, 3 Feb 2023 09:15:28 -0500 Subject: Added word frequency information --- lib/form.cpp | 9 ++++++++- lib/form.h | 28 ++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/form.cpp b/lib/form.cpp index 256dc59..fa72c8a 100644 --- a/lib/form.cpp +++ b/lib/form.cpp @@ -8,13 +8,14 @@ namespace verbly { const object form::objectType = object::form; - const std::list form::select = {"form_id", "form", "complexity", "proper", "length"}; + const std::list form::select = {"form_id", "form", "complexity", "proper", "length", "frequency"}; const field form::id = field::integerField(object::form, "form_id"); const field form::text = field::stringField(object::form, "form"); const field form::complexity = field::integerField(object::form, "complexity"); const field form::proper = field::booleanField(object::form, "proper"); const field form::length = field::integerField(object::form, "length"); + const field form::frequency = field::integerField(object::form, "frequency"); const field form::pronunciations = field::joinThrough(object::form, "form_id", object::pronunciation, "forms_pronunciations", "pronunciation_id"); @@ -36,6 +37,12 @@ namespace verbly { proper_ = (std::get(row[3]) == 1); length_ = std::get(row[4]); + if (!mpark::holds_alternative(row[5])) + { + hasFreq_ = true; + frequency_ = mpark::get(row[5]); + } + pronunciations_ = db.pronunciations(*this, pronunciation::id, -1).all(); } diff --git a/lib/form.h b/lib/form.h index 39f53aa..fb6b733 100644 --- a/lib/form.h +++ b/lib/form.h @@ -82,6 +82,31 @@ namespace verbly { return length_; } + bool hasFrequency() const + { + if (!valid_) + { + throw std::domain_error("Bad access to uninitialized form"); + } + + return hasFreq_; + } + + bool getFrequency() const + { + if (!valid_) + { + throw std::domain_error("Bad access to uninitialized form"); + } + + if (!hasFreq_) + { + throw std::domain_error("Form does not have a frequency"); + } + + return frequency_; + } + const std::vector& getPronunciations() const { if (!valid_) @@ -109,6 +134,7 @@ namespace verbly { static const field complexity; static const field proper; static const field length; + static const field frequency; operator filter() const { @@ -149,6 +175,8 @@ namespace verbly { int complexity_; bool proper_; int length_; + bool hasFreq_ = false; + int frequency_; std::vector pronunciations_; }; -- cgit 1.4.1