From 0ba0fff06fb679f5cabedd52257fc0c38a600279 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Tue, 24 Jan 2017 21:46:18 -0500 Subject: Added word::getGroup --- lib/word.cpp | 24 ++++++++++++++++++++++-- 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 { return lemma_; } + const group& word::getGroup() const + { + if (!valid_) + { + throw std::domain_error("Bad access to uninitialized word"); + } + + if (!hasGroup_) + { + throw std::domain_error("Word does not have a group"); + } + + if (!group_) + { + group_ = db_->groups(group::id == groupId_).first(); + } + + return group_; + } + std::string word::getBaseForm() const { return getLemma().getBaseForm().getText(); } - std::list word::getInflections(inflection category) const + std::vector word::getInflections(inflection category) const { - std::list result; + std::vector result; for (const form& infl : getLemma().getInflections(category)) { 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 { const lemma& getLemma() const; + bool hasGroup() const + { + if (!valid_) + { + throw std::domain_error("Bad access to uninitialized word"); + } + + return hasGroup_; + } + + const group& getGroup() const; + // Convenience accessors std::string getBaseForm() const; - std::list getInflections(inflection infl) const; + std::vector getInflections(inflection infl) const; // Type info -- cgit 1.4.1