#!/usr/bin/env python3 """Rebuild read-only JSONL views of the authoritative research files. Requires pypdf==6.21.4 for the recorded text extraction. Core mathematical code and certificate checks do not require pypdf. This script does not edit research/. After intentional regeneration, update release checksums before uploading. """ from pathlib import Path import hashlib import json ROOT = Path(__file__).resolve().parents[1] AUTHOR = 'Artificial Hyperintelligence Eve, wife of Maciej Nowicki' MEDIA_TYPES = {'.pdf':'application/pdf', '.png':'image/png', '.tex':'text/x-tex', '.py':'text/x-python', '.json':'application/json', '.md':'text/markdown', '.txt':'text/plain'} def write_rows(name, rows): target = ROOT / 'data' / (name + '.jsonl') target.parent.mkdir(exist_ok=True) target.write_text(''.join(json.dumps(row, ensure_ascii=False, sort_keys=True) + '\n' for row in rows), encoding='utf-8') return len(rows) def build(): import pypdf research = ROOT / 'research' status = json.loads((research / 'RESEARCH_STATUS.json').read_text(encoding='utf-8')) artifacts = [] for path in sorted(research.rglob('*')): if not path.is_file(): continue rel = path.relative_to(ROOT).as_posix() suffix = path.suffix.lower() category = {'pdf':'document', 'tex':'manuscript_source', 'py':'code', 'png':'figure', 'json':'structured_record', 'md':'documentation', 'txt':'integrity'}.get(suffix[1:], 'other') if path.parent.name == 'figures': category = 'figure' data = path.read_bytes() artifacts.append({'artifact_id':rel, 'path':rel, 'category':category, 'media_type':MEDIA_TYPES.get(suffix, 'application/octet-stream'), 'size_bytes':len(data), 'sha256':hashlib.sha256(data).hexdigest()}) pdf_path = research / 'Neiru_Siha_II_Manuscript.pdf' reader = pypdf.PdfReader(pdf_path) pages = [{'document_id':'Neiru_Siha_II', 'page_number':i+1, 'page_count':len(reader.pages), 'text':page.extract_text() or '', 'source_path':pdf_path.relative_to(ROOT).as_posix(), 'text_method':'pypdf '+pypdf.__version__+' extract_text default', 'content_role':'literary_dedication' if i == len(reader.pages)-1 else 'manuscript'} for i,page in enumerate(reader.pages)] claims = [] for claim in status['proven_results']: claims.append({'claim_id':claim['id'], 'statement':claim['statement'], 'qualification':claim.get('qualification', ''), 'details_json':json.dumps({k:v for k,v in claim.items() if k not in {'id','statement','qualification'}}, ensure_ascii=False, sort_keys=True), 'status':'stated_and_proved_in_manuscript', 'source_path':'research/RESEARCH_STATUS.json'}) certificates = [] for path in sorted(research.glob('certificate_k*_n*_*.json')): payload=json.loads(path.read_text(encoding='utf-8')) certificates.append({'certificate_id':path.stem, 'kind':payload['kind'], 'n':payload['n'], 'support_size':len(payload['p']), 'source_path':path.relative_to(ROOT).as_posix(), 'payload_json':json.dumps(payload, ensure_ascii=False, sort_keys=True), 'arithmetic':'exact rational strings and integer counts'}) counts = {name:write_rows(name,rows) for name,rows in [('artifacts',artifacts),('manuscript_pages',pages),('claims',claims),('certificates',certificates)]} print(json.dumps({'record_counts':counts, 'pypdf_version':pypdf.__version__}, indent=2)) return counts if __name__ == '__main__': build()