syllable module¶
- class inflex.syllable.Syllable[source]¶
Bases:
object
Class with Syllable information from Carnegie Mellon University’s cmudict.txt. This class provides several static methods which can be used to count the number of syllables of an input word. Another purpose is to find out whether the word ends with stress.
- static data() Dict[str, List[List[float]]] [source]¶
Lazy load syllable and stress data when requested.
Examples
>>> Stress.data() { "ab": [[1], [1, 1]], "ababa": [[0, 1, 0], [1, 0, 0]], "abacha": [[1, 0, 0]], ... }
- Returns
- The dictionary key is a regular word, which maps
to a list of syllable interpretations. Each interpretation is a list of stress values, where 1 means Primary stress, 0.5 means secondary stress, and 0 is unstressed.
- Return type
Dict[str, List[List[float]]]
- static get_stress(word: str) List[List[float]] [source]¶
Return a list of syllable interpretations that correspond to stress values, for word.
Examples
>>> Stress.get_stress("abdomen") [[0, 1, 0], [1, 0, 0]]
This shows that the word has two interpretations, both with 3 syllables. In the first interpretation, the second syllable has primary stress, while in the second interpretation, the first syllable has primary stress. The other syllables are unstressed.
- Parameters
word (str) – The input word.
- Returns
- A list of syllable interpretations that correspond to stress values,
for word.
- Return type
List[List[float]]
- static count_syllables(word: str) Set[int] [source]¶
Return the set of valid syllable counts of word.
Note
Some words have multiple valid syllable counts, like “abdomen”.
- Parameters
word (str) – The input word.
- Returns
The set of valid syllable counts of word.
- Return type
Set[int]
- static count_reduced_syllables(word: str) Set[int] [source]¶
Return the set of valid syllable counts of word, with “un” removed from the start.
- Parameters
word (str) – The input word.
- Returns
The set of valid syllable counts of word, but optionally with “un” removed from the start of word.
- Return type
Set[int]
- static ends_with_stress(word: str) bool [source]¶
Returns True if all syllable interpretations of word end with stress.
Note
Either primary or secondary stress is considered stress.
- Parameters
word (str) – The input word.
- Returns
- True if all syllable interpretations of word end with stress.
False otherwise.
- Return type
bool