summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2023-02-03 09:15:28 -0500
committerStar Rauchenberger <fefferburbia@gmail.com>2023-02-03 09:16:28 -0500
commit64f26d4a3b80969e08a607f80dde87d49ad5c2e3 (patch)
tree92ab69c6550d696ac6b15e1366b54222e773ada9 /lib
parentf2aacc40f4c26b3f4d71d81090f05261f4969e29 (diff)
downloadverbly-64f26d4a3b80969e08a607f80dde87d49ad5c2e3.tar.gz
verbly-64f26d4a3b80969e08a607f80dde87d49ad5c2e3.tar.bz2
verbly-64f26d4a3b80969e08a607f80dde87d49ad5c2e3.zip
Added word frequency information
Diffstat (limited to 'lib')
-rw-r--r--lib/form.cpp9
-rw-r--r--lib/form.h28
2 files changed, 36 insertions, 1 deletions
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 {
8 8
9 const object form::objectType = object::form; 9 const object form::objectType = object::form;
10 10
11 const std::list<std::string> form::select = {"form_id", "form", "complexity", "proper", "length"}; 11 const std::list<std::string> form::select = {"form_id", "form", "complexity", "proper", "length", "frequency"};
12 12
13 const field form::id = field::integerField(object::form, "form_id"); 13 const field form::id = field::integerField(object::form, "form_id");
14 const field form::text = field::stringField(object::form, "form"); 14 const field form::text = field::stringField(object::form, "form");
15 const field form::complexity = field::integerField(object::form, "complexity"); 15 const field form::complexity = field::integerField(object::form, "complexity");
16 const field form::proper = field::booleanField(object::form, "proper"); 16 const field form::proper = field::booleanField(object::form, "proper");
17 const field form::length = field::integerField(object::form, "length"); 17 const field form::length = field::integerField(object::form, "length");
18 const field form::frequency = field::integerField(object::form, "frequency");
18 19
19 const field form::pronunciations = field::joinThrough(object::form, "form_id", object::pronunciation, "forms_pronunciations", "pronunciation_id"); 20 const field form::pronunciations = field::joinThrough(object::form, "form_id", object::pronunciation, "forms_pronunciations", "pronunciation_id");
20 21
@@ -36,6 +37,12 @@ namespace verbly {
36 proper_ = (std::get<int>(row[3]) == 1); 37 proper_ = (std::get<int>(row[3]) == 1);
37 length_ = std::get<int>(row[4]); 38 length_ = std::get<int>(row[4]);
38 39
40 if (!mpark::holds_alternative<std::nullptr_t>(row[5]))
41 {
42 hasFreq_ = true;
43 frequency_ = mpark::get<int>(row[5]);
44 }
45
39 pronunciations_ = db.pronunciations(*this, pronunciation::id, -1).all(); 46 pronunciations_ = db.pronunciations(*this, pronunciation::id, -1).all();
40 } 47 }
41 48
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 {
82 return length_; 82 return length_;
83 } 83 }
84 84
85 bool hasFrequency() const
86 {
87 if (!valid_)
88 {
89 throw std::domain_error("Bad access to uninitialized form");
90 }
91
92 return hasFreq_;
93 }
94
95 bool getFrequency() const
96 {
97 if (!valid_)
98 {
99 throw std::domain_error("Bad access to uninitialized form");
100 }
101
102 if (!hasFreq_)
103 {
104 throw std::domain_error("Form does not have a frequency");
105 }
106
107 return frequency_;
108 }
109
85 const std::vector<pronunciation>& getPronunciations() const 110 const std::vector<pronunciation>& getPronunciations() const
86 { 111 {
87 if (!valid_) 112 if (!valid_)
@@ -109,6 +134,7 @@ namespace verbly {
109 static const field complexity; 134 static const field complexity;
110 static const field proper; 135 static const field proper;
111 static const field length; 136 static const field length;
137 static const field frequency;
112 138
113 operator filter() const 139 operator filter() const
114 { 140 {
@@ -149,6 +175,8 @@ namespace verbly {
149 int complexity_; 175 int complexity_;
150 bool proper_; 176 bool proper_;
151 int length_; 177 int length_;
178 bool hasFreq_ = false;
179 int frequency_;
152 std::vector<pronunciation> pronunciations_; 180 std::vector<pronunciation> pronunciations_;
153 }; 181 };
154 182