Problem Statement
You are given a
Each letter is either a vowel or a consonant. In this problem the vowels are 'a', 'e', 'i', 'o', and 'u'. Note that in this problem 'y' is always a consonant. The rules for counting syllables are as follows:
- In general, the number of syllables is equal to the number of vowels in the word.
- There are groups of vowels that usually produce fewer syllables if they occur together. For the purpose of our estimate, these groups are "au", "oa", "oo", and "iou". To make it simple, we subtract 1 from the syllable count for each occurrence of each of these vowel groups. (All occurrences count, even if they are a part of a bigger group of vowels.)
- Subtract 1 if the word ends in 'e'.
- Add 1 if the word ends in "le" and the previous letter exists and is a consonant.
- If the result is less than 1, set it to 1.
Return the number of syllables in the given W estimated using the above sequence of rules.
Definition
- Class:
- SyllableCountEstimator
- Method:
- estimate
- Parameters:
- String
- Returns:
- int
- Method signature:
- int estimate(String W)
- (be sure your method is public)
Constraints
- W will contain between 1 and 20 characters, inclusive.
- Each character in W will be a lowercase English letter ('a'-'z').
Examples
"potato"
Returns: 3
The string "potato" has three vowels ('o', 'a', 'o'). No other rules apply, so our estimate says it should have three syllables.
"haul"
Returns: 1
Two vowels, but we subtract 1 for the group "au".
"gooooooal"
Returns: 1
The groups of vowels may overlap. For example, this W contains five occurrences of "oo" and one occurrence of "oy". Thus, the answer is (7 vowels) minus (5 occurrences of "oo") minus (1 occurrence of "oa") = 1.
"rhythm"
Returns: 1
Our rules are not perfect. In actual English the word "rhythm" has two syllables, but our rules produce an incorrect estimate: According to rule #1, there are no 'a', 'e', 'i', 'o', 'u' in this W so the current number of syllables is 0. Rules #2, #3, #4 do not apply. In rule #5 we fix the number of syllables from 0 to 1, which is our final answer.
"e"
Returns: 1
The given W does not have to be a valid English word. When estimating the number of syllables for "e", we set it to 1 in rule #1, then decrease it to 0 in rule #3, and then increase it back to 1 in rule #5.
"le"
Returns: 1
"various"
Returns: 3
This W contains an occurrence of "iou".
"queued"
Returns: 4
Another case when our simple estimate doesn't match reality.
"qwertyuiopasdfghjkl"
Returns: 5
"participle"
Returns: 4
"ukulele"
Returns: 3
"worrier"
Returns: 3
"advocating"
Returns: 4
"unceasingly"
Returns: 4
"tomboy"
Returns: 2
"boyhoods"
Returns: 2
"conjurers"
Returns: 3
"uttermost"
Returns: 3
"larynxes"
Returns: 2
"conglomeration"
Returns: 6
"osiers"
Returns: 3
"abortionist"
Returns: 5
"wartime"
Returns: 2
"flagging"
Returns: 2
"weltering"
Returns: 3
"slaloms"
Returns: 2
"pilafs"
Returns: 2
"extradites"
Returns: 4
"indemnities"
Returns: 5
"nadir"
Returns: 2
"writhed"
Returns: 2
"payday"
Returns: 2
"veracious"
Returns: 4
"hyaenas"
Returns: 3
"induct"
Returns: 2
"awes"
Returns: 2
"minuting"
Returns: 3
"geed"
Returns: 2
"recluses"
Returns: 3
"fame"
Returns: 1
"shepherdess"
Returns: 3
"sealants"
Returns: 3
"carats"
Returns: 2
"bravely"
Returns: 2
"circumstanced"
Returns: 4
"dwarfism"
Returns: 2
"western"
Returns: 2
"bailed"
Returns: 3
"tat"
Returns: 1
"solenoid"
Returns: 4
"gap"
Returns: 1
"engross"
Returns: 2
"laborer"
Returns: 3
"stalwart"
Returns: 2
"somersaulting"
Returns: 4
"enfeebled"
Returns: 4
"stabler"
Returns: 2
"indorsed"
Returns: 3
"scorecards"
Returns: 3
"periodically"
Returns: 5
"overcrowds"
Returns: 3
"coated"
Returns: 2
"pinhole"
Returns: 2
"idle"
Returns: 2
"agreeable"
Returns: 5
"inalienable"
Returns: 6
"settable"
Returns: 3
"embezzle"
Returns: 3
"unable"
Returns: 3
"indictable"
Returns: 4
"quadrangle"
Returns: 4
"a"
Returns: 1
"y"
Returns: 1
"at"
Returns: 1
"to"
Returns: 1
"ex"
Returns: 1
"tt"
Returns: 1
"auoaaooiouuaoe"
Returns: 9
"ooooo"
Returns: 1
"yle"
Returns: 1
"ele"
Returns: 1
"asocla"
Returns: 3
"bc"
Returns: 1
"oooobbooo"
Returns: 2