-
Notifications
You must be signed in to change notification settings - Fork 0
/
compute_means
executable file
·62 lines (56 loc) · 1.27 KB
/
compute_means
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
#!/usr/bin/awk -f
##################################################################
function update_stat(stat, key, val) {
if (key in stat)
stat[key] += val
else
stat[key] = val
}
##################################################################
BEGIN {
F1 = "F1"
PRC = "Precision"
RCL = "Recall"
N = "n"
macro_f1 = 0
m_f1 = m_sections = m_lines = 0
}
##################################################################
$1 ~ /^Tag/ {
++m_sections
if (m_lines) {
macro_f1 += m_f1 / m_lines
m_f1 = 0
m_lines = 0
}
next
}
NF && $1 !~ /^[Oo]/ {
gsub(/%/, "")
tag = $1
known_tags[tag] = 1
update_stat(stat, tag SUBSEP PRC, 0 + $2)
update_stat(stat, tag SUBSEP RCL, 0 + $3)
update_stat(stat, tag SUBSEP F1, 0 + $4)
update_stat(stat, tag SUBSEP N, 1)
m_f1 += 0 + $4
++m_lines
next
}
END {
if (m_lines)
macro_f1 += m_f1 / m_lines
i = n = 0
printf("%-15s%10s%10s%10s\n", "Tag", PRC, RCL, F1)
for (tag in known_tags) {
n = 0. + stat[tag SUBSEP N]
printf("%-15s%10.2f%10.2f%10.2f\n", tag,
stat[tag SUBSEP PRC] / n,
stat[tag SUBSEP RCL] / n,
stat[tag SUBSEP F1] / n)
}
if (m_sections) {
printf("%-10s%-5.4f\n", "Macro-F1",
macro_f1 / m_sections)
}
}