File size: 1,022 Bytes
04782c0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
"""Instrument check: family rules against hand labels.

usage: labelcheck.py LABEL_META.jsonl labels.tsv
LABEL_META.jsonl is fetch.py output for the ids in labels.tsv (columns n, id, hand_label, rule_family). Reads only;
writes nothing. Reports rule-vs-hand agreement and any row whose stored rule_family differs from the current rules."""
import sys, os, json
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
import classify

if len(sys.argv) < 3:
    sys.exit(__doc__)
meta = {}
for l in open(sys.argv[1]):
    if l.strip():
        d = json.loads(l); meta[d["id"]] = d
rows = [l.rstrip("\n").split("\t") for l in open(sys.argv[2])][1:]
ok = stale = 0
for n, i, hand, stored, *_ in rows:
    f = classify.family(meta[i]); ok += f == hand
    if f != hand: print("miss", n, i, "hand", hand, "rule", f)
    if f != stored: stale += 1; print("stale rule_family", n, i, "stored", stored, "now", f)
print(f"agree {ok}/{len(rows)} = {ok/len(rows):.1%} (rule needed 85%); stale stored rule_family rows: {stale}")