-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathconllu-eval.py
65 lines (52 loc) · 1.45 KB
/
conllu-eval.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import sys ;
if len(sys.argv) != 3: #{
print('conllu-eval.py <ref file> <tst file>');
sys.exit(-1);
#}
ref = open(sys.argv[1]);
tst = open(sys.argv[2]);
total = 0.0;
uas_correct = 0.0;
las_correct = 0.0;
uas_errors = 0.0;
las_errors = 0.0;
while True: #{
ref_l = ref.readline();
tst_l = tst.readline();
if ref_l == '' and tst_l == '': #{
break;
#}
if ref_l == '\n' and tst_l == '\n': #{
continue;
#}
ref_r = ref_l.split('\t');
tst_r = tst_l.split('\t');
if ref_r[0].count('-') > 0 and tst_r[0].count('-') > 0: #{
ref_l = ref.readline();
ref_r = ref_l.split('\t');
tst_l = tst.readline();
tst_r = tst_l.split('\t');
elif ref_r[0].count('-') > 0 and tst_r[0].count('-') == 0: #{
ref_l = ref.readline();
ref_r = ref_l.split('\t');
#}
if ref_r[1] != tst_r[1]: #{
print('ERROR: Unaligned', file=sys.stderr);
print('REF:', ref_r, file=sys.stderr);
print('TST:', tst_r, file=sys.stderr);
break;
#}
if ref_r[1] == tst_r[1] and ref_r[6] == tst_r[6]: #{
uas_correct = uas_correct + 1.0;
elif ref_r[1] == tst_r[1] and ref_r[6] != tst_r[6]: #{
uas_errors = uas_errors + 1.0;
#}
if ref_r[1] == tst_r[1] and ref_r[6] == tst_r[6] and ref_r[7] == tst_r[7]: #{
las_correct = las_correct + 1.0;
elif ref_r[1] == tst_r[1] and (ref_r[6] != tst_r[6] or ref_r[7] != tst_r[7]): #{
las_errors = las_errors + 1.0;
#}
total = total + 1.0
#}
print('UAS: %.2f' % (uas_correct/total*100.0));
print('LAS: %.2f' % (las_correct/total*100.0));