Voynich Master Archive - Volume 07 - Pages 6001-7000
Test CSV, JSON, and Markdown records. Sections carry a Source path and a SHA-256 line.
PDF page 131 of 1000. Catalog page range 6001-7000.
Extracted text
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