-
Notifications
You must be signed in to change notification settings - Fork 0
/
serialize.cpp
212 lines (173 loc) · 7.17 KB
/
serialize.cpp
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#include "json.hpp"
#include "words.hpp"
#include <stdexcept>
using nlohmann::json;
json WordForm::to_json() const {
json ret;
switch (part_of_speech) {
case PART_OF_SPEECH_NOUN: ret["part_of_speech"] = "noun"; break;
case PART_OF_SPEECH_VERB: ret["part_of_speech"] = "verb"; break;
case PART_OF_SPEECH_PARTICIPLE: ret["part_of_speech"] = "participle"; break;
case PART_OF_SPEECH_SUPINE: ret["part_of_speech"] = "supine"; break;
case PART_OF_SPEECH_ADJECTIVE: ret["part_of_speech"] = "adjective"; break;
case PART_OF_SPEECH_ADVERB: ret["part_of_speech"] = "adverb"; break;
case PART_OF_SPEECH_PRONOUN: ret["part_of_speech"] = "pronoun"; break;
case PART_OF_SPEECH_CONJUNCTION: ret["part_of_speech"] = "conjunction"; break;
case PART_OF_SPEECH_PREPOSITION: ret["part_of_speech"] = "preposition"; break;
case PART_OF_SPEECH_INTERJECTION: ret["part_of_speech"] = "interjection"; break;
case PART_OF_SPEECH_NUMERAL: ret["part_of_speech"] = "numeral"; break;
}
return ret;
}
json Noun::to_json() const {
json ret = WordForm::to_json();
switch (casus) {
case CASUS_NOMINATIVE: ret["casus"] = "nominative"; break;
case CASUS_GENITIVE: ret["casus"] = "genitive"; break;
case CASUS_DATIVE: ret["casus"] = "dative"; break;
case CASUS_ACCUSATIVE: ret["casus"] = "accusative"; break;
case CASUS_ABLATIVE: ret["casus"] = "ablative"; break;
case CASUS_VOCATIVE: ret["casus"] = "vocative"; break;
case CASUS_LOCATIVE: ret["casus"] = "locative"; break;
default: throw std::logic_error("Invalid case");
}
ret["plural"] = plural;
switch (gender) {
case GENDER_MASCULINE: ret["gender"] = "masculine"; break;
case GENDER_FEMININE: ret["gender"] = "feminine"; break;
case GENDER_NEUTER: ret["gender"] = "neuter"; break;
case GENDER_COMMON: ret["gender"] = "common"; break;
default: throw std::logic_error("Invalid gender");
}
return ret;
}
json Verb::to_json() const {
json ret = WordForm::to_json();
switch (tense) {
case TENSE_PRESENT: ret["tense"] = "present"; break;
case TENSE_IMPERFECT: ret["tense"] = "imperfect"; break;
case TENSE_PERFECT: ret["tense"] = "perfect"; break;
case TENSE_PLUPERFECT: ret["tense"] = "pluperfect"; break;
case TENSE_FUTURE: ret["tense"] = "future"; break;
case TENSE_FUTURE_PERFECT: ret["tense"] = "future_perfect"; break;
default: throw std::logic_error("Invalid tense");
}
switch (voice) {
case VOICE_ACTIVE: ret["voice"] = "active"; break;
case VOICE_PASSIVE: ret["voice"] = "passive"; break;
default: throw std::logic_error("Invalid voice");
}
switch (mood) {
case MOOD_INDICATIVE: ret["mood"] = "indicative"; break;
case MOOD_SUBJUNCTIVE: ret["mood"] = "subjunctive"; break;
case MOOD_IMPERATIVE: ret["mood"] = "imperative"; break;
case MOOD_INFINITIVE: ret["mood"] = "infinitive"; break;
default: throw std::logic_error("Invalid mood");
}
ret["person"] = person + 1;
ret["plural"] = plural;
return ret;
}
json Participle::to_json() const {
json ret = WordForm::to_json();
switch (casus) {
case CASUS_NOMINATIVE: ret["casus"] = "nominative"; break;
case CASUS_GENITIVE: ret["casus"] = "genitive"; break;
case CASUS_DATIVE: ret["casus"] = "dative"; break;
case CASUS_ACCUSATIVE: ret["casus"] = "accusative"; break;
case CASUS_ABLATIVE: ret["casus"] = "ablative"; break;
case CASUS_VOCATIVE: ret["casus"] = "vocative"; break;
case CASUS_LOCATIVE: ret["casus"] = "locative"; break;
default: throw std::logic_error("Invalid case");
}
ret["plural"] = plural;
switch (gender) {
case GENDER_MASCULINE: ret["gender"] = "masculine"; break;
case GENDER_FEMININE: ret["gender"] = "feminine"; break;
case GENDER_NEUTER: ret["gender"] = "neuter"; break;
case GENDER_COMMON: ret["gender"] = "common"; break;
default: throw std::logic_error("Invalid gender");
}
switch (tense) {
case TENSE_PRESENT: ret["tense"] = "present"; break;
case TENSE_IMPERFECT: ret["tense"] = "imperfect"; break;
case TENSE_PERFECT: ret["tense"] = "perfect"; break;
case TENSE_PLUPERFECT: ret["tense"] = "pluperfect"; break;
case TENSE_FUTURE: ret["tense"] = "future"; break;
case TENSE_FUTURE_PERFECT: ret["tense"] = "future_perfect"; break;
default: throw std::logic_error("Invalid tense");
}
switch (voice) {
case VOICE_ACTIVE: ret["voice"] = "active"; break;
case VOICE_PASSIVE: ret["voice"] = "passive"; break;
default: throw std::logic_error("Invalid voice");
}
return ret;
}
json Supine::to_json() const {
json ret = WordForm::to_json();
switch (casus) {
case CASUS_NOMINATIVE: ret["casus"] = "nominative"; break;
case CASUS_GENITIVE: ret["casus"] = "genitive"; break;
case CASUS_DATIVE: ret["casus"] = "dative"; break;
case CASUS_ACCUSATIVE: ret["casus"] = "accusative"; break;
case CASUS_ABLATIVE: ret["casus"] = "ablative"; break;
case CASUS_VOCATIVE: ret["casus"] = "vocative"; break;
case CASUS_LOCATIVE: ret["casus"] = "locative"; break;
default: throw std::logic_error("Invalid case");
}
ret["plural"] = plural;
switch (gender) {
case GENDER_MASCULINE: ret["gender"] = "masculine"; break;
case GENDER_FEMININE: ret["gender"] = "feminine"; break;
case GENDER_NEUTER: ret["gender"] = "neuter"; break;
case GENDER_COMMON: ret["gender"] = "common"; break;
default: throw std::logic_error("Invalid gender");
}
return ret;
}
json Adjective::to_json() const {
json ret = Noun::to_json();
switch (degree) {
case DEGREE_POSITIVE: ret["degree"] = "positive"; break;
case DEGREE_COMPARATIVE: ret["degree"] = "comparative"; break;
case DEGREE_SUPERLATIVE: ret["degree"] = "superlative"; break;
default: throw std::logic_error("Invalid degree");
}
return ret;
}
json Adverb::to_json() const {
json ret = WordForm::to_json();
switch (degree) {
case DEGREE_POSITIVE: ret["degree"] = "positive"; break;
case DEGREE_COMPARATIVE: ret["degree"] = "comparative"; break;
case DEGREE_SUPERLATIVE: ret["degree"] = "superlative"; break;
default: throw std::logic_error("Invalid gender");
}
return ret;
}
json Preposition::to_json() const {
json ret = WordForm::to_json();
switch (casus) {
case CASUS_NOMINATIVE: ret["casus"] = "nominative"; break;
case CASUS_GENITIVE: ret["casus"] = "genitive"; break;
case CASUS_DATIVE: ret["casus"] = "dative"; break;
case CASUS_ACCUSATIVE: ret["casus"] = "accusative"; break;
case CASUS_ABLATIVE: ret["casus"] = "ablative"; break;
case CASUS_VOCATIVE: ret["casus"] = "vocative"; break;
case CASUS_LOCATIVE: ret["casus"] = "locative"; break;
default: throw std::logic_error("Invalid case");
}
return ret;
}
json Numeral::to_json() const {
json ret = Noun::to_json();
switch (type) {
case NUMERAL_TYPE_CARDINAL: ret["type"] = "cardinal"; break;
case NUMERAL_TYPE_ORDINAL: ret["type"] = "ordinal"; break;
case NUMERAL_TYPE_DISTRIBUTIVE: ret["type"] = "distributive"; break;
case NUMERAL_TYPE_ADVERB: ret["type"] = "adverb"; break;
default: throw std::logic_error("Invalid type");
}
return ret;
}