def check_poem(poem_lines, pattern, word_to_phonemes, form_name): """ (list of str, poetry pattern, pronunciation dictionary, str) -> NoneType Check whether the poem in poem_lines has the right number of lines to match for form given in pattern, and print a message if it doesn't. If it does, then check whether the lines in the poem have the right number of syllables and report the lines that don't; also check whether the lines of the poem have the correct rhyming scheme and report the lines that should rhyme but don't. """ if poetry_functions.count_lines(poem_lines) != len(pattern[0]): print("\n== The poem doesn't have the right number of lines. == \n") else: problem_lines = poetry_functions.check_syllables( poem_lines, pattern, word_to_phonemes) if len(problem_lines) == 0: print( '\nThe poem has the right number of syllables on each line.\n') else: print('\n== The poem is not a {}. These lines don\'t have the ' 'right number of syllables: == '.format(form_name)) print('\n'.join(problem_lines) + '\n') problem_rhymes = poetry_functions.check_rhyme_scheme( poem_lines, pattern, word_to_phonemes) if len(problem_rhymes) == 0: print('The poem follows the rhyme scheme.\n') else: print('\n== The poem is not a {}. These lines should rhyme' " but don't: ==".format(form_name)) for lines in problem_rhymes: print('\n'.join(lines) + '\n')
def check_poem(poem_lines, pattern, word_to_phonemes, form_name): """ (list of str, poetry pattern, pronunciation dictionary, str) -> NoneType Check whether the poem in poem_lines has the right number of lines to match for form given in pattern, and print a message if it doesn't. If it does, then check whether the lines in the poem have the right number of syllables and report the lines that don't; also check whether the lines of the poem have the correct rhyming scheme and report the lines that should rhyme but don't. """ if poetry_functions.count_lines(poem_lines) != len(pattern[0]): print("\n== The poem doesn't have the right number of lines. == \n") else: problem_lines = poetry_functions.check_syllables( poem_lines, pattern, word_to_phonemes) if len(problem_lines) == 0: print('\nThe poem has the right number of syllables on each line.\n') else: print('\n== The poem is not a {}. These lines don\'t have the ' 'right number of syllables: == '.format(form_name)) print('\n'.join(problem_lines) + '\n') problem_rhymes = poetry_functions.check_rhyme_scheme( poem_lines, pattern, word_to_phonemes) if len(problem_rhymes) == 0: print('The poem follows the rhyme scheme.\n') else: print('\n== The poem is not a {}. These lines should rhyme' " but don't: ==".format(form_name)) for lines in problem_rhymes: print('\n'.join(lines) + '\n')
'GAP': ['G', 'AE1', 'P'], 'BEFORE': ['B', 'IH0', 'F', 'AO1', 'R'], 'LEADS': ['L', 'IY1', 'D', 'Z'], 'WITH': ['W', 'IH1', 'DH'], 'LINE': ['L', 'AY1', 'N'], 'THEN': ['DH', 'EH1', 'N'], 'THE': ['DH', 'AH0'], 'A': ['AH0'], 'FIRST': ['F', 'ER1', 'S', 'T'], 'ENDS': ['EH1', 'N', 'D', 'Z'], 'POEM': ['P', 'OW1', 'AH0', 'M'], 'OFF': ['AO1', 'F'] } # Type check poetry_functions.check_rhyme_scheme result = poetry_functions.check_rhyme_scheme(poem_lines, pattern, word_to_phonemes) assert isinstance(result, list), \ '''poetry_functions.check_rhyme_scheme should return a list of list of str, but returned {0}.''' \ .format(type(result)) for item in result: assert isinstance(item, list), \ '''poetry_functions.check_rhyme_scheme should return a list of list of str, but returned a list of {0}.''' \ .format(type(item)) # Type check poetry_functions.check_syllables result = poetry_functions.check_syllables(poem_lines, pattern, word_to_phonemes) assert isinstance(result, list), \ '''poetry_functions.check_syllables should return a list, but returned {0}.''' \ .format(type(result))
word_to_phonemes = {'NEXT': ['N', 'EH1', 'K', 'S', 'T'], 'GAP': ['G', 'AE1', 'P'], 'BEFORE': ['B', 'IH0', 'F', 'AO1', 'R'], 'LEADS': ['L', 'IY1', 'D', 'Z'], 'WITH': ['W', 'IH1', 'DH'], 'LINE': ['L', 'AY1', 'N'], 'THEN': ['DH', 'EH1', 'N'], 'THE': ['DH', 'AH0'], 'A': ['AH0'], 'FIRST': ['F', 'ER1', 'S', 'T'], 'ENDS': ['EH1', 'N', 'D', 'Z'], 'POEM': ['P', 'OW1', 'AH0', 'M'], 'OFF': ['AO1', 'F']} # Type check poetry_functions.check_rhyme_scheme result = poetry_functions.check_rhyme_scheme(poem_lines, pattern, word_to_phonemes) assert isinstance(result, list), \ '''poetry_functions.check_rhyme_scheme should return a list of list of str, but returned {0}.''' \ .format(type(result)) for item in result: assert isinstance(item, list), \ '''poetry_functions.check_rhyme_scheme should return a list of list of str, but returned a list of {0}.''' \ .format(type(item)) # Type check poetry_functions.check_syllables result = poetry_functions.check_syllables(poem_lines, pattern, word_to_phonemes) assert isinstance(result, list), \ '''poetry_functions.check_syllables should return a list, but returned {0}.''' \ .format(type(result)) for item in result: