Voynich Master Archive - Volume 02 - Pages 1001-2000
EVA token text
PDF page 798 of 1000. Catalog page range 1001-2000.
Extracted text
Voynich Complete Reproducibility Compendium - 2026-08-28 Page 1797
current: Page | None = None
label_block = 0
previous_was_label = False
for lineno, raw in enumerate(path.read_text(encoding='utf-8', errors='replace').splitlines(), 1):
m = PAGE_RE.match(raw)
if m:
current = pages.setdefault(m.group(1), Page(m.group(1)))
label_block = 0
previous_was_label = False
continue
if current is None:
continue
if raw.startswith('#'):
comment = raw[1:].strip()
current.comments.append(comment)
pm = PLANT_RE.search(comment)
if pm:
current.plant_id = pm.group(1).strip()
rm = REF_RE.search(comment)
if rm:
current.refs.append((rm.group(1), int(rm.group(2)) if rm.group(2) else None,
int(rm.group(3)) if rm.group(3) else None, comment))
previous_was_label = False
continue
if not raw.strip():
previous_was_label = False
continue
lm = LOCUS_RE.match(raw)
if not lm:
previous_was_label = False
continue
page, num, marker, typ, text = lm.groups()
toks = clean_tokens(text)
if typ == 'P':
current.paragraph_tokens.extend(toks)
previous_was_label = False
elif typ == 'L':
if not previous_was_label:
label_block += 1
for tok in toks:
current.labels.append(Label(tok, collapse(tok), f'{page}.{num}', lineno, label_block))
previous_was_label = True
else:
previous_was_label = False
return pages
def lev(a: str, b: str) -> int:
if len(a) < len(b):
a, b = b, a
prev = list(range(len(b) + 1))
for i, ca in enumerate(a, 1):
cur = [i]
for j, cb in enumerate(b, 1):
cur.append(min(cur[-1] + 1, prev[j] + 1, prev[j-1] + (ca != cb)))
prev = cur
return prev[-1]
def ndist(a: str, b: str) -> float:
return lev(a, b) / max(len(a), len(b), 1)
def candidate_labels(target: Page, row: int | None, col: int | None) -> tuple[list[Label], str]:
"""Use coordinates when they map cleanly; otherwise return the local block/all labels.
ZL's [r,c] notation is iconographic and is not uniform across foldouts. We
therefore never silently pretend an exact map: exact/block/all is recorded.
"""
if not target.labels:
return [], 'none'
blocks: dict[int, list[Label]] = defaultdict(list)
for lab in target.labels:
blocks[lab.block].append(lab)
if row is not None and row in blocks:
block = blocks[row]
if col is not None and 1 <= col <= len(block):
return [block[col-1]], 'exact-block-coordinate'
return block, 'row-block'
return target.labels, 'all-target-labels'
def page_match(label: str, tokens: list[str]) -> tuple[float, str, int, int]:
if not tokens:
return 1.0, '', 0, 0
ctoks = [collapse(t) for t in tokens]
ds = [(ndist(label, t), raw) for t, raw in zip(ctoks, tokens)]
ds.sort()
best_d, best_raw = ds[0]
threshold = max(1, round(len(label) * 0.25))
family = sum(lev(label, t) <= threshold for t in ctoks)
exact = sum(label == t for t in ctoks)
return best_d, best_raw, family, exact
def main() -> None: