diff options
| author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2018-03-31 23:05:02 -0400 |
|---|---|---|
| committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2018-03-31 23:05:02 -0400 |
| commit | 75e947fa0021547f460496d1c3aef5b61af4c669 (patch) | |
| tree | 64559a5329b3e5983ffdfe7ee2ad65c7c938e98d /generator/form.cpp | |
| parent | 3554df2e34e63364eea3a7998e0dfb0e6be65ca4 (diff) | |
| download | verbly-75e947fa0021547f460496d1c3aef5b61af4c669.tar.gz verbly-75e947fa0021547f460496d1c3aef5b61af4c669.tar.bz2 verbly-75e947fa0021547f460496d1c3aef5b61af4c669.zip | |
Migrated generator to hkutil
Diffstat (limited to 'generator/form.cpp')
| -rw-r--r-- | generator/form.cpp | 35 |
1 files changed, 18 insertions, 17 deletions
| diff --git a/generator/form.cpp b/generator/form.cpp index f616344..c66820c 100644 --- a/generator/form.cpp +++ b/generator/form.cpp | |||
| @@ -1,8 +1,7 @@ | |||
| 1 | #include "form.h" | 1 | #include "form.h" |
| 2 | #include <algorithm> | 2 | #include <algorithm> |
| 3 | #include <list> | 3 | #include <list> |
| 4 | #include "database.h" | 4 | #include <cctype> |
| 5 | #include "field.h" | ||
| 6 | #include "pronunciation.h" | 5 | #include "pronunciation.h" |
| 7 | 6 | ||
| 8 | namespace verbly { | 7 | namespace verbly { |
| @@ -14,7 +13,7 @@ namespace verbly { | |||
| 14 | id_(nextId_++), | 13 | id_(nextId_++), |
| 15 | text_(text), | 14 | text_(text), |
| 16 | complexity_(std::count(std::begin(text), std::end(text), ' ') + 1), | 15 | complexity_(std::count(std::begin(text), std::end(text), ' ') + 1), |
| 17 | proper_(std::any_of(std::begin(text), std::end(text), std::isupper)), | 16 | proper_(std::any_of(std::begin(text), std::end(text), ::isupper)), |
| 18 | length_(text.length()) | 17 | length_(text.length()) |
| 19 | { | 18 | { |
| 20 | } | 19 | } |
| @@ -24,28 +23,30 @@ namespace verbly { | |||
| 24 | pronunciations_.insert(&p); | 23 | pronunciations_.insert(&p); |
| 25 | } | 24 | } |
| 26 | 25 | ||
| 27 | database& operator<<(database& db, const form& arg) | 26 | hatkirby::database& operator<<(hatkirby::database& db, const form& arg) |
| 28 | { | 27 | { |
| 29 | // Serialize the form first. | 28 | // Serialize the form first. |
| 30 | { | 29 | { |
| 31 | std::list<field> fields; | 30 | db.insertIntoTable( |
| 32 | fields.emplace_back("form_id", arg.getId()); | 31 | "forms", |
| 33 | fields.emplace_back("form", arg.getText()); | 32 | { |
| 34 | fields.emplace_back("complexity", arg.getComplexity()); | 33 | { "form_id", arg.getId() }, |
| 35 | fields.emplace_back("proper", arg.isProper()); | 34 | { "form", arg.getText() }, |
| 36 | fields.emplace_back("length", arg.getLength()); | 35 | { "complexity", arg.getComplexity() }, |
| 37 | 36 | { "proper", arg.isProper() }, | |
| 38 | db.insertIntoTable("forms", std::move(fields)); | 37 | { "length", arg.getLength() } |
| 38 | }); | ||
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | // Then, serialize the form/pronunciation relationship. | 41 | // Then, serialize the form/pronunciation relationship. |
| 42 | for (const pronunciation* p : arg.getPronunciations()) | 42 | for (const pronunciation* p : arg.getPronunciations()) |
| 43 | { | 43 | { |
| 44 | std::list<field> fields; | 44 | db.insertIntoTable( |
| 45 | fields.emplace_back("form_id", arg.getId()); | 45 | "forms_pronunciations", |
| 46 | fields.emplace_back("pronunciation_id", p->getId()); | 46 | { |
| 47 | 47 | { "form_id", arg.getId() }, | |
| 48 | db.insertIntoTable("forms_pronunciations", std::move(fields)); | 48 | { "pronunciation_id", p->getId() } |
| 49 | }); | ||
| 49 | } | 50 | } |
| 50 | 51 | ||
| 51 | return db; | 52 | return db; |
