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