#!/usr/bin/env python3

# FORMAT
# INSTITUTION-NAME_TASK-NAME_METHOD-NAME_TYPE
# INSTITUTION-NAME: Short identifier, e.g. SHEF
# TASK-NAME: 1: translation, 2: description, 3: both
# METHOD-NAME: NeuralTranslation, Moses, etc.
# TYPE: C: Constrained, U: Unconstrained

# SHEF_2_Moses_C: SHEF, description task, Moses system, Constrained

import argparse

if __name__ == '__main__':
    parser = argparse.ArgumentParser(prog='mmt-prep-submission')
    parser.add_argument('-T', '--task', type=str, required=True,
                        help='1 (translation), 2 (description) or 3 (both).')
    parser.add_argument('-t', '--type', type=str, default='C',
                        help='C(onstrained) or U(nconstrained)')
    parser.add_argument('-i', '--imgfile', type=str, required=True,
                        help='.txt file for image list in the split')
    parser.add_argument('-H', '--hypfile', type=str, required=True,
                        help='Hypothesis file')
    parser.add_argument('-m', '--method', type=str, required=True,
                        help='Method name')
    parser.add_argument('-I', '--instname', type=str, required=True,
                        help='Institution name')
    args = parser.parse_args()

    print('Institution name:', args.instname)
    print('Task name:', args.task)
    print('Method name:', args.method)
    print('Type:', args.type)

    # Open image files
    with open(args.imgfile) as fi:
        images = fi.read().strip().split("\n")

    with open(args.hypfile) as fh:
        hyps = fh.read().strip().split("\n")

    assert len(images) == len(hyps), "Number of images != number of sents"

    # INSTITUTION-NAME_TASK-NAME_METHOD-NAME_TYPE, where:
    out_file = '{}_{}_{}_{}'.format(
        args.instname, args.task, args.method, args.type)

    with open(out_file, 'w') as f:
        for img, hyp in zip(images, hyps):
            f.write('{}\t{}\t{}\t{}\t{}\n'.format(
                args.method, img, hyp, args.task, args.type))
