# -*- coding: utf-8 -*- """Merge deduplicado das fontes parciais → cache_dados/corpus_v16.jsonl (regra do projeto: dedup global por hash do texto; ordem determinística).""" import hashlib import json import os import sys RAIZ = "/home/z/my-project/khtst" DIR_P = os.path.join(RAIZ, "cache_dados", "_parcial") SAIDA = os.path.join(RAIZ, "cache_dados", "corpus_v16.jsonl") def _hash_texto(t: str) -> str: return hashlib.sha256((t or "").encode("utf-8")).hexdigest() def main() -> None: vistos, regs = set(), [] for nome in sorted(os.listdir(DIR_P)): if not nome.endswith(".jsonl"): continue with open(os.path.join(DIR_P, nome), encoding="utf-8") as f: for linha in f: try: r = json.loads(linha) except Exception: continue chave = _hash_texto(r.get("texto") or ((r.get("entrada") or "") + "␟" + (r.get("saida") or ""))) if chave and chave not in vistos: vistos.add(chave) regs.append(r) with open(SAIDA, "w", encoding="utf-8") as f: for r in regs: f.write(json.dumps(r, ensure_ascii=False) + "\n") tarefas = {} for r in regs: tarefas[r.get("tarefa")] = tarefas.get(r.get("tarefa"), 0) + 1 print(f"corpus final: {len(regs)} registros; por tarefa: {tarefas}") if __name__ == "__main__": main()