summary refs log tree commit diff stats
path: root/generator
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2016-05-30 11:31:20 -0400
committerKelly Rauchenberger <fefferburbia@gmail.com>2016-05-30 11:31:20 -0400
commit6c2aca03c89b37e136ab4c7ea58b485dadc85bcd (patch)
treea9e562aa7e55b02d789755c61bbc4e5c1a8fb383 /generator
parentf94d32242380b23b361f66eb021cad17c35acd8c (diff)
downloadverbly-6c2aca03c89b37e136ab4c7ea58b485dadc85bcd.tar.gz
verbly-6c2aca03c89b37e136ab4c7ea58b485dadc85bcd.tar.bz2
verbly-6c2aca03c89b37e136ab4c7ea58b485dadc85bcd.zip
Added pronunciation syllable count and stress structure
Also updated CMakeLists.txt such that including projects don't have to include sqlite3.
Diffstat (limited to 'generator')
-rw-r--r--generator/generator.cpp49
-rw-r--r--generator/schema.sql8
2 files changed, 45 insertions, 12 deletions
diff --git a/generator/generator.cpp b/generator/generator.cpp index 3201154..6a16467 100644 --- a/generator/generator.cpp +++ b/generator/generator.cpp
@@ -80,6 +80,8 @@ struct pronunciation_t {
80 std::string phonemes; 80 std::string phonemes;
81 std::string prerhyme; 81 std::string prerhyme;
82 std::string rhyme; 82 std::string rhyme;
83 int syllables = 0;
84 std::string stress;
83 85
84 bool operator<(const pronunciation_t& other) const 86 bool operator<(const pronunciation_t& other) const
85 { 87 {
@@ -609,6 +611,8 @@ int main(int argc, char** argv)
609 611
610 pronunciation_t p; 612 pronunciation_t p;
611 p.phonemes = phonemes; 613 p.phonemes = phonemes;
614
615 // Rhyme detection
612 if (phemstrt != std::end(phoneme_set)) 616 if (phemstrt != std::end(phoneme_set))
613 { 617 {
614 std::stringstream rhymer; 618 std::stringstream rhymer;
@@ -641,6 +645,23 @@ int main(int argc, char** argv)
641 p.rhyme = ""; 645 p.rhyme = "";
642 } 646 }
643 647
648 // Syllable/stress
649 for (auto phm : phoneme_set)
650 {
651 if (isdigit(phm.back()))
652 {
653 // It's a vowel!
654 p.syllables++;
655
656 if (phm.back() == '1')
657 {
658 p.stress.push_back('1');
659 } else {
660 p.stress.push_back('0');
661 }
662 }
663 }
664
644 pronunciations[canonical].insert(p); 665 pronunciations[canonical].insert(p);
645 } 666 }
646 } 667 }
@@ -864,9 +885,9 @@ int main(int argc, char** argv)
864 { 885 {
865 if (!pronunciation.rhyme.empty()) 886 if (!pronunciation.rhyme.empty())
866 { 887 {
867 query = "INSERT INTO verb_pronunciations (verb_id, pronunciation, prerhyme, rhyme) VALUES (?, ?, ?, ?)"; 888 query = "INSERT INTO verb_pronunciations (verb_id, pronunciation, syllables, stress, prerhyme, rhyme) VALUES (?, ?, ?, ?, ?, ?)";
868 } else { 889 } else {
869 query = "INSERT INTO verb_pronunciations (verb_id, pronunciation) VALUES (?, ?)"; 890 query = "INSERT INTO verb_pronunciations (verb_id, pronunciation, syllables, stress) VALUES (?, ?, ?, ?)";
870 } 891 }
871 892
872 if (sqlite3_prepare_v2(ppdb, query.c_str(), query.length(), &ppstmt, NULL) != SQLITE_OK) 893 if (sqlite3_prepare_v2(ppdb, query.c_str(), query.length(), &ppstmt, NULL) != SQLITE_OK)
@@ -876,11 +897,13 @@ int main(int argc, char** argv)
876 897
877 sqlite3_bind_int(ppstmt, 1, rowid); 898 sqlite3_bind_int(ppstmt, 1, rowid);
878 sqlite3_bind_text(ppstmt, 2, pronunciation.phonemes.c_str(), pronunciation.phonemes.length(), SQLITE_TRANSIENT); 899 sqlite3_bind_text(ppstmt, 2, pronunciation.phonemes.c_str(), pronunciation.phonemes.length(), SQLITE_TRANSIENT);
900 sqlite3_bind_int(ppstmt, 3, pronunciation.syllables);
901 sqlite3_bind_text(ppstmt, 4, pronunciation.stress.c_str(), pronunciation.stress.length(), SQLITE_TRANSIENT);
879 902
880 if (!pronunciation.rhyme.empty()) 903 if (!pronunciation.rhyme.empty())
881 { 904 {
882 sqlite3_bind_text(ppstmt, 3, pronunciation.prerhyme.c_str(), pronunciation.prerhyme.length(), SQLITE_TRANSIENT); 905 sqlite3_bind_text(ppstmt, 5, pronunciation.prerhyme.c_str(), pronunciation.prerhyme.length(), SQLITE_TRANSIENT);
883 sqlite3_bind_text(ppstmt, 4, pronunciation.rhyme.c_str(), pronunciation.rhyme.length(), SQLITE_TRANSIENT); 906 sqlite3_bind_text(ppstmt, 6, pronunciation.rhyme.c_str(), pronunciation.rhyme.length(), SQLITE_TRANSIENT);
884 } 907 }
885 908
886 if (sqlite3_step(ppstmt) != SQLITE_DONE) 909 if (sqlite3_step(ppstmt) != SQLITE_DONE)
@@ -1243,9 +1266,9 @@ int main(int argc, char** argv)
1243 { 1266 {
1244 if (!pronunciation.rhyme.empty()) 1267 if (!pronunciation.rhyme.empty())
1245 { 1268 {
1246 query = "INSERT INTO noun_pronunciations (noun_id, pronunciation, prerhyme, rhyme) VALUES (?, ?, ?, ?)"; 1269 query = "INSERT INTO noun_pronunciations (noun_id, pronunciation, syllables, stress, prerhyme, rhyme) VALUES (?, ?, ?, ?, ?, ?)";
1247 } else { 1270 } else {
1248 query = "INSERT INTO noun_pronunciations (noun_id, pronunciation) VALUES (?, ?)"; 1271 query = "INSERT INTO noun_pronunciations (noun_id, pronunciation, syllables, stress) VALUES (?, ?, ?, ?)";
1249 } 1272 }
1250 1273
1251 break; 1274 break;
@@ -1255,9 +1278,9 @@ int main(int argc, char** argv)
1255 { 1278 {
1256 if (!pronunciation.rhyme.empty()) 1279 if (!pronunciation.rhyme.empty())
1257 { 1280 {
1258 query = "INSERT INTO adjective_pronunciations (adjective_id, pronunciation, prerhyme, rhyme) VALUES (?, ?, ?, ?)"; 1281 query = "INSERT INTO adjective_pronunciations (adjective_id, pronunciation, syllables, stress, prerhyme, rhyme) VALUES (?, ?, ?, ?, ?, ?)";
1259 } else { 1282 } else {
1260 query = "INSERT INTO adjective_pronunciations (adjective_id, pronunciation) VALUES (?, ?)"; 1283 query = "INSERT INTO adjective_pronunciations (adjective_id, pronunciation, syllables, stress) VALUES (?, ?, ?, ?)";
1261 } 1284 }
1262 1285
1263 break; 1286 break;
@@ -1267,9 +1290,9 @@ int main(int argc, char** argv)
1267 { 1290 {
1268 if (!pronunciation.rhyme.empty()) 1291 if (!pronunciation.rhyme.empty())
1269 { 1292 {
1270 query = "INSERT INTO adverb_pronunciations (adverb_id, pronunciation, prerhyme, rhyme) VALUES (?, ?, ?, ?)"; 1293 query = "INSERT INTO adverb_pronunciations (adverb_id, pronunciation, syllables, stress, prerhyme, rhyme) VALUES (?, ?, ?, ?, ?, ?)";
1271 } else { 1294 } else {
1272 query = "INSERT INTO adverb_pronunciations (adverb_id, pronunciation) VALUES (?, ?)"; 1295 query = "INSERT INTO adverb_pronunciations (adverb_id, pronunciation, syllables, stress) VALUES (?, ?, ?, ?)";
1273 } 1296 }
1274 1297
1275 break; 1298 break;
@@ -1283,11 +1306,13 @@ int main(int argc, char** argv)
1283 1306
1284 sqlite3_bind_int(ppstmt, 1, rowid); 1307 sqlite3_bind_int(ppstmt, 1, rowid);
1285 sqlite3_bind_text(ppstmt, 2, pronunciation.phonemes.c_str(), pronunciation.phonemes.length(), SQLITE_TRANSIENT); 1308 sqlite3_bind_text(ppstmt, 2, pronunciation.phonemes.c_str(), pronunciation.phonemes.length(), SQLITE_TRANSIENT);
1309 sqlite3_bind_int(ppstmt, 3, pronunciation.syllables);
1310 sqlite3_bind_text(ppstmt, 4, pronunciation.stress.c_str(), pronunciation.stress.length(), SQLITE_TRANSIENT);
1286 1311
1287 if (!pronunciation.rhyme.empty()) 1312 if (!pronunciation.rhyme.empty())
1288 { 1313 {
1289 sqlite3_bind_text(ppstmt, 3, pronunciation.prerhyme.c_str(), pronunciation.prerhyme.length(), SQLITE_TRANSIENT); 1314 sqlite3_bind_text(ppstmt, 5, pronunciation.prerhyme.c_str(), pronunciation.prerhyme.length(), SQLITE_TRANSIENT);
1290 sqlite3_bind_text(ppstmt, 4, pronunciation.rhyme.c_str(), pronunciation.rhyme.length(), SQLITE_TRANSIENT); 1315 sqlite3_bind_text(ppstmt, 6, pronunciation.rhyme.c_str(), pronunciation.rhyme.length(), SQLITE_TRANSIENT);
1291 } 1316 }
1292 1317
1293 if (sqlite3_step(ppstmt) != SQLITE_DONE) 1318 if (sqlite3_step(ppstmt) != SQLITE_DONE)
diff --git a/generator/schema.sql b/generator/schema.sql index 1836c62..410b536 100644 --- a/generator/schema.sql +++ b/generator/schema.sql
@@ -186,6 +186,8 @@ CREATE TABLE `noun_pronunciations` (
186 `pronunciation` VARCHAR(64) NOT NULL, 186 `pronunciation` VARCHAR(64) NOT NULL,
187 `prerhyme` VARCHAR(8), 187 `prerhyme` VARCHAR(8),
188 `rhyme` VARCHAR(64), 188 `rhyme` VARCHAR(64),
189 `syllables` INT NOT NULL,
190 `stress` VARCHAR(64) NOT NULL,
189 FOREIGN KEY (`noun_id`) REFERENCES `nouns`(`noun_id`) 191 FOREIGN KEY (`noun_id`) REFERENCES `nouns`(`noun_id`)
190); 192);
191 193
@@ -195,6 +197,8 @@ CREATE TABLE `verb_pronunciations` (
195 `pronunciation` VARCHAR(64) NOT NULL, 197 `pronunciation` VARCHAR(64) NOT NULL,
196 `prerhyme` VARCHAR(8), 198 `prerhyme` VARCHAR(8),
197 `rhyme` VARCHAR(64), 199 `rhyme` VARCHAR(64),
200 `syllables` INT NOT NULL,
201 `stress` VARCHAR(64) NOT NULL,
198 FOREIGN KEY (`verb_id`) REFERENCES `verbs`(`verb_id`) 202 FOREIGN KEY (`verb_id`) REFERENCES `verbs`(`verb_id`)
199); 203);
200 204
@@ -204,6 +208,8 @@ CREATE TABLE `adjective_pronunciations` (
204 `pronunciation` VARCHAR(64) NOT NULL, 208 `pronunciation` VARCHAR(64) NOT NULL,
205 `prerhyme` VARCHAR(8), 209 `prerhyme` VARCHAR(8),
206 `rhyme` VARCHAR(64), 210 `rhyme` VARCHAR(64),
211 `syllables` INT NOT NULL,
212 `stress` VARCHAR(64) NOT NULL,
207 FOREIGN KEY (`adjective_id`) REFERENCES `adjectives`(`adjective_id`) 213 FOREIGN KEY (`adjective_id`) REFERENCES `adjectives`(`adjective_id`)
208); 214);
209 215
@@ -213,6 +219,8 @@ CREATE TABLE `adverb_pronunciations` (
213 `pronunciation` VARCHAR(64) NOT NULL, 219 `pronunciation` VARCHAR(64) NOT NULL,
214 `prerhyme` VARCHAR(8), 220 `prerhyme` VARCHAR(8),
215 `rhyme` VARCHAR(64), 221 `rhyme` VARCHAR(64),
222 `syllables` INT NOT NULL,
223 `stress` VARCHAR(64) NOT NULL,
216 FOREIGN KEY (`adverb_id`) REFERENCES `adverbs`(`adverb_id`) 224 FOREIGN KEY (`adverb_id`) REFERENCES `adverbs`(`adverb_id`)
217); 225);
218 226