1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
#include "lemma.h"
#include <list>
#include <cassert>
#include "field.h"
#include "database.h"
#include "form.h"
namespace verbly {
namespace generator {
int lemma::nextId_ = 0;
lemma::lemma(const form& baseForm) :
id_(nextId_++),
baseForm_(baseForm)
{
inflections_[inflection::base] = {&baseForm};
}
void lemma::addInflection(inflection type, const form& f)
{
// There can only be one base form.
assert(type != inflection::base);
inflections_[type].insert(&f);
}
std::set<const form*> lemma::getInflections(inflection type) const
{
if (inflections_.count(type))
{
return inflections_.at(type);
} else {
return {};
}
}
database& operator<<(database& db, const lemma& arg)
{
for (inflection type : {
inflection::base,
inflection::plural,
inflection::comparative,
inflection::superlative,
inflection::past_tense,
inflection::past_participle,
inflection::ing_form,
inflection::s_form})
{
for (const form* f : arg.getInflections(type))
{
std::list<field> fields;
fields.emplace_back("lemma_id", arg.getId());
fields.emplace_back("form_id", f->getId());
fields.emplace_back("category", static_cast<int>(type));
db.insertIntoTable("lemmas_forms", std::move(fields));
}
}
return db;
}
};
};
|