<filename>components/utils/agg_morph_results.py
import sys
import pandas as pd

def read_morph_agg_file(fn):
    acc_case = {'mlp_2018': {}, 'rnn_soft': {}, 'rnn_hard':{}}
    acc_nocase = {'mlp_2018': {}, 'rnn_soft':{}, 'rnn_hard':{}}

    with open(fn) as aggfh:

        for line in aggfh:
            items = line.strip().split()
            model_info = items[0].split('/')[2].split('_')
            model_type = '_'.join(model_info[1:3])[:8]
            seed = model_info[-1]

            score = float(items[-1])
            score_type = items[-2][:-1]
            if score_type == 'accuracy':
                acc_case[model_type][seed] = score
            else:
                assert score_type == 'case)'
                acc_nocase[model_type][seed] = score

    for k,v in acc_case.items():
        assert len(v.values()) == 10

    for k,v in acc_nocase.items():
        assert len(v.values()) == 10

    return acc_case, acc_nocase

def main():

    scores_agg_txt_fn = sys.argv[1]

    acc, acc_nocase = read_morph_agg_file(scores_agg_txt_fn)

    for model, seed_specific_scores in acc.items():
        print('Scores for model: %s' % model)
        nocase_scores = acc_nocase[model]

        seeds = []
        accs = []
        accs_nocase = []

        for s, a in seed_specific_scores.items():
            seeds.append(s)
            accs.append(a)
            accs_nocase.append(nocase_scores[s])

        df_data = {'seeds': seeds,
                   'Acc': accs,
                   'Acc_nocase': accs_nocase
                   }

        df = pd.DataFrame.from_dict(df_data)
        print(df)
        print(df.describe())
        print('\n')

if __name__ == '__main__':
    main()