summary refs log tree commit diff stats
path: root/lib/word.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/word.cpp')
-rw-r--r--lib/word.cpp85
1 files changed, 11 insertions, 74 deletions
diff --git a/lib/word.cpp b/lib/word.cpp index 6f0fe22..60657ba 100644 --- a/lib/word.cpp +++ b/lib/word.cpp
@@ -1,5 +1,4 @@
1#include "word.h" 1#include "word.h"
2#include <sqlite3.h>
3#include "form.h" 2#include "form.h"
4#include "util.h" 3#include "util.h"
5#include "database.h" 4#include "database.h"
@@ -45,89 +44,27 @@ namespace verbly {
45 return field::joinThroughWhere(object::word, "lemma_id", object::form, "lemmas_forms", "form_id", "category", static_cast<int>(category)); 44 return field::joinThroughWhere(object::word, "lemma_id", object::form, "lemmas_forms", "form_id", "category", static_cast<int>(category));
46 } 45 }
47 46
48 word::word(const database& db, sqlite3_stmt* row) : db_(&db), valid_(true) 47 word::word(const database& db, hatkirby::row row) : db_(db), valid_(true)
49 { 48 {
50 id_ = sqlite3_column_int(row, 0); 49 id_ = mpark::get<int>(row[0]);
51 notionId_ = sqlite3_column_int(row, 1);
52 lemmaId_ = sqlite3_column_int(row, 2);
53 50
54 if (sqlite3_column_type(row, 3) != SQLITE_NULL) 51 notion_ = db.notions(notion::id == mpark::get<int>(row[1])).first();
55 {
56 hasTagCount_ = true;
57 tagCount_ = sqlite3_column_int(row, 3);
58 }
59
60 if (sqlite3_column_type(row, 4) != SQLITE_NULL)
61 {
62 adjectivePosition_ = static_cast<positioning>(sqlite3_column_int(row, 4));
63 }
64
65 if (sqlite3_column_type(row, 5) != SQLITE_NULL)
66 {
67 hasGroup_ = true;
68 groupId_ = sqlite3_column_int(row, 5);
69 }
70 }
71
72 const notion& word::getNotion() const
73 {
74 if (!valid_)
75 {
76 throw std::domain_error("Bad access to uninitialized word");
77 }
78 52
79 if (!notion_.isValid()) 53 if (!mpark::holds_alternative<std::nullptr_t>(row[3]))
80 { 54 {
81 notion_ = db_->notions(notion::id == notionId_).first(); 55 hasTagCount_ = true;
82 } 56 tagCount_ = mpark::get<int>(row[3]);
83
84 return notion_;
85 }
86
87 bool word::hasFrames() const
88 {
89 if (!valid_)
90 {
91 throw std::domain_error("Bad access to uninitialized word");
92 }
93
94 if (!hasGroup_)
95 {
96 return false;
97 }
98
99 if (!initializedFrames_)
100 {
101 initializeFrames();
102 }
103
104 return !frames_.empty();
105 }
106
107 const std::vector<frame>& word::getFrames() const
108 {
109 if (!valid_)
110 {
111 throw std::domain_error("Bad access to uninitialized word");
112 } 57 }
113 58
114 if (!hasGroup_) 59 if (!mpark::holds_alternative<std::nullptr_t>(row[4]))
115 { 60 {
116 throw std::domain_error("Word does not have a group"); 61 adjectivePosition_ = static_cast<positioning>(mpark::get<int>(row[4]));
117 } 62 }
118 63
119 if (!initializedFrames_) 64 if (!mpark::holds_alternative<std::nullptr_t>(row[5]))
120 { 65 {
121 initializeFrames(); 66 frames_ = db.frames(*this).all();
122 } 67 }
123
124 return frames_;
125 }
126
127 void word::initializeFrames() const
128 {
129 initializedFrames_ = true;
130 frames_ = db_->frames(*this, {}, -1).all();
131 } 68 }
132 69
133 const form& word::getBaseForm() const 70 const form& word::getBaseForm() const
@@ -167,7 +104,7 @@ namespace verbly {
167 104
168 void word::initializeForm(inflection infl) const 105 void word::initializeForm(inflection infl) const
169 { 106 {
170 forms_[infl] = db_->forms(form::words(infl) %= *this, verbly::form::id, -1).all(); 107 forms_[infl] = db_.forms(form::words(infl) %= *this, verbly::form::id, -1).all();
171 } 108 }
172 109
173 filter word::synonyms_field::operator%=(filter joinCondition) const 110 filter word::synonyms_field::operator%=(filter joinCondition) const