summary refs log tree commit diff stats
path: root/generator/lemma.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'generator/lemma.cpp')
-rw-r--r--generator/lemma.cpp65
1 files changed, 65 insertions, 0 deletions
diff --git a/generator/lemma.cpp b/generator/lemma.cpp new file mode 100644 index 0000000..e66b153 --- /dev/null +++ b/generator/lemma.cpp
@@ -0,0 +1,65 @@
1#include "lemma.h"
2#include <list>
3#include <cassert>
4#include "field.h"
5#include "database.h"
6#include "form.h"
7
8namespace verbly {
9 namespace generator {
10
11 int lemma::nextId_ = 0;
12
13 lemma::lemma(const form& baseForm) :
14 id_(nextId_++),
15 baseForm_(baseForm)
16 {
17 inflections_[inflection::base] = {&baseForm};
18 }
19
20 void lemma::addInflection(inflection type, const form& f)
21 {
22 // There can only be one base form.
23 assert(type != inflection::base);
24
25 inflections_[type].insert(&f);
26 }
27
28 std::set<const form*> lemma::getInflections(inflection type) const
29 {
30 if (inflections_.count(type))
31 {
32 return inflections_.at(type);
33 } else {
34 return {};
35 }
36 }
37
38 database& operator<<(database& db, const lemma& arg)
39 {
40 for (inflection type : {
41 inflection::base,
42 inflection::plural,
43 inflection::comparative,
44 inflection::superlative,
45 inflection::past_tense,
46 inflection::past_participle,
47 inflection::ing_form,
48 inflection::s_form})
49 {
50 for (const form* f : arg.getInflections(type))
51 {
52 std::list<field> fields;
53 fields.emplace_back("lemma_id", arg.getId());
54 fields.emplace_back("form_id", f->getId());
55 fields.emplace_back("category", static_cast<int>(type));
56
57 db.insertIntoTable("lemmas_forms", std::move(fields));
58 }
59 }
60
61 return db;
62 }
63
64 };
65};