feat(chunks): ottimizzazione chunking e post-processing
- chunker.py: scrive meta.json con strategia e soglie effettive (target,
min_chars, max_chars) per ogni documento chunked
- verify_chunks.py:
* _load_thresholds(): legge min/max da meta.json invece del TARGET_CHARS
globale, eliminando il mismatch tra soglie chunker e verify
(h3_aware target=600 -> range 450-750, non piu' validato a 225-375)
* _ROMAN_END: esclude numeri romani finali (XV, XIV...) dagli incompleti
perche' sono artefatti indice PDF, non frasi spezzate
* PUNCT_END: aggiunge ; come fine valida (clausole legali italiane)
- fix_chunks.py:
* _load_thresholds(): usa max_chars da meta.json per split coerente
* _SECONDARY_END: split secondario su ; per testo legale multi-clausola
* Fase 1 (convergenza): risolve solo blockers (incomplete, empty,
no_prefix) senza toccare warnings -- elimina il ciclo
merge->too_long->split->incomplete->merge
* Fase 2 (finale): una sola passata di merge too_short + split too_long
dopo che i blockers sono azzerati
Risultato su dirittopenale: da blocked (265 incomplete) a warnings_only
in 2 iterazioni, senza cicli infiniti.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -439,6 +439,12 @@ def process_stem(stem: str, project_root: Path, force: bool) -> bool:
|
||||
lower = int(target * (1 - tolerance))
|
||||
upper = int(target * (1 + tolerance))
|
||||
|
||||
meta = {"strategy": strategia, "target_chars": target,
|
||||
"min_chars": lower, "max_chars": upper}
|
||||
(out_dir / "meta.json").write_text(
|
||||
json.dumps(meta, ensure_ascii=False), encoding="utf-8"
|
||||
)
|
||||
|
||||
lengths = [c["n_chars"] for c in chunks]
|
||||
min_c = min(lengths)
|
||||
max_c = max(lengths)
|
||||
|
||||
Reference in New Issue
Block a user