"""Auditable local text preparation. Fetching a dataset is deliberately a notebook/user action.""" import argparse, hashlib, json, re from pathlib import Path CONTROL=re.compile(r'[\x00-\x08\x0b\x0c\x0e-\x1f]') # Baseline filters; they are not a legal/privacy guarantee. EMAIL=re.compile(r'\b[\w.+-]+@[\w.-]+\.[A-Za-z]{2,}\b') PHONE=re.compile(r'\b(?:\+?1[-. ]?)?(?:\(?\d{3}\)?[-. ]?){2}\d{4}\b') def clean(text): text=CONTROL.sub('',text).replace('\r\n','\n').replace('\r','\n') text=EMAIL.sub('[EMAIL_REDACTED]',text);text=PHONE.sub('[PHONE_REDACTED]',text) return '\n'.join(x.rstrip() for x in text.splitlines()).strip() def prepare(inp,out,minimum=80): seen=set(); stats={'read':0,'kept':0,'duplicates':0,'too_short':0};Path(out).parent.mkdir(parents=True,exist_ok=True) with open(out,'w',encoding='utf8') as dst: for line in Path(inp).open(encoding='utf8'): stats['read']+=1 try: raw=json.loads(line);text=clean(str(raw.get('text',''))) except json.JSONDecodeError: continue key=hashlib.sha256(text.encode()).hexdigest() if len(text)