From d5ee4e39e5b5b3b8daa85cd972802195ad35e965 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sun, 20 Mar 2016 18:19:05 -0400 Subject: Added fallback to vowel sound detection when no entry exists in CMUDICT --- lib/word.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'lib/word.cpp') diff --git a/lib/word.cpp b/lib/word.cpp index 156e7e0..15af150 100644 --- a/lib/word.cpp +++ b/lib/word.cpp @@ -32,9 +32,17 @@ namespace verbly { bool word::starts_with_vowel_sound() const { - return std::any_of(std::begin(pronunciations), std::end(pronunciations), [] (std::list phonemes) { - return (phonemes.front().find_first_of("012") != std::string::npos); - }); + if (pronunciations.size() > 0) + { + return std::any_of(std::begin(pronunciations), std::end(pronunciations), [] (std::list phonemes) { + return (phonemes.front().find_first_of("012") != std::string::npos); + }); + } else { + // If the word is not in CMUDICT, fall back to checking whether the first letter is a vowel + // Not perfect but will work in most cases + char ch = tolower(base_form().front()); + return (ch == 'a') || (ch == 'e') || (ch == 'i') || (ch == 'o') || (ch == 'u'); + } } }; -- cgit 1.4.1