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