diff options
| author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2018-03-31 23:05:02 -0400 |
|---|---|---|
| committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2018-03-31 23:05:02 -0400 |
| commit | 75e947fa0021547f460496d1c3aef5b61af4c669 (patch) | |
| tree | 64559a5329b3e5983ffdfe7ee2ad65c7c938e98d /generator/pronunciation.cpp | |
| parent | 3554df2e34e63364eea3a7998e0dfb0e6be65ca4 (diff) | |
| download | verbly-75e947fa0021547f460496d1c3aef5b61af4c669.tar.gz verbly-75e947fa0021547f460496d1c3aef5b61af4c669.tar.bz2 verbly-75e947fa0021547f460496d1c3aef5b61af4c669.zip | |
Migrated generator to hkutil
Diffstat (limited to 'generator/pronunciation.cpp')
| -rw-r--r-- | generator/pronunciation.cpp | 55 |
1 files changed, 36 insertions, 19 deletions
| diff --git a/generator/pronunciation.cpp b/generator/pronunciation.cpp index eb07607..3075d42 100644 --- a/generator/pronunciation.cpp +++ b/generator/pronunciation.cpp | |||
| @@ -3,9 +3,7 @@ | |||
| 3 | #include <algorithm> | 3 | #include <algorithm> |
| 4 | #include <cctype> | 4 | #include <cctype> |
| 5 | #include <iterator> | 5 | #include <iterator> |
| 6 | #include "database.h" | 6 | #include <hkutil/string.h> |
| 7 | #include "field.h" | ||
| 8 | #include "../lib/util.h" | ||
| 9 | 7 | ||
| 10 | namespace verbly { | 8 | namespace verbly { |
| 11 | namespace generator { | 9 | namespace generator { |
| @@ -16,28 +14,45 @@ namespace verbly { | |||
| 16 | id_(nextId_++), | 14 | id_(nextId_++), |
| 17 | phonemes_(phonemes) | 15 | phonemes_(phonemes) |
| 18 | { | 16 | { |
| 19 | auto phonemeList = split<std::list<std::string>>(phonemes, " "); | 17 | auto phonemeList = |
| 20 | 18 | hatkirby::split<std::list<std::string>>(phonemes, " "); | |
| 21 | auto rhymeStart = std::find_if(std::begin(phonemeList), std::end(phonemeList), [] (std::string phoneme) { | 19 | |
| 22 | return phoneme.find("1") != std::string::npos; | 20 | std::list<std::string>::iterator rhymeStart = |
| 23 | }); | 21 | std::find_if( |
| 22 | std::begin(phonemeList), | ||
| 23 | std::end(phonemeList), | ||
| 24 | [] (std::string phoneme) { | ||
| 25 | return phoneme.find("1") != std::string::npos; | ||
| 26 | }); | ||
| 24 | 27 | ||
| 25 | // Rhyme detection | 28 | // Rhyme detection |
| 26 | if (rhymeStart != std::end(phonemeList)) | 29 | if (rhymeStart != std::end(phonemeList)) |
| 27 | { | 30 | { |
| 28 | std::list<std::string> rhymePhonemes; | 31 | std::list<std::string> rhymePhonemes; |
| 29 | 32 | ||
| 30 | std::transform(rhymeStart, std::end(phonemeList), std::back_inserter(rhymePhonemes), [] (std::string phoneme) { | 33 | std::transform( |
| 31 | std::string naked; | 34 | rhymeStart, |
| 32 | 35 | std::end(phonemeList), | |
| 33 | std::remove_copy_if(std::begin(phoneme), std::end(phoneme), std::back_inserter(naked), [] (char ch) { | 36 | std::back_inserter(rhymePhonemes), |
| 34 | return std::isdigit(ch); | 37 | [] (std::string phoneme) { |
| 38 | std::string naked; | ||
| 39 | |||
| 40 | std::remove_copy_if( | ||
| 41 | std::begin(phoneme), | ||
| 42 | std::end(phoneme), | ||
| 43 | std::back_inserter(naked), | ||
| 44 | [] (char ch) { | ||
| 45 | return std::isdigit(ch); | ||
| 46 | }); | ||
| 47 | |||
| 48 | return naked; | ||
| 35 | }); | 49 | }); |
| 36 | 50 | ||
| 37 | return naked; | 51 | rhyme_ = |
| 38 | }); | 52 | hatkirby::implode( |
| 39 | 53 | std::begin(rhymePhonemes), | |
| 40 | rhyme_ = implode(std::begin(rhymePhonemes), std::end(rhymePhonemes), " "); | 54 | std::end(rhymePhonemes), |
| 55 | " "); | ||
| 41 | 56 | ||
| 42 | if (rhymeStart != std::begin(phonemeList)) | 57 | if (rhymeStart != std::begin(phonemeList)) |
| 43 | { | 58 | { |
| @@ -63,9 +78,11 @@ namespace verbly { | |||
| 63 | } | 78 | } |
| 64 | } | 79 | } |
| 65 | 80 | ||
| 66 | database& operator<<(database& db, const pronunciation& arg) | 81 | hatkirby::database& operator<<( |
| 82 | hatkirby::database& db, | ||
| 83 | const pronunciation& arg) | ||
| 67 | { | 84 | { |
| 68 | std::list<field> fields; | 85 | std::list<hatkirby::column> fields; |
| 69 | 86 | ||
| 70 | fields.emplace_back("pronunciation_id", arg.getId()); | 87 | fields.emplace_back("pronunciation_id", arg.getId()); |
| 71 | fields.emplace_back("phonemes", arg.getPhonemes()); | 88 | fields.emplace_back("phonemes", arg.getPhonemes()); |
