diff options
Diffstat (limited to 'lib/lemma.cpp')
| -rw-r--r-- | lib/lemma.cpp | 69 |
1 files changed, 69 insertions, 0 deletions
| diff --git a/lib/lemma.cpp b/lib/lemma.cpp new file mode 100644 index 0000000..f9e9fcc --- /dev/null +++ b/lib/lemma.cpp | |||
| @@ -0,0 +1,69 @@ | |||
| 1 | #include "lemma.h" | ||
| 2 | #include <sqlite3.h> | ||
| 3 | #include "database.h" | ||
| 4 | #include "query.h" | ||
| 5 | |||
| 6 | namespace verbly { | ||
| 7 | |||
| 8 | const object lemma::objectType = object::lemma; | ||
| 9 | |||
| 10 | const std::list<std::string> lemma::select = {"lemma_id"}; | ||
| 11 | |||
| 12 | const field lemma::id = field::integerField(object::lemma, "lemma_id"); | ||
| 13 | |||
| 14 | const field lemma::word = field::joinField(object::lemma, "lemma_id", object::word); | ||
| 15 | |||
| 16 | const field lemma::formJoin = field::joinField(object::lemma, "form_id", object::form); | ||
| 17 | const field lemma::inflectionCategory = field::integerField(object::lemma, "category"); | ||
| 18 | |||
| 19 | filter operator%=(lemma::inflection_field check, filter joinCondition) | ||
| 20 | { | ||
| 21 | return (lemma::formJoin %= joinCondition) && (lemma::inflectionCategory == check.getCategory()); | ||
| 22 | } | ||
| 23 | |||
| 24 | lemma::lemma(const database& db, sqlite3_stmt* row) : db_(&db), valid_(true) | ||
| 25 | { | ||
| 26 | id_ = sqlite3_column_int(row, 0); | ||
| 27 | } | ||
| 28 | |||
| 29 | const form& lemma::getBaseForm() const | ||
| 30 | { | ||
| 31 | if (!valid_) | ||
| 32 | { | ||
| 33 | throw std::domain_error("Bad access to uninitialized lemma"); | ||
| 34 | } | ||
| 35 | |||
| 36 | if (!forms_.count(inflection::base)) | ||
| 37 | { | ||
| 38 | initializeForm(inflection::base); | ||
| 39 | } | ||
| 40 | |||
| 41 | return forms_.at(inflection::base).front(); | ||
| 42 | } | ||
| 43 | |||
| 44 | bool lemma::hasInflection(inflection category) const | ||
| 45 | { | ||
| 46 | return !getInflections(category).empty(); | ||
| 47 | } | ||
| 48 | |||
| 49 | const std::vector<form>& lemma::getInflections(inflection category) const | ||
| 50 | { | ||
| 51 | if (!valid_) | ||
| 52 | { | ||
| 53 | throw std::domain_error("Bad access to uninitialized lemma"); | ||
| 54 | } | ||
| 55 | |||
| 56 | if (!forms_.count(category)) | ||
| 57 | { | ||
| 58 | initializeForm(category); | ||
| 59 | } | ||
| 60 | |||
| 61 | return forms_.at(category); | ||
| 62 | } | ||
| 63 | |||
| 64 | void lemma::initializeForm(inflection infl) const | ||
| 65 | { | ||
| 66 | forms_[infl] = db_->forms(form::lemma(infl) %= *this, false, -1).all(); | ||
| 67 | } | ||
| 68 | |||
| 69 | }; | ||
