diff options
Diffstat (limited to 'lib/pronunciation.cpp')
| -rw-r--r-- | lib/pronunciation.cpp | 69 |
1 files changed, 69 insertions, 0 deletions
| diff --git a/lib/pronunciation.cpp b/lib/pronunciation.cpp new file mode 100644 index 0000000..f5b742f --- /dev/null +++ b/lib/pronunciation.cpp | |||
| @@ -0,0 +1,69 @@ | |||
| 1 | #include "pronunciation.h" | ||
| 2 | #include <sqlite3.h> | ||
| 3 | #include "form.h" | ||
| 4 | #include "lemma.h" | ||
| 5 | #include "word.h" | ||
| 6 | #include "util.h" | ||
| 7 | |||
| 8 | namespace verbly { | ||
| 9 | |||
| 10 | const object pronunciation::objectType = object::pronunciation; | ||
| 11 | |||
| 12 | const std::list<std::string> pronunciation::select = {"pronunciation_id", "phonemes", "syllables", "stress", "prerhyme", "rhyme"}; | ||
| 13 | |||
| 14 | const field pronunciation::id = field::integerField(object::pronunciation, "pronunciation_id"); | ||
| 15 | const field pronunciation::numOfSyllables = field::integerField(object::pronunciation, "syllables"); | ||
| 16 | const field pronunciation::stress = field::stringField(object::pronunciation, "stress"); | ||
| 17 | |||
| 18 | const field pronunciation::form = field::joinThrough(object::pronunciation, "pronunciation_id", object::form, "forms_pronunciations", "form_id"); | ||
| 19 | |||
| 20 | const field pronunciation::prerhyme = field::stringField(object::pronunciation, "prerhyme", true); | ||
| 21 | const field pronunciation::rhyme = field::stringField(object::pronunciation, "rhyme", true); | ||
| 22 | |||
| 23 | pronunciation::pronunciation(const database& db, sqlite3_stmt* row) : db_(&db), valid_(true) | ||
| 24 | { | ||
| 25 | id_ = sqlite3_column_int(row, 0); | ||
| 26 | |||
| 27 | std::string phonemesStr(reinterpret_cast<const char*>(sqlite3_column_text(row, 1))); | ||
| 28 | phonemes_ = split<std::vector<std::string>>(phonemesStr, " "); | ||
| 29 | |||
| 30 | syllables_ = sqlite3_column_int(row, 2); | ||
| 31 | stress_ = std::string(reinterpret_cast<const char*>(sqlite3_column_text(row, 3))); | ||
| 32 | |||
| 33 | if (sqlite3_column_type(row, 5) != SQLITE_NULL) | ||
| 34 | { | ||
| 35 | hasRhyme_ = true; | ||
| 36 | |||
| 37 | prerhyme_ = std::string(reinterpret_cast<const char*>(sqlite3_column_text(row, 4))); | ||
| 38 | rhyme_ = std::string(reinterpret_cast<const char*>(sqlite3_column_text(row, 5))); | ||
| 39 | } | ||
| 40 | } | ||
| 41 | |||
| 42 | filter pronunciation::rhymesWith(const pronunciation& arg) | ||
| 43 | { | ||
| 44 | return (prerhyme != arg.getPrerhyme()) && (rhyme == arg.getRhyme()); | ||
| 45 | } | ||
| 46 | |||
| 47 | /*filter pronunciation::rhymesWith(const class form& arg) | ||
| 48 | { | ||
| 49 | filter result; | ||
| 50 | |||
| 51 | for (const pronunciation& p : arg.getPronunciations()) | ||
| 52 | { | ||
| 53 | result |= rhymesWith(p); | ||
| 54 | } | ||
| 55 | |||
| 56 | return result; | ||
| 57 | } | ||
| 58 | |||
| 59 | filter pronunciation::rhymesWith(const lemma& arg) | ||
| 60 | { | ||
| 61 | return rhymesWith(arg.getBaseForm()); | ||
| 62 | } | ||
| 63 | |||
| 64 | filter pronunciation::rhymesWith(const word& arg) | ||
| 65 | { | ||
| 66 | return rhymesWith(arg.getLemma()); | ||
| 67 | }*/ | ||
| 68 | |||
| 69 | }; | ||
