"""Integrate the self-licensed gardening notes (1988-89 garden journal) into polocrbench-train-pool-v1 (handwriting-gardnotes source). License holder: Piotr Styła (declared CC BY 4.0, 2026-10-23). Content: handwritten garden journal on yellowed paper (weather table, plant and variety lists with pencil/pen strike-outs, transplanting and fertilizing log). Some pages cut at edges ([ucięte]); struck text excluded per benchmark convention ([skreślone] marker). One re-scan pair (Scan_0012 / Scan_0017 = same source page, different crops) is kept deliberately as rescanning variety. No personal identifiers found (deterministic PII scan). """ import collections import hashlib import json import shutil from pathlib import Path BASE = Path('C:/Users/Hipek/OCR_external_data') WORK = BASE / 'skany-antoni-work' POOL = BASE / 'polocrbench-train-pool-v1' RESCAN_PAIR = {'Scan_0012 (1)', 'Scan_0017 (1)'} def sha(data): return hashlib.sha256(data).hexdigest() def main(): trans = {} for line in (WORK / 'transcriptions.jsonl').read_text(encoding='utf-8').splitlines(): row = json.loads(line) trans[row['page_id']] = row['text'] originals = {p.stem: sha(p.read_bytes()) for p in (WORK / 'originals').glob('*.jpg')} assert len(trans) == 10 rows = [] for stem in sorted(trans): src = WORK / 'pages' / f'{stem}.jpg' pool_id = 'hwgard_' + stem.lower().replace(' ', '_').replace('(', '').replace(')', '') data = src.read_bytes() shutil.copyfile(src, POOL / 'images' / f'{pool_id}.jpg') rows.append({'id': pool_id, 'source': 'handwriting-gardnotes', 'source_ref': 'self-licensed garden journal 1988-89 ' '(license holder: Piotr Styła, CC BY 4.0, 2026-10-23)', 'image': f'images/{pool_id}.jpg', 'image_sha256': sha(data), 'text': trans[stem], 'text_sha256': sha(trans[stem].encode()), 'width': 700, 'height': 1000, 'split': 'train', 'license': 'cc-by-4.0', 'human_verified': False, 'gold': False, 'page_fragment': True, 'rescan_group': 'rescan-pair-1' if stem in RESCAN_PAIR else None, 'original_image_sha256': originals.get(stem), 'transcription': 'ai-preannotation-cut-markers'}) manifest_path = POOL / 'manifest.jsonl' existing = manifest_path.read_text(encoding='utf-8') manifest_path.write_text(existing + ''.join( json.dumps(r, ensure_ascii=False) + '\n' for r in rows), encoding='utf-8') report = json.loads((POOL / 'report.json').read_text(encoding='utf-8')) all_rows = [json.loads(s) for s in manifest_path.read_text(encoding='utf-8').splitlines()] report['schema'] = 'polocrbench-train-pool-v1.5' report['pages'] = len(all_rows) report['by_source'] = dict(collections.Counter(r['source'] for r in all_rows)) report['by_split'] = dict(collections.Counter(r['split'] for r in all_rows)) report['handwriting_gardnotes_pages'] = len(rows) report['handwriting_gardnotes_license'] = 'CC BY 4.0 (license holder: Piotr Styła)' report['handwriting_gardnotes_content'] = ('garden journal 1988-89 on yellowed paper; ' 'plant/variety lists with strike-outs, weather ' 'table, gardening log; one re-scan pair kept ' 'as rescanning variety (rescan_group field)') report['licenses']['handwriting-gardnotes'] = 'CC BY 4.0 (license holder: Piotr Styła)' (POOL / 'report.json').write_text(json.dumps(report, ensure_ascii=False, indent=2), encoding='utf-8') sums = {p.relative_to(POOL).as_posix(): sha(p.read_bytes()) for p in sorted(POOL.rglob('*')) if p.is_file() and p.name != 'checksums.json'} (POOL / 'checksums.json').write_text(json.dumps(sums, indent=2), encoding='utf-8') print(json.dumps({'gardnotes_rows': len(rows), 'pool_pages': len(all_rows), 'by_source': report['by_source'], 'checksum_entries': len(sums)}, ensure_ascii=False, indent=2)) if __name__ == '__main__': main()