-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmakemql.cpp
More file actions
230 lines (200 loc) · 7.85 KB
/
makemql.cpp
File metadata and controls
230 lines (200 loc) · 7.85 KB
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#include <string>
#include <iostream>
#include "makemql.hpp"
using namespace std;
void mql::head()
{
os << "// Create database\n"
<< "CREATE DATABASE 'jvulgate'\n"
<< "GO\n"
<< "\n"
<< "// Switch to using database\n"
<< "USE DATABASE 'jvulgate' GO\n"
<< "\n"
<< "\n"
<< "\n";
}
void mql::list_enum(const string& name, const initializer_list<string>& il, bool first_is_default)
{
os << "CREATE ENUMERATION " << name << " = {\n";
bool first = first_is_default;
int num = 0;
for (const string& s : il) {
os << " " << (first ? "DEFAULT " : "") << s << " = " << ++num << (s != *(il.end()-1) ? ",\n" : "\n");
first = false;
}
os << "}\n"
<< "GO\n"
<< "\n";
}
void mql::enums()
{
list_enum("book_name_t",
{ "Matthew", "Mark", "Luke", "John", "Acts", "Romans",
"I_Corinthians", "II_Corinthians", "Galatians", "Ephesians", "Philippians",
"Colossians", "I_Thessalonians", "II_Thessalonians", "I_Timothy", "II_Timothy",
"Titus", "Philemon", "Hebrews", "James", "I_Peter", "II_Peter",
"I_John", "II_John", "III_John", "Jude", "Revelation" },
false);
list_enum("psp_t",
{ "adjective", "adverb", "cardinal_numeral", "conjunction", "demonstrative_pronoun", "foreign_word",
"indefinite_pronoun", "interjection", "interrogative_adverb", "interrogative_pronoun", "noun",
"ordinal_numeral", "personal_pronoun", "personal_reflexive_pronoun", "possessive_pronoun",
"possessive_reflexive_pronoun", "preposition", "proper_noun", "reciprocal_pronoun",
"relative_adverb", "relative_pronoun", "subjunction", "verb" },
false);
list_enum("person_t",{ "NA", "first_person", "second_person", "third_person" });
list_enum("number_t",{ "NA", "singular", "plural" });
list_enum("tense_t", { "NA", "future", "future_perfect", "imperfect", "perfect", "pluperfect", "present" });
list_enum("mood_t", { "NA", "indicative", "subjunctive", "imperative", "infinitive", "participle", "gerund", "gerundive", "supine"});
list_enum("voice_t", { "NA", "active", "passive" });
list_enum("gender_t",{ "NA", "masculine", "feminine", "neuter", "masculine_or_feminine", "masculine_or_neuter", "feminine_or_neuter", "masculine_or_feminine_or_neuter" });
list_enum("case_t", { "NA", "nominative", "accusative", "genitive", "dative", "ablative", "vocative" });
list_enum("degree_t",{ "NA", "positive", "comparative", "superlative" });
list_enum("inflection_t", { "non_inflecting", "inflecting" }, false);
list_enum("conjugation_t", { "NA", "first_c", "second_c", "third_c", "third_c_io", "fourth_c", "irregular" });
list_enum("declension_t", { "NA", "first_d", "first_or_second_d", "second_d", "second_d_er", "third_d", "fourth_d", "fifth_d", "indeclinable", "irregular" });
list_enum("stem_t", { "NA", "a", "b", "c", "d", "e", "g", "i", "l", "n", "o", "o_or_a", "p", "r", "t", "u", "v", "indeclinable", "irregular" });
}
void mql::types()
{
os << "// Object type word\n"
<< "CREATE OBJECT TYPE\n"
<< "[word\n"
<< " frequency_rank : integer DEFAULT 99999;\n"
<< " lexeme_occurrences : integer DEFAULT 0;\n"
<< " ref : string DEFAULT \"\";\n"
<< " surface : string FROM SET DEFAULT \"\";\n"
<< " suffix : string FROM SET DEFAULT \"\";\n"
<< " normalized : string FROM SET DEFAULT \"\";\n"
<< " lemma : string FROM SET WITH INDEX DEFAULT \"\";\n"
<< " lemma_variant : integer DEFAULT 0;\n"
<< " lemma_with_variant : string FROM SET WITH INDEX DEFAULT \"\";\n"
<< " psp : psp_t;\n"
<< " person : person_t DEFAULT NA;\n"
<< " number : number_t DEFAULT NA;\n"
<< " case : case_t DEFAULT NA;\n"
<< " gender : gender_t DEFAULT NA;\n"
<< " tense : tense_t DEFAULT NA;\n"
<< " voice : voice_t DEFAULT NA;\n"
<< " mood : mood_t DEFAULT NA;\n"
<< " degree : degree_t DEFAULT NA;\n"
<< " inflection : inflection_t;\n"
<< " conjugation : conjugation_t DEFAULT NA;\n"
<< " declension : declension_t DEFAULT NA;\n"
<< " stem : stem_t DEFAULT NA;\n"
<< "]\n"
<< "GO\n"
<< "\n";
os << "// Object type book\n"
<< "CREATE OBJECT TYPE\n"
<< "[book\n"
<< " book : book_name_t;\n"
<< "]\n"
<< "GO\n"
<< "\n";
os << "// Object type chapter\n"
<< "CREATE OBJECT TYPE\n"
<< "[chapter\n"
<< " book : book_name_t;\n"
<< " chapter : integer DEFAULT 0;\n"
<< "]\n"
<< "GO\n"
<< "\n";
os << "// Object type verse\n"
<< "CREATE OBJECT TYPE\n"
<< "[verse\n"
<< " book : book_name_t;\n"
<< " chapter : integer DEFAULT 0;\n"
<< " verse : integer DEFAULT 0;\n"
<< " ref : string DEFAULT \"\";\n"
<< "]\n"
<< "GO\n"
<< "\n";
os << "// Object type sentence\n"
<< "CREATE OBJECT TYPE\n"
<< "[sentence\n"
<< "]\n"
<< "GO\n"
<< "\n";
}
void mql::start_type(const string& t)
{
os << "DROP INDEXES ON OBJECT TYPE[" << t << "] GO\n\n";
os << "CREATE OBJECTS\n"
<< "WITH OBJECT TYPE[" << t << "]\n";
}
void mql::end_type(const string& t)
{
os << "GO\n";
os << "CREATE INDEXES ON OBJECT TYPE[" << t << "] GO\n\n";
}
void mql::make_word(const word& w)
{
os << "\n"
<< "CREATE OBJECT\n"
<< "FROM MONADS= { " << w.monad() << " }\n"
<< "[\n"
<< "frequency_rank:=" << w.frequency_rank() << ";\n"
<< "lexeme_occurrences:=" << w.occurrences() << ";\n"
<< "ref:=\"" << w.citation_part() << "\";\n"
<< "surface:=\"" << w.form() << "\";\n"
<< "normalized:=\"" << w.form() << "\";\n" // Same as surface, but exercises will not add suffix
<< "lemma:=\"" << w.lemma() << "\";\n"
<< "lemma_variant:=" << w.lemma_variant() << ";\n"
<< "lemma_with_variant:=\"" << w.lemma() << (w.lemma_variant()==0 ? "" :
w.lemma_variant()==1 ? " I" :
w.lemma_variant()==2 ? " II" :
w.lemma_variant()==3 ? " III" : " ?") << "\";\n"
<< "suffix:=\"" << w.suffix() << "\";\n"
<< "psp:=" << w.part_of_speech() << ";\n"
<< "conjugation:=" << w.conjugation() << ";\n"
<< "declension:=" << w.declension() << ";\n"
<< "stem:=" << w.stem() << ";\n";
for (const pair<string,string>& m : w.morph)
os << m.first << ":=" << m.second << ";\n";
os << "]\n";
}
void mql::make_sentence(const sentence& s)
{
os << "\n"
<< "CREATE OBJECT\n"
<< "FROM MONADS= { " << s.start_monad() << "-" << s.end_monad() << " }\n"
<< "[\n"
<< "]\n";
}
void mql::make_book(const book& b)
{
os << "\n"
<< "CREATE OBJECT\n"
<< "FROM MONADS= { " << b.start_monad() << "-" << b.end_monad() << " }\n"
<< "[\n"
<< "book:=" << b.book_name() << ";\n"
<< "]\n";
}
void mql::make_chapter(const chapter& c)
{
os << "\n"
<< "CREATE OBJECT\n"
<< "FROM MONADS= { " << c.start_monad() << "-" << c.end_monad() << " }\n"
<< "[\n"
<< "book:=" << c.book_name() << ";\n"
<< "chapter:=" << c.chap_no() << ";\n"
<< "]\n";
}
void mql::make_verse(const verse& v)
{
os << "\n"
<< "CREATE OBJECT\n"
<< "FROM MONADS= { " << v.start_monad() << "-" << v.end_monad() << " }\n"
<< "[\n"
<< "book:=" << v.book_name() << ";\n"
<< "chapter:=" << v.chap_no() << ";\n"
<< "verse:=" << v.verse_no() << ";\n"
<< "ref:=\"" << v.ref() << "\";\n"
<< "]\n";
}
void mql::tail()
{
os << "VACUUM DATABASE ANALYZE GO\n\n";
}