File size: 1,222 Bytes
24aaa76 | 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 | """Self-test of data.load_mix on three plausible layouts of mix_v1.yaml (written to DATA/tmp). Prints the flattened shares."""
import os
import sys
from . import data as D
from .common import DATA
TMP = DATA + "/tmp/mix_selftest"
os.makedirs(TMP, exist_ok=True)
A = """components:
- name: kohtd
manifest: /x/kohtd_train.tsv
share: 0.35
- name: other_cyr
share: 0.15
members:
- {manifest: /x/hkr_train.tsv}
- {manifest: /x/chd_train.tsv}
- {manifest: /x/school_train.tsv}
- name: hand_synth
share: 0.35
manifests: [/x/s1.tsv, /x/s2.tsv]
- name: typed
manifest: /x/typed.tsv
share: 0.12
filter: {kind: typed_synth}
- name: clutter
manifest: /x/clutter.tsv
share: 0.03
"""
B = """sources:
kohtd: {path: /x/kohtd_train.tsv, weight: 35}
hkr: {path: /x/hkr_train.tsv, weight: 15}
"""
C = """- manifest: /x/a.tsv
share: 0.5
- manifest: /x/b.tsv
share: 0.5
"""
for nm, txt in (("A", A), ("B", B), ("C", C)):
p = "%s/mix_%s.yaml" % (TMP, nm)
open(p, "w").write(txt)
r = D.load_mix(p)
print(nm, [(c["name"], os.path.basename(c["manifest"]), round(c["share"], 4), c["filter"]) for c in r], "sum", round(sum(c["share"] for c in r), 6))
|