diff options
Diffstat (limited to 'generator/group.cpp')
| -rw-r--r-- | generator/group.cpp | 59 |
1 files changed, 31 insertions, 28 deletions
| diff --git a/generator/group.cpp b/generator/group.cpp index 5b23578..1ffb9d9 100644 --- a/generator/group.cpp +++ b/generator/group.cpp | |||
| @@ -1,10 +1,8 @@ | |||
| 1 | #include "group.h" | 1 | #include "group.h" |
| 2 | #include <stdexcept> | 2 | #include <stdexcept> |
| 3 | #include <list> | 3 | #include <list> |
| 4 | #include "database.h" | 4 | #include <hkutil/string.h> |
| 5 | #include "field.h" | ||
| 6 | #include "frame.h" | 5 | #include "frame.h" |
| 7 | #include "../lib/util.h" | ||
| 8 | 6 | ||
| 9 | namespace verbly { | 7 | namespace verbly { |
| 10 | namespace generator { | 8 | namespace generator { |
| @@ -50,28 +48,26 @@ namespace verbly { | |||
| 50 | return roles_.at(name); | 48 | return roles_.at(name); |
| 51 | } | 49 | } |
| 52 | 50 | ||
| 53 | database& operator<<(database& db, const group& arg) | 51 | hatkirby::database& operator<<(hatkirby::database& db, const group& arg) |
| 54 | { | 52 | { |
| 55 | // Serialize each frame | 53 | // Serialize each frame |
| 56 | for (const frame& f : arg.getFrames()) | 54 | for (const frame& f : arg.getFrames()) |
| 57 | { | 55 | { |
| 58 | // First, serialize the group/frame relationship | 56 | // First, serialize the group/frame relationship |
| 59 | { | 57 | db.insertIntoTable( |
| 60 | std::list<field> fields; | 58 | "frames", |
| 61 | 59 | { | |
| 62 | fields.emplace_back("frame_id", f.getId()); | 60 | { "frame_id", f.getId() }, |
| 63 | fields.emplace_back("group_id", arg.getId()); | 61 | { "group_id", arg.getId() }, |
| 64 | fields.emplace_back("length", f.getLength()); | 62 | { "length", f.getLength() } |
| 65 | 63 | }); | |
| 66 | db.insertIntoTable("frames", std::move(fields)); | ||
| 67 | } | ||
| 68 | 64 | ||
| 69 | // Then, serialize the frame parts in the context of the group | 65 | // Then, serialize the frame parts in the context of the group |
| 70 | for (int partIndex = 0; partIndex < f.getLength(); partIndex++) | 66 | for (int partIndex = 0; partIndex < f.getLength(); partIndex++) |
| 71 | { | 67 | { |
| 72 | const part& p = f[partIndex]; | 68 | const part& p = f[partIndex]; |
| 73 | 69 | ||
| 74 | std::list<field> fields; | 70 | std::list<hatkirby::column> fields; |
| 75 | fields.emplace_back("part_id", p.getId()); | 71 | fields.emplace_back("part_id", p.getId()); |
| 76 | fields.emplace_back("frame_id", f.getId()); | 72 | fields.emplace_back("frame_id", f.getId()); |
| 77 | fields.emplace_back("part_index", partIndex); | 73 | fields.emplace_back("part_index", partIndex); |
| @@ -92,23 +88,23 @@ namespace verbly { | |||
| 92 | 88 | ||
| 93 | for (const std::string& s : partSelrestrs) | 89 | for (const std::string& s : partSelrestrs) |
| 94 | { | 90 | { |
| 95 | std::list<field> selrestrFields; | 91 | db.insertIntoTable( |
| 96 | 92 | "selrestrs", | |
| 97 | selrestrFields.emplace_back("part_id", p.getId()); | 93 | { |
| 98 | selrestrFields.emplace_back("selrestr", s); | 94 | { "part_id", p.getId() }, |
| 99 | 95 | { "selrestr", s } | |
| 100 | db.insertIntoTable("selrestrs", std::move(selrestrFields)); | 96 | }); |
| 101 | } | 97 | } |
| 102 | 98 | ||
| 103 | // Short interlude to serialize the synrestrs | 99 | // Short interlude to serialize the synrestrs |
| 104 | for (const std::string& s : p.getNounSynrestrs()) | 100 | for (const std::string& s : p.getNounSynrestrs()) |
| 105 | { | 101 | { |
| 106 | std::list<field> synrestrFields; | 102 | db.insertIntoTable( |
| 107 | 103 | "synrestrs", | |
| 108 | synrestrFields.emplace_back("part_id", p.getId()); | 104 | { |
| 109 | synrestrFields.emplace_back("synrestr", s); | 105 | { "part_id", p.getId() }, |
| 110 | 106 | { "synrestr", s } | |
| 111 | db.insertIntoTable("synrestrs", std::move(synrestrFields)); | 107 | }); |
| 112 | } | 108 | } |
| 113 | 109 | ||
| 114 | break; | 110 | break; |
| @@ -117,10 +113,17 @@ namespace verbly { | |||
| 117 | case part::type::preposition: | 113 | case part::type::preposition: |
| 118 | { | 114 | { |
| 119 | std::set<std::string> setChoices = p.getPrepositionChoices(); | 115 | std::set<std::string> setChoices = p.getPrepositionChoices(); |
| 120 | std::string serializedChoices = implode(std::begin(setChoices), std::end(setChoices), ","); | 116 | |
| 117 | std::string serializedChoices = | ||
| 118 | hatkirby::implode( | ||
| 119 | std::begin(setChoices), | ||
| 120 | std::end(setChoices), | ||
| 121 | ","); | ||
| 121 | 122 | ||
| 122 | fields.emplace_back("prepositions", std::move(serializedChoices)); | 123 | fields.emplace_back("prepositions", std::move(serializedChoices)); |
| 123 | fields.emplace_back("preposition_literality", p.isPrepositionLiteral() ? 1 : 0); | 124 | |
| 125 | fields.emplace_back("preposition_literality", | ||
| 126 | p.isPrepositionLiteral() ? 1 : 0); | ||
| 124 | 127 | ||
| 125 | break; | 128 | break; |
| 126 | } | 129 | } |
