Syllable counting for English words.
Uses a vowel-group heuristic with a small table of known
exceptions. This is the same family of algorithm used by Python's
textstat and is accurate enough (~90%) for the readability
metrics in Text.Readability. For exact hyphenation points or
precise syllable boundaries, prefer Text.Hyphenation, which uses
Liang's algorithm with TeX hyphenation patterns.
Only English (:en) is supported at the moment. Other languages
will raise ArgumentError. Multilingual support will arrive when
Text.Hyphenation lands and this module can defer to its
pattern-based syllable boundaries.
Summary
Functions
Returns the number of syllables in an English word.
Returns the total syllable count for a sentence or longer text.
Functions
@spec count( String.t(), keyword() ) :: non_neg_integer()
Returns the number of syllables in an English word.
Arguments
wordis an English word as a string. Leading and trailing non-letter characters are stripped before counting.
Options
:languageis the language of the word. The default is:en. Only:enis supported; other values raiseArgumentError.
Returns
- A non-negative integer count of syllables. Returns
0for an empty string or a token containing no letters.
Examples
iex> Text.Syllable.count("syllable")
3
iex> Text.Syllable.count("hello")
2
iex> Text.Syllable.count("queue")
1
iex> Text.Syllable.count("rhythm")
1
iex> Text.Syllable.count("")
0
@spec count_text( String.t(), keyword() ) :: non_neg_integer()
Returns the total syllable count for a sentence or longer text.
Splits on whitespace and sums the syllable count of each token.
Arguments
textis a string containing zero or more words.
Options
:languageis the language of the text. The default is:en.
Returns
- A non-negative integer total syllable count across all tokens.
Examples
iex> Text.Syllable.count_text("the quick brown fox")
4
iex> Text.Syllable.count_text("")
0