Professional Documents
Culture Documents
Assignment 5
Assignment 5
# Sample documents
documents = [
"This is the first document.",
"This document is the second document.",
"And this is the third one.",
"Is this the first document?"
]
nltk.download('cmudict')
def get_rhymes(word):
pronouncing_dict = cmudict.dict()
# Extract the rhyming part of the pronunciation (from the stressed vowel to the end)
rhyming_part = pronunciation[pronunciation.index('1'):]
# Find words that have the same rhyming part in the pronunciation dictionary
rhymes = [w for w, pron in pronouncing_dict.items() if pron[-len(rhyming_part):] ==
rhyming_part]
return rhymes
else:
return []
# Example usage
word_to_rhyme = "cat"
rhymes = get_rhymes(word_to_rhyme)
if rhymes:
print(f"Rhymes for '{word_to_rhyme}':")
print(rhymes)
else:
print(f"No rhymes found for '{word_to_rhyme}'.")