-
Notifications
You must be signed in to change notification settings - Fork 57
/
mmt-prep-submission
executable file
·51 lines (41 loc) · 1.94 KB
/
mmt-prep-submission
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/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))