-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathextract_output_for_path_k.py
50 lines (39 loc) · 1.36 KB
/
extract_output_for_path_k.py
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
name = "k_path_large-epochbest-k5"
flag = False
d = {}
with open(f"output/{name}.out") as f:
line = f.readline()
while line:
if line[0].isdigit():
if flag:
break
else:
line = f.readline()
continue
flag = True
src = line.strip().split('\t')[1]
ref = f.readline().strip().split('\t')[1]
score = float(f.readline().strip().split('\t')[1])
sys = f.readline().strip().split('\t')[2]
xs = src.split(";")
x = xs[0].strip()
y = xs[-1].split(":")[-1].strip()
p = (x,y)
if p not in d:
d[p] = {"src": src, "ref": ref, "sys": sys, "score": score, "count": 1}
else:
if score > d[p]["score"]:
d[p]["src"] = src
d[p]["sys"] = sys
d[p]["score"] = score
d[p]["count"] += 1
f.readline()
line = f.readline()
with open("input/shortest_path/test.src") as f, open(f"output/{name}.out.ref", 'w') as f1, open(f"output/{name}.out.sys", 'w') as f2:
for line in f:
xs = line.strip().split(';')
x = xs[0].strip()
y = xs[-1].split(":")[-1].strip()
d_ = d[(x,y)]
print(d_["ref"], file=f1)
print(d_["sys"], file=f2)