def semi(pron): prim_stress_idx = pron_proc.stress_idx(pron, pron_proc.PRIMARY_STRESS) stress_pattern = pron_proc.stress(pron) # Look for (->) type semirhymes post_stress_sounds = pron[prim_stress_idx:] front_semirhymes = [] for word, phon in setup.ENTRIES: phon_prim_stress_idx = pron_proc.stress_idx(phon, pron_proc.PRIMARY_STRESS) phon_post_stress = phon[phon_prim_stress_idx:] if (post_stress_sounds == phon_post_stress[:len(post_stress_sounds)] and pron_proc.num_syllables(post_stress_sounds) == pron_proc.num_syllables(phon_post_stress) - 1): front_semirhymes.append( (word, phon, pron_proc.num_syllables(phon))) # (<-) type semirhymes back_semirhymes = [] # check if the stressed syllable is penultimate syllables = pron_proc.syllabify_helper(pron) for i in range(len(stress_pattern)): if stress_pattern[i] == pron_proc.PRIMARY_STRESS: stressed_syll_no_onset = list(syllables[i][1:]) stressed_syll_no_onset = [ phon for seg in stressed_syll_no_onset for phon in seg ] back_semirhymes.extend(match_sounds(stressed_syll_no_onset, pron)) break return front_semirhymes + back_semirhymes
def perfect(pron): # Locate stressed syllable, and declare sounds we want to match post_stress_sounds = pron[pron_proc.stress_idx(pron, pron_proc. PRIMARY_STRESS):] # Return tuples of words whose ending matches all sounds following # the stressed syllable return match_sounds(post_stress_sounds, pron)
def syllabic(pron): # Check if last syllable unstressed stress_pattern = pron_proc.stress(pron) if stress_pattern[-1] != pron_proc.UNSTRESSED: return [] # Locate unstressed syllable, and declare sounds we want to match final_syll = pron[pron_proc.stress_idx(pron, pron_proc.UNSTRESSED, len(stress_pattern) - 1):] # Return tuples of words whose ending matches all sounds following # the stressed syllable return match_sounds(final_syll, pron)
def near(pron): rhymes = [] # Find near rhymes using primary stress of given pron prim_sound_idx = pron_proc.stress_idx(pron, pron_proc.PRIMARY_STRESS) # Calculate initial unstressed index unstressed_sound_idx = pron_proc.stress_idx(pron, pron_proc.UNSTRESSED) # If primary stress is after unstressed if prim_sound_idx > unstressed_sound_idx: # Retrieve unstressed version of sounds to match post_stress_sounds = pron_proc.stressify(pron[prim_sound_idx:], pron_proc.UNSTRESSED) rhymes = rhymes + match_sounds(post_stress_sounds, pron) # Use only unstressed syllables after primary stress if exists if (len(post_stress_sounds) > 1): unstressed_sound_idx = pron_proc.stress_idx( post_stress_sounds[1:], pron_proc.UNSTRESSED) else: # Reset primary index to search for unstressed near rhymes below prim_sound_idx = 0 # If unstressed syllables do exist after primary stress or w/out primary # stress at all, find near rhymes using the unstressed syll. of given pron if unstressed_sound_idx > prim_sound_idx: # Retrieve stressed version of sounds to match post_stressless_sounds = pron[(prim_sound_idx + unstressed_sound_idx):] post_stressless_sounds = pron_proc.stressify(post_stressless_sounds, pron_proc.PRIMARY_STRESS) rhymes = rhymes + match_sounds(post_stressless_sounds, pron) return rhymes
def asson(pron): # Remove stress numbers from pronunciation nostress_pron = pron_proc.stressify(pron, pron_proc.EMPTY_STRESS) stress_pattern = pron_proc.stress(pron) # Extract vowel pattern - consider both with/without onset vowel_pattern = pron_proc.sound_pattern(nostress_pron, pron_proc.ARPABET_VOWELS) vowel_pattern_no_onset = vowel_pattern[ pron_proc.stress_idx(pron, stress_pattern[0]):] return ( match_pattern(vowel_pattern, pron_proc.ARPABET_VOWELS, pron) + match_pattern(vowel_pattern_no_onset, pron_proc.ARPABET_VOWELS, pron))