diff options
Diffstat (limited to 'lib/word.cpp')
-rw-r--r-- | lib/word.cpp | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/lib/word.cpp b/lib/word.cpp index a928659..90eab1d 100644 --- a/lib/word.cpp +++ b/lib/word.cpp | |||
@@ -17,7 +17,7 @@ namespace verbly { | |||
17 | 17 | ||
18 | const field word::notion = field::joinField(object::word, "notion_id", object::notion); | 18 | const field word::notion = field::joinField(object::word, "notion_id", object::notion); |
19 | const field word::lemma = field::joinField(object::word, "lemma_id", object::lemma); | 19 | const field word::lemma = field::joinField(object::word, "lemma_id", object::lemma); |
20 | const field word::group = field::joinField(object::word, "group_id", object::group, true); | 20 | const field word::frame = field::joinField(object::word, "group_id", object::frame, true); |
21 | 21 | ||
22 | const field word::antonyms = field::selfJoin(object::word, "word_id", "antonymy", "antonym_2_id", "antonym_1_id"); | 22 | const field word::antonyms = field::selfJoin(object::word, "word_id", "antonymy", "antonym_2_id", "antonym_1_id"); |
23 | 23 | ||
@@ -93,7 +93,27 @@ namespace verbly { | |||
93 | return lemma_; | 93 | return lemma_; |
94 | } | 94 | } |
95 | 95 | ||
96 | const group& word::getGroup() const | 96 | bool word::hasFrames() const |
97 | { | ||
98 | if (!valid_) | ||
99 | { | ||
100 | throw std::domain_error("Bad access to uninitialized word"); | ||
101 | } | ||
102 | |||
103 | if (!hasGroup_) | ||
104 | { | ||
105 | return false; | ||
106 | } | ||
107 | |||
108 | if (!initializedFrames_) | ||
109 | { | ||
110 | initializeFrames(); | ||
111 | } | ||
112 | |||
113 | return !frames_.empty(); | ||
114 | } | ||
115 | |||
116 | const std::vector<frame>& word::getFrames() const | ||
97 | { | 117 | { |
98 | if (!valid_) | 118 | if (!valid_) |
99 | { | 119 | { |
@@ -105,12 +125,12 @@ namespace verbly { | |||
105 | throw std::domain_error("Word does not have a group"); | 125 | throw std::domain_error("Word does not have a group"); |
106 | } | 126 | } |
107 | 127 | ||
108 | if (!group_) | 128 | if (!initializedFrames_) |
109 | { | 129 | { |
110 | group_ = db_->groups(group::id == groupId_).first(); | 130 | initializeFrames(); |
111 | } | 131 | } |
112 | 132 | ||
113 | return group_; | 133 | return frames_; |
114 | } | 134 | } |
115 | 135 | ||
116 | std::string word::getBaseForm() const | 136 | std::string word::getBaseForm() const |
@@ -129,4 +149,10 @@ namespace verbly { | |||
129 | return result; | 149 | return result; |
130 | } | 150 | } |
131 | 151 | ||
152 | void word::initializeFrames() const | ||
153 | { | ||
154 | initializedFrames_ = true; | ||
155 | frames_ = db_->frames(*this, {}, -1).all(); | ||
156 | } | ||
157 | |||
132 | }; | 158 | }; |