def main(): word_to_phonemes = poetry_reader.read_pronunciation( open(DICTIONARY_FILENAME)) name_to_poetry_pattern = poetry_reader.read_poetry_form_descriptions( open(POETRY_FORMS_FILENAME)) menu, menu_dict = make_menu(name_to_poetry_pattern) print('=================================================') prompt = \ 'Enter number for poetry form to check (0 to quit):\n{}'.format(menu) form_num = input(prompt) while form_num != '' and form_num != '0': if form_num in menu_dict.keys(): form_name = menu_dict[form_num] poetry_pattern = name_to_poetry_pattern[form_name] poem_filename = get_valid_filename("Enter a poem filename: ") poem_file = open(poem_filename) poem = poem_file.read() poem_lines = poetry_functions.get_poem_lines(poem) check_poem(poem_lines, poetry_pattern, word_to_phonemes, form_name) print('=================================================') form_num = input(prompt) else: form_num = input('Invalid number. ' + prompt)
import poetry_functions as f import poetry_reader as r t1 = time.perf_counter() ## ##poem_lines = ['The first line leads off,', 'With a gap before the next.', 'Then the poem ends.'] ##pattern = ([5, 5, 4], ['*', '*', '*']) ##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']} ##poetry_functions.check_vowel_phoneme_counts(poem_lines, pattern, word_to_phonemes) ## a = open('/Users/lino/Desktop/University/Computer Science/108/a3/dictionary.txt') r.read_pronunciation(a) t2 = time.perf_counter() print('The code took {: .2f}ms'.format((t2 - t1) * 1000.))
'''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 checks for poetry_reader module # Type check poetry_reader.read_pronunciation try: file = open('dictionary.txt') except: assert False, '''place the pronunciation dictionary dictionary.txt ''' \ '''in the same folder as the typechecker''' result = poetry_reader.read_pronunciation(file) assert isinstance(result, dict), \ '''poetry_reader.read_pronunciation should return a dict ''' \ '''but returned {0}'''.format(type(result)) key = list(result.keys())[0] assert isinstance(key, str), \ '''poetry_reader.read_pronunciation should return a dict of ''' \ '''str: list of str, but has keys of type {0}.'''.format(type(key)) assert isinstance(result[key], list), \ '''poetry_reader.read_pronunciation should return a dict of ''' \ '''str: list of str, but has values of type {0}.''' \ .format(type(result[key])) for item in result[key]: assert isinstance(item, str), \ '''poetry_reader.read_pronunciation should return a dict of ''' \ '''str: list of str, but instead returned a dict of ''' \