fix: Unicode NFC-нормализация id лекций и фрагментов
macOS хранит имена каталогов в NFD, LLM печатают NFC — байтово разные строки выглядят одинаково, ломая идемпотентность (9 лекций числились неизвлечёнными). id корпуса нормализуются на входе, quote_check сравнивает в NFC, данные приведены одноразово. Реестр: 28 извлечено, 0 сирот, 41 осталась. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
+10
-3
@@ -13,6 +13,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
import unicodedata
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
from typing import Iterable, Iterator
|
||||
@@ -20,6 +21,12 @@ from typing import Iterable, Iterator
|
||||
from . import config
|
||||
|
||||
|
||||
def _nfc(s: str) -> str:
|
||||
"""macOS хранит имена каталогов в NFD («й» = «и»+◌̆), а LLM печатают NFC —
|
||||
строки выглядят одинаково, но байтово различны. Все id приводим к NFC."""
|
||||
return unicodedata.normalize("NFC", s)
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Transcript:
|
||||
id: str # человекочитаемый id (имя лекции)
|
||||
@@ -51,7 +58,7 @@ def iter_transcripts() -> Iterator[Transcript]:
|
||||
for seg in sorted(config.CORPUS_DIR.glob("*/transcript/segments.txt")):
|
||||
if seg.stat().st_size == 0 or _excluded(seg) or _is_stub(seg):
|
||||
continue
|
||||
yield Transcript(id=seg.parent.parent.name, source="mass", path=seg)
|
||||
yield Transcript(id=_nfc(seg.parent.parent.name), source="mass", path=seg)
|
||||
# Ручные разборы: ищем любые *segments*.txt внутри
|
||||
for d in config.MANUAL_DIRS:
|
||||
if not d.exists():
|
||||
@@ -59,7 +66,7 @@ def iter_transcripts() -> Iterator[Transcript]:
|
||||
for seg in sorted(d.rglob("*segments*.txt")):
|
||||
if seg.stat().st_size == 0 or _excluded(seg) or _is_stub(seg):
|
||||
continue
|
||||
yield Transcript(id=d.name, source="manual", path=seg)
|
||||
yield Transcript(id=_nfc(d.name), source="manual", path=seg)
|
||||
|
||||
|
||||
_NAT_SPLIT = re.compile(r"(\d+)")
|
||||
@@ -120,7 +127,7 @@ def expected_fragment_counts() -> dict[str, int]:
|
||||
# такой фрагмент не «ожидается» лекцией
|
||||
if seg.exists() and seg.stat().st_size > 0 and _is_stub(seg):
|
||||
continue
|
||||
pid = parent_lecture_id(d.name)
|
||||
pid = parent_lecture_id(_nfc(d.name))
|
||||
counts[pid] = counts.get(pid, 0) + 1
|
||||
return counts
|
||||
|
||||
|
||||
Reference in New Issue
Block a user