src.ch08 package

Submodules

src.ch08.p1_count_syllables module

Test count_syllables with a word dictionary file.

Randomly select words from a word dictionary file and pass them through count_syllables() to find their syllable counts. Output each word with their respective syllable count.

src.ch08.p1_count_syllables.CMUDICT

Dictionary of CMUdict’s phonemes with the word as a key and its phonemes as a list of lists.

Type

dict

src.ch08.p1_count_syllables.MISSING_WORDS

Dictionary with syllable counts of words missing from CMUdict’s phoneme list where the word is the key and its syllable count as an integer value.

Type

dict

src.ch08.p1_count_syllables.count_syllables(words: list) → int[source]

Use CMUdict to count syllables in English word.

Calculate sum of syllable counts for each word in words. Checks syllable counts in the nltk.corpus CMUdict phoneme list, if word is not found in CMUdict, also checks local dictionary with syllable counts.

Parameters

words (list) – List of strings to sum number of syllables.

Returns

Integer representing number of syllables in words.

Note

Defaults to first element in CMUdict phoneme list. So, multiple syllable counts are ignored.

src.ch08.p1_count_syllables.format_words(words: str) → list[source]

Format words for processing.

Remove hyphens, convert to lowercase, and strip both punctuation and possessives from word or phrase.

Parameters

words (str) – Word or phrase to format for processing.

Returns

List of strings containing processed words.

src.ch08.p1_count_syllables.main()[source]

Demonstrate count_syllables with a word dictionary file.

Module contents

Chapter 8.