SyllableCounter
Takes a string and returns the number of syllables.
Installation
Add this line to your application's Gemfile:
gem 'syllable_counter'
And then execute:
$ bundle
Or install it yourself as:
$ gem install syllable_counter
Usage
To get the number of syllables for a string:
SyllableCounter::Count.get_syllables("Text to be evaluated goes here")
#=> 10
Algorithm
The algorithm is not corpus-based but based upon phonemic complementary distributions as they exist in American English. This is an introductory set that will keep growing. Suggestions for additions are absolutely welcome! Email me at [email protected].
- Assumes at least one obligatory vowel per syllable
- Final /e/ is not realized unless the final /e/ is preceded by an /l/ or /r/ and a consonant (ie. -dle, -cre).
- Final /ed/ suffix is only realized when preceeded by a /t/ or /d/
- Final /es/ plural suffix is realized after /s/ /z/ /sh/ /dg/ /ch/ /[aeiou]g/
- Two consecutive vowels outside of /[aeiouy]o/ are combined as one syllable
Pending
- /[aeiuy]o/ does not get merged as one syllable (ie. aon, ion, eon)
- /iu/ combinations are two syllables
- Exceptions: "maybe", "Wednesday"
- Dialect-specific versions for English
Contributing
Submit a pull request! The code is structured so that you can easily add a rule or an exception and specs. If the PR hasn't been addressed, feel free to ping me.