示例#1
0
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)
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)
示例#3
0
    raise Exception("You must not call built-in function input!")


builtins.print = disable_print
builtins.input = disable_input

import poetry_functions

# Type check poetry_functions.count_lines
result = poetry_functions.count_lines(['First line;\n', '\n', 'last line\n'])
assert isinstance(result, int), \
       '''poetry_functions.count_lines should return an int, but returned {0}
       .'''.format(type(result))

# Type check poetry_functions.get_poem_lines
result = poetry_functions.get_poem_lines('One,\ntwo,\nthree.\n')
assert isinstance(result, list), \
       '''poetry_functions.get_poem_lines should return a list, but returned {0}.''' \
       .format(type(result))
for item in result:
    assert isinstance(item, str), \
       '''poetry_functions.get_poem_lines should return a list of str,
        but returned a list of {0}.''' \
       .format(type(item))

# Set-up for the next two type checks.
poem_lines = [
    'The first line leads off,', 'With a gap before the next.',
    'Then the poem ends.'
]
pattern = ([5, 7, 5], ['A', 'B', 'A'])
    raise Exception("You must not call built-in function input!")

builtins.print = disable_print
builtins.input = disable_input


import poetry_functions

# Type check poetry_functions.count_lines
result = poetry_functions.count_lines(['First line;\n', '\n', 'last line\n'])
assert isinstance(result, int), \
       '''poetry_functions.count_lines should return an int, but returned {0}
       .'''.format(type(result))

# Type check poetry_functions.get_poem_lines
result = poetry_functions.get_poem_lines('One,\ntwo,\nthree.\n')
assert isinstance(result, list), \
       '''poetry_functions.get_poem_lines should return a list, but returned {0}.''' \
       .format(type(result))
for item in result:
    assert isinstance(item, str), \
       '''poetry_functions.get_poem_lines should return a list of str,
        but returned a list of {0}.''' \
       .format(type(item))

# Set-up for the next two type checks.
poem_lines = ['The first line leads off,', 'With a gap before the next.', 'Then the poem ends.']
pattern = ([5, 7, 5], ['A', 'B', 'A'])
word_to_phonemes = {'NEXT': ['N', 'EH1', 'K', 'S', 'T'],
                    'GAP': ['G', 'AE1', 'P'],
                    'BEFORE': ['B', 'IH0', 'F', 'AO1', 'R'],