You're tasked with writing a program that syllabifies words in a string of text, by separating them with a hyphen. That would be a lot of work, so you want to skip some parts, mainly because you don't want to have a table of the pronunciations required for perfect algorithm. You also want to make it as short (and thus unreadable and unmaintainable) as possible as a revenge for being given this assignment.
You have two choices:
- Write a program that takes the string from STDIN and outputs the result to STDOUT.
- Write a function that takes the string as a single parameter, and returns the result.
- In this case, string means any string-like construct in your language of choice (byte arrays, character arrays, strings...).
- Vowels are
a, e, i, o, u
- The string given has
1 <= n <= 10words, where each has a length between
1 - 30characters, inclusive.. Your output should be those words hyphenated.
- All letters are lowercase and words are always separated with spaces. Thus, the input consists of characters
- Apply rules in order of importance.
- When a word is divided, start again with the right half of the word.
Rules for syllabification, in order of importance
Two consecutive same vowels count as one (ie.
feet has only one vowel, but
finding have two). Every syllable has exactly one vowel, thus there is one syllable for each vowel.
- If the whole word has only four letters, return it unchanged. (skip this for the rest of the word)
- If the word has only one vowel, return the word unchanged.
- If the word has two consecutive vowels, divide between them (ie.
- When two or more consonants come between two vowels (same or different), divide after the first consonant (ie.
sis-ter) unless the consonant part is
ck, in which case divide the word after it. (ie.
- When a
ycomes between two vowels, divide the word after it (e.g.
- When one consonant comes between two vowels (same or different), divide before the consonant (ie.
- Return the word unchanged if no division could be done.
I chose these rules, because they can be applied recursively without problems and require no pronunciation tables. Thus, they are not accurate, and for example rule #5 is often not correct. In general case though, it is.
In: hello world Out: hel-lo world In: have a nice day Out: have a nice day In: pour some nickel and xenon there Out: pour some nick-el and xe-non the-re