"""Assignment 1."""

from assignment_1_eval import pairs

vowels = ['a', 'e', 'i', 'o', 'u']
es_sounds = ['ch', 's', 'z']
no_change = [
            'economics', 'mathematics', 'statistics', 'luggage',
            'baggage', 'furniture', 'information', 'gymnastics', 'news']
always_singular = ['fish', 'barracks', 'deer', 'sheep']


def pluralize(sg):
    """Return list of plural form(s) of input_word.

    Building this function is the purpose of Assignment 1.
    The most basic case is already provided.
    """
    # print('Enter word to be made plural: ')
    plurals = []
    if sg in no_change:
        plurals.append('')
    elif sg in always_singular:
        plurals.append(sg)
    elif sg == 'tooth':
        plurals.append('teeth')
    elif sg == 'goose':
        plurals.append('geese')
    elif sg == 'child':
        plurals.append('children')
    elif sg == 'foot':
        plurals.append('feet')
    elif sg == 'man':
        plurals.append('men')
    elif sg == 'woman':
        plurals.append('women')
    elif sg == 'person':
        plurals.append('people')
    elif sg == 'mouse':
        plurals.append('mice')
    elif sg == 'corpus':
        plurals.append(sg.replace(sg[-2:], 'ora'))
    elif sg == 'genus':
        plurals.append(sg.replace(sg[-2:], 'era'))
    elif sg.endswith('a'):
        plurals.append(sg + 'e')
        plurals.append(sg + 's')
    elif sg == 'crisis':
        plurals.append('crises')
    elif sg.endswith('us'):
        plurals.append(sg.replace(sg[-2:], 'i'))
        plurals.append(sg + 'es')
    elif sg.endswith('ex'):
        plurals.append(sg.replace(sg[-2:], 'ices'))
        plurals.append(sg + 'es')
    elif sg.endswith('x'):
        plurals.append(sg.replace(sg[-1], 'ces'))
        plurals.append(sg + 'es')
    elif sg.endswith('um'):
        plurals.append(sg.replace(sg[-2:], 'a'))
        plurals.append(sg + 's')
    elif sg.endswith('on'):
        plurals.append(sg.replace(sg[-2:], 'a'))
    elif sg.endswith('is'):
        plurals.append(sg.replace(sg[-2:], 'es'))
    elif sg.endswith('oo'):
        plurals.append(sg + 's')
    elif sg.endswith('o') and sg != 'auto':
        plurals.append(sg + 'es')
        plurals.append(sg + 's')
    elif sg.endswith('y') and sg[-2] in vowels:
        plurals.append(sg + 's')
    elif sg.endswith('y'):
        plurals.append(sg.replace(sg[-1], 'ies'))
    # NOTE I had to add parentheses to the following two lines to make the interpreter keep reading the next line.
    elif (sg.endswith(es_sounds[0]) or sg.endswith(es_sounds[1])
    or sg.endswith(es_sounds[2])):
        plurals.append(sg + 'es')
    elif sg.endswith('f'):
        plurals.append(sg.replace(sg[-1], 'ves'))
    elif sg.endswith('fe'):
        plurals.append(sg.replace(sg[-2:], 'ves'))
    else:
        plurals.append(sg + 's')
    return plurals


def singularize(sg):
    """Return list of plural form(s) of input_word.

    Building this function is the purpose of Assignment 1.
    The most basic case is already provided.
    """
    # print("Enter word to be made singular: ")

    plurals = []

    return plurals


def evaluate(pl_func=pluralize, pair_data=pairs):
    """Evaluate the performance of pluralize function based on pairs data.

    pl_func -- function that pluralizes input word (default=pluralize)
    pair_data -- list of 2-tuples: [(sg1, pl1), (sg2, pl2),...] (default=pairs)
    """
    total = len(pair_data)
    # Determine how many lexemes have more than one plural form.
    # duplicates = len(set([i for i, j in pair_data]))
    correct = 0
    for sg, pl in pair_data:
        predicted_pl = pl_func(sg)
        if pl == predicted_pl or pl in predicted_pl:
            correct += 1
            print('correct:', sg, predicted_pl, '({})'.format(pl), sep='\t')
        else:
            print('INcorrect:', sg, predicted_pl, '({})'.format(pl), sep='\t')
    print('Your score:', correct, '/', total, '{:.2%}'.format(correct / total))


evaluate()
