diff options
| -rw-r--r-- | lib/word.cpp | 24 | ||||
| -rw-r--r-- | lib/word.h | 14 |
2 files changed, 35 insertions, 3 deletions
| diff --git a/lib/word.cpp b/lib/word.cpp index 3edf2d2..d13d0bc 100644 --- a/lib/word.cpp +++ b/lib/word.cpp | |||
| @@ -93,14 +93,34 @@ namespace verbly { | |||
| 93 | return lemma_; | 93 | return lemma_; |
| 94 | } | 94 | } |
| 95 | 95 | ||
| 96 | const group& word::getGroup() const | ||
| 97 | { | ||
| 98 | if (!valid_) | ||
| 99 | { | ||
| 100 | throw std::domain_error("Bad access to uninitialized word"); | ||
| 101 | } | ||
| 102 | |||
| 103 | if (!hasGroup_) | ||
| 104 | { | ||
| 105 | throw std::domain_error("Word does not have a group"); | ||
| 106 | } | ||
| 107 | |||
| 108 | if (!group_) | ||
| 109 | { | ||
| 110 | group_ = db_->groups(group::id == groupId_).first(); | ||
| 111 | } | ||
| 112 | |||
| 113 | return group_; | ||
| 114 | } | ||
| 115 | |||
| 96 | std::string word::getBaseForm() const | 116 | std::string word::getBaseForm() const |
| 97 | { | 117 | { |
| 98 | return getLemma().getBaseForm().getText(); | 118 | return getLemma().getBaseForm().getText(); |
| 99 | } | 119 | } |
| 100 | 120 | ||
| 101 | std::list<std::string> word::getInflections(inflection category) const | 121 | std::vector<std::string> word::getInflections(inflection category) const |
| 102 | { | 122 | { |
| 103 | std::list<std::string> result; | 123 | std::vector<std::string> result; |
| 104 | for (const form& infl : getLemma().getInflections(category)) | 124 | for (const form& infl : getLemma().getInflections(category)) |
| 105 | { | 125 | { |
| 106 | result.push_back(infl.getText()); | 126 | result.push_back(infl.getText()); |
| diff --git a/lib/word.h b/lib/word.h index f71dad9..7b3c0f7 100644 --- a/lib/word.h +++ b/lib/word.h | |||
| @@ -97,11 +97,23 @@ namespace verbly { | |||
| 97 | 97 | ||
| 98 | const lemma& getLemma() const; | 98 | const lemma& getLemma() const; |
| 99 | 99 | ||
| 100 | bool hasGroup() const | ||
| 101 | { | ||
| 102 | if (!valid_) | ||
| 103 | { | ||
| 104 | throw std::domain_error("Bad access to uninitialized word"); | ||
| 105 | } | ||
| 106 | |||
| 107 | return hasGroup_; | ||
| 108 | } | ||
| 109 | |||
| 110 | const group& getGroup() const; | ||
| 111 | |||
| 100 | // Convenience accessors | 112 | // Convenience accessors |
| 101 | 113 | ||
| 102 | std::string getBaseForm() const; | 114 | std::string getBaseForm() const; |
| 103 | 115 | ||
| 104 | std::list<std::string> getInflections(inflection infl) const; | 116 | std::vector<std::string> getInflections(inflection infl) const; |
| 105 | 117 | ||
| 106 | // Type info | 118 | // Type info |
| 107 | 119 | ||
