summary refs log tree commit diff stats
path: root/generator/frame.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'generator/frame.cpp')
-rw-r--r--generator/frame.cpp69
1 files changed, 9 insertions, 60 deletions
diff --git a/generator/frame.cpp b/generator/frame.cpp index f75e3ba..4e4ac5f 100644 --- a/generator/frame.cpp +++ b/generator/frame.cpp
@@ -11,72 +11,21 @@ namespace verbly {
11 { 11 {
12 } 12 }
13 13
14 void frame::push_back(part fp) 14 frame frame::duplicate(const frame& other)
15 {
16 parts_.push_back(std::move(fp));
17 }
18
19 database& operator<<(database& db, const frame& arg)
20 { 15 {
21 std::list<field> fields; 16 frame result;
22 fields.emplace_back("frame_id", arg.getId());
23 17
24 nlohmann::json jsonParts; 18 for (const part& p : other.parts_)
25 for (const part& p : arg)
26 { 19 {
27 nlohmann::json jsonPart; 20 result.push_back(part::duplicate(p));
28 jsonPart["type"] = static_cast<int>(p.getType());
29
30 switch (p.getType())
31 {
32 case part::type::noun_phrase:
33 {
34 jsonPart["role"] = p.getNounRole();
35 jsonPart["selrestrs"] = p.getNounSelrestrs().toJson();
36 jsonPart["synrestrs"] = p.getNounSynrestrs();
37
38 break;
39 }
40
41 case part::type::preposition:
42 {
43 jsonPart["choices"] = p.getPrepositionChoices();
44 jsonPart["literal"] = p.isPrepositionLiteral();
45
46 break;
47 }
48
49 case part::type::literal:
50 {
51 jsonPart["value"] = p.getLiteralValue();
52
53 break;
54 }
55
56 case part::type::verb:
57 case part::type::adjective:
58 case part::type::adverb:
59 {
60 break;
61 }
62
63 case part::type::invalid:
64 {
65 // Invalid parts should not be serialized.
66 assert(false);
67
68 break;
69 }
70 }
71
72 jsonParts.push_back(std::move(jsonPart));
73 } 21 }
74 22
75 fields.emplace_back("data", jsonParts.dump()); 23 return result;
76 24 }
77 db.insertIntoTable("frames", std::move(fields));
78 25
79 return db; 26 void frame::push_back(part fp)
27 {
28 parts_.push_back(std::move(fp));
80 } 29 }
81 30
82 }; 31 };