diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2016-05-30 11:31:20 -0400 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2016-05-30 11:31:20 -0400 |
commit | 6c2aca03c89b37e136ab4c7ea58b485dadc85bcd (patch) | |
tree | a9e562aa7e55b02d789755c61bbc4e5c1a8fb383 /generator/generator.cpp | |
parent | f94d32242380b23b361f66eb021cad17c35acd8c (diff) | |
download | verbly-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/generator.cpp')
-rw-r--r-- | generator/generator.cpp | 49 |
1 files changed, 37 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) |