diff options
| author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2016-04-17 13:44:37 -0400 |
|---|---|---|
| committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2016-04-17 13:44:37 -0400 |
| commit | 04338f2b040fee5142904c062e0e38c836601034 (patch) | |
| tree | a3ca42f738839ae4f6c83d599277c33203beb733 /lib/word.cpp | |
| parent | 040ee58fecdc9c478004bc2e554e1ae126ec4602 (diff) | |
| download | verbly-04338f2b040fee5142904c062e0e38c836601034.tar.gz verbly-04338f2b040fee5142904c062e0e38c836601034.tar.bz2 verbly-04338f2b040fee5142904c062e0e38c836601034.zip | |
Fixed perfect rhyming
Rhyme detection now ensures that any rhymes it finds are perfect rhymes and not identical rhymes. Rhyme detection is also now a lot faster because additional information is stored in the datafile. Also fixed a bug in the query interface (and the generator) that could cause incorrect queries to be executed.
Diffstat (limited to 'lib/word.cpp')
| -rw-r--r-- | lib/word.cpp | 41 |
1 files changed, 22 insertions, 19 deletions
| diff --git a/lib/word.cpp b/lib/word.cpp index 13c611f..49e34a1 100644 --- a/lib/word.cpp +++ b/lib/word.cpp | |||
| @@ -3,6 +3,26 @@ | |||
| 3 | 3 | ||
| 4 | namespace verbly { | 4 | namespace verbly { |
| 5 | 5 | ||
| 6 | rhyme::rhyme(std::string prerhyme, std::string phonemes) : _prerhyme(prerhyme), _rhyme(phonemes) | ||
| 7 | { | ||
| 8 | |||
| 9 | } | ||
| 10 | |||
| 11 | std::string rhyme::get_prerhyme() const | ||
| 12 | { | ||
| 13 | return _prerhyme; | ||
| 14 | } | ||
| 15 | |||
| 16 | std::string rhyme::get_rhyme() const | ||
| 17 | { | ||
| 18 | return _rhyme; | ||
| 19 | } | ||
| 20 | |||
| 21 | bool rhyme::operator==(const rhyme& other) const | ||
| 22 | { | ||
| 23 | return std::tie(_prerhyme, _rhyme) == std::tie(other._prerhyme, other._rhyme); | ||
| 24 | } | ||
| 25 | |||
| 6 | word::word() | 26 | word::word() |
| 7 | { | 27 | { |
| 8 | 28 | ||
| @@ -13,28 +33,11 @@ namespace verbly { | |||
| 13 | 33 | ||
| 14 | } | 34 | } |
| 15 | 35 | ||
| 16 | std::list<std::string> word::rhyme_phonemes() const | 36 | std::list<rhyme> word::get_rhymes() const |
| 17 | { | 37 | { |
| 18 | assert(_valid == true); | 38 | assert(_valid == true); |
| 19 | 39 | ||
| 20 | std::list<std::string> result; | 40 | return rhymes; |
| 21 | |||
| 22 | for (auto pronunciation : pronunciations) | ||
| 23 | { | ||
| 24 | auto phemstrt = std::find_if(std::begin(pronunciation), std::end(pronunciation), [] (std::string phoneme) { | ||
| 25 | return phoneme.find("1") != std::string::npos; | ||
| 26 | }); | ||
| 27 | |||
| 28 | std::stringstream rhymer; | ||
| 29 | for (auto it = phemstrt; it != std::end(pronunciation); it++) | ||
| 30 | { | ||
| 31 | rhymer << " " << *it; | ||
| 32 | } | ||
| 33 | |||
| 34 | result.push_back(rhymer.str()); | ||
| 35 | } | ||
| 36 | |||
| 37 | return result; | ||
| 38 | } | 41 | } |
| 39 | 42 | ||
| 40 | bool word::starts_with_vowel_sound() const | 43 | bool word::starts_with_vowel_sound() const |
