"""TL-T1-53-SUSP · 05: selección del banco según prereg/BANCO_REGLA.md (f80cdce6) y fragmentos para la lectura a mano. Escribe priv/banco_sel.json.""" import json, gzip, re, hashlib, sys sys.path.insert(0, '/o/py') import extrae as E cas = {json.loads(l)['id']: json.loads(l) for l in open('/am/priv/casado.jsonl')} ext = [json.loads(l) for l in open('/o/priv/resol_ext.jsonl')] def anio(r): return int(r['fecha'][:4]) if r.get('fecha') else (int(r['numero'].split('/')[-1]) if r.get('numero') and r['numero'].split('/')[-1].isdigit() else None) U = [r for r in ext if r['acto'] == 'adjudicacion' and r['sentido'] in ('desestimacion', 'estimacion', 'estimacion_parcial') and cas.get(r['id'], {}).get('estado') == 'casada' and anio(r) in (2022, 2023, 2024)] N = {'tarcja': 14, 'tccsp': 12, 'tarccyl': 8, 'tacpa': 6} orden = lambda r: hashlib.md5(('t153-banco|' + r['id']).encode()).hexdigest() sel = {} for t in ('tccsp', 'tarccyl', 'tacpa'): sel[t] = sorted([r for r in U if r['tribunal'] == t], key=orden)[:N[t]] falta = sum(N[t] - len(sel[t]) for t in sel) sel['tarcja'] = sorted([r for r in U if r['tribunal'] == 'tarcja'], key=orden)[:N['tarcja'] + falta] json.dump({t: [r['id'] for r in v] for t, v in sel.items()}, open('/o/priv/banco_sel.json', 'w'), indent=1) print('universo', {t: sum(1 for r in U if r['tribunal'] == t) for t in N}, 'elegidos', {t: len(v) for t, v in sel.items()}) if len(sys.argv) > 1 and sys.argv[1] == 'fragmentos': k = 0 for t in ('tarcja', 'tccsp', 'tarccyl', 'tacpa'): for r in sel[t]: k += 1 x = re.sub(r'\s+', ' ', gzip.open(r['texto'], 'rt', encoding='utf-8', errors='replace').read()) m = E.RX_FUND.search(x); ant = x[:m.start()] if m and m.start() > 500 else x[:max(4000, len(x) * 2 // 5)] print(f"#### B{k:02d} {r['id']} | EXT I={r['I']} ({r['I_regla']}) R={r['R']} ({r['R_origen']}) L={r['L']} Lsf={r['L_sin_fecha']} amb={r['previa_ambigua']} lotes={r['lotes_impugnados']} fallo_lev={r['fallo_levanta']} tipos={r['susp_tipos']}") mc = re.search(r'Resoluci', x); print(' CAB:', x[mc.start():mc.start() + 260] if mc else x[:260]) n1 = n2 = 0 for p0, fr in E.frases(ant): if (E.RX_ENTRADA.search(fr) or E.RX_INTERP.search(fr) or E.RX_REQ.search(fr)) and n1 < 4: print(' INT:', fr[:300]); n1 += 1 elif E.RX_SUSP.search(fr) and n2 < 4: print(' SUS:', fr[:240]); n2 += 1