# decryption_complete: false # source: /Voynich/prepare_libro_audit_023.py # stated_sha256: 5f0a25e63706e80568f2b2bfe66053c1a9af77c2dc60329d1dfe89282264f3af # matches_stated_sha256: false # pdf_pages: 131-132 # note: The stated SHA-256 is the digest printed in the PDF. # The PDF page extract follows the form feed. decryption_complete stays false. prepare_libro_audit_023.py VOYNICH RESEARCH ARCHIVE | 16 SEPTEMBER 2026 1 prepare_libro_audit_023.py Source: /Voynich/prepare_libro_audit_023.py SHA-256: 5f0a25e63706e80568f2b2bfe66053c1a9af77c2dc60329d1dfe89282264f3af !/usr/bin/env python3 """Prepare the natural Libro corpus and a coverage-stratified 200-sentence audit ledger.""" import csv, hashlib, re from collections import Counter from pathlib import Path ROOT=Path(__file__).resolve().parent OUT=ROOT/'libro_voynich_manual_023';OUT.mkdir(exist_ok=True) TXT=ROOT/'tmp/pdfs/libro_direct/libro.txt' TAGS=('MOVE','SIGN','MEASURE','REPORT','MARVEL','ASSET') PAT={ 'MARVEL':r'marvellous|marvelous|miracle|magical virtues|secrets of the stars', 'SIGN':r'\b(device|flag|ensign|arms|coat of arms|for his sign)\b', 'MEASURE':r'\b\d+\s+(miles?|leagues?|days? journey|days?)\b|distance is|journey in length|journey in width', 'MOVE':r'\b(i departed|i left|i went|i returned|i entered|i arrived|i crossed|i travelled|on leaving|afterwards i departed)\b', 'REPORT':r'\b(they say|they told me|i was told|know that|it is said|they call|i heard|i enquired)\b'} PRIORITY=('MARVEL','SIGN','MEASURE','MOVE','REPORT') def clean_page(x): lines=[] for s in x.splitlines(): s=re.sub(r'\s+',' ',s).strip() if not s or re.fullmatch(r'[\d ivxlcdm,.-]+',s.lower()):continue if re.search(r'C\.\s*R\.\s*M\.|See Plate|PLATE [IVXLCDM]',s,re.I):continue lines.append(s) return ' '.join(lines) rows=[] for pageno,page in enumerate(TXT.read_text(errors='ignore').split('\f')[23:117],23): for j,s in enumerate(re.split(r'(?<=[.!?])\s+(?=[A-Z])',clean_page(page))): s=s.strip();wc=len(re.findall(r'\b\w+\b',s)) if not(7<=wc<=90) or re.search(r'Hakluyt|Jimenez|Espada|Markham|Franciscan shows|according to',s,re.I):continue labs=[t for t,p in PAT.items() if re.search(p,s,re.I)] if not labs:labs=['ASSET'] primary=next((t for t in PRIORITY if t in labs),'ASSET') suspicious=[] if len(labs)>1:suspicious.append('MULTI_FUNCTION') if s.count('I departed')+s.count('I left')+s.count('I went')>1:suspicious.append('MERGED_MOVES') if re.search(r'\b\d+\s*\)',s):suspicious.append('FOOTNOTE_JOIN') if s.count('(')!=s.count(')'):suspicious.append('UNBALANCED_PAREN') if len(s)>450:suspicious.append('LONG_OCR_UNIT') rows.append({'corpus_id':f'C-{len(rows)+1:04d}','page_index':pageno,'sentence_index':j,'word_count':wc , 'rule_labels':'|'.join(labs),'rule_primary':primary,'quality_flags':'|'.join(suspicious),'sentence':s }) Coverage-stratified audit: unique hash-ranked rows, 25 per explicit class, then fill to 200 corpus-wide. selected=[];used=set() def rank(r,salt):return hashlib.sha256((salt+'|'+r['corpus_id']).encode()).hexdigest() for tag in TAGS: pool=sorted([r for r in rows if tag in r['rule_labels'].split('|') and r['corpus_id'] not in used],key=lambda r:rank(r,'AUDIT-'+tag)) for r in pool[:25]:selected.append(r);used.add(r['corpus_id']) pool=sorted([r for r in rows if r['corpus_id'] not in used],key=lambda r:rank(r,'AUDIT-FILL')) for r in pool[:200-len(selected)]:selected.append(r);used.add(r['corpus_id']) with (OUT/'libro_full_natural_corpus.csv').open('w',newline='') as f: basefields=['corpus_id','page_index','sentence_index','word_count','rule_labels','rule_primary','qualit prepare_libro_audit_023.py VOYNICH RESEARCH ARCHIVE | 16 SEPTEMBER 2026 2 y_flags','sentence'] w=csv.DictWriter(f,fieldnames=basefields);w.writeheader();w.writerows(rows) selected=[dict(r) for r in selected] selected.sort(key=lambda r:(r['page_index'],r['sentence_index'])) for i,r in enumerate(selected,1): r['audit_id']=f'AUD-{i:03d}';r['audit_primary']=r['rule_primary'];r['audit_labels']=r['rule_labels'] r['audit_disposition']='REVIEW_REQUIRED' if r['quality_flags'] else 'ACCEPT_RULE' r['audit_note']='' fields=['audit_id','corpus_id','page_index','sentence_index','word_count','rule_labels','rule_primary',' quality_flags','audit_labels','audit_primary','audit_disposition','audit_note','sentence'] with (OUT/'libro_200_sentence_audit_ledger.csv').open('w',newline='') as f: w=csv.DictWriter(f,fieldnames=fields);w.writeheader();w.writerows(selected) print('corpus',len(rows),'primary',dict(Counter(r['rule_primary'] for r in rows))) print('audit',len(selected),'primary',dict(Counter(r['rule_primary'] for r in selected)),'review',sum(r['audit_disposition']=='REVIEW_REQUIRED' for r in selected))