From d8a0bb1a175736c11fef8e74be7feaf5eb1a9cc4 Mon Sep 17 00:00:00 2001 From: anor Date: Fri, 5 Jun 2026 00:50:56 +1000 Subject: [PATCH] =?UTF-8?q?fix:=20=D1=84=D0=B8=D0=BB=D1=8C=D1=82=D1=80=20?= =?UTF-8?q?=D1=82=D1=80=D0=B0=D0=BD=D1=81=D0=BA=D1=80=D0=B8=D0=BF=D1=82?= =?UTF-8?q?=D0=BE=D0=B2-=D0=BC=D0=B0=D1=80=D0=BA=D0=B5=D1=80=D0=BE=D0=B2?= =?UTF-8?q?=20(=D0=B4=D0=B5=D0=BC=D0=BE=20=D0=B1=D0=B5=D0=B7=20=D1=80?= =?UTF-8?q?=D0=B5=D1=87=D0=B8=20/=20=D0=B1=D0=B8=D1=82=D1=8B=D0=B5=20?= =?UTF-8?q?=D1=84=D0=B0=D0=B9=D0=BB=D1=8B)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 8 транскриптов корпуса — маркеры, не текст: пропускаются при итерации и не считаются «ожидаемыми» фрагментами лекций (иначе 6 лекций вечно частичные). Итог: 780 массовых, все 69 лекций полные. Co-Authored-By: Claude Opus 4.8 (1M context) --- rag/corpus.py | 26 +++++++++++++++++++++----- tests/test_corpus_lectures.py | 11 +++++++++++ 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/rag/corpus.py b/rag/corpus.py index 31d498e..010e867 100644 --- a/rag/corpus.py +++ b/rag/corpus.py @@ -34,12 +34,22 @@ def _excluded(p: Path) -> bool: return any(str(p).startswith(str(ex)) for ex in config.EXCLUDE_DIRS) +# Маркеры вместо текста: 6 демо без речи + 2 битых файла (см. PROJECT_STATUS +# «Состояние корпуса») — извлечение обязано их пропускать +_STUB_MARKERS = ("[нет распознанной", "[битый", "[БИТЫЙ") + + +def _is_stub(p: Path) -> bool: + with p.open(encoding="utf-8") as f: + return f.readline().lstrip().startswith(_STUB_MARKERS) + + def iter_transcripts() -> Iterator[Transcript]: """Все готовые транскрипты: массовый корпус + ручные разборы (кроме 811).""" # Массовый корпус: <лекция>/transcript/segments.txt if config.CORPUS_DIR.exists(): for seg in sorted(config.CORPUS_DIR.glob("*/transcript/segments.txt")): - if seg.stat().st_size == 0 or _excluded(seg): + 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) # Ручные разборы: ищем любые *segments*.txt внутри @@ -47,7 +57,7 @@ def iter_transcripts() -> Iterator[Transcript]: if not d.exists(): continue for seg in sorted(d.rglob("*segments*.txt")): - if seg.stat().st_size == 0 or _excluded(seg): + if seg.stat().st_size == 0 or _excluded(seg) or _is_stub(seg): continue yield Transcript(id=d.name, source="manual", path=seg) @@ -103,9 +113,15 @@ def expected_fragment_counts() -> dict[str, int]: counts: dict[str, int] = {} if config.CORPUS_DIR.exists(): for d in config.CORPUS_DIR.iterdir(): - if d.is_dir() and not d.name.startswith("_") and not _excluded(d): - pid = parent_lecture_id(d.name) - counts[pid] = counts.get(pid, 0) + 1 + if not d.is_dir() or d.name.startswith("_") or _excluded(d): + continue + seg = d / "transcript" / "segments.txt" + # маркер (демо без речи / битый) = обработан, текста не будет — + # такой фрагмент не «ожидается» лекцией + if seg.exists() and seg.stat().st_size > 0 and _is_stub(seg): + continue + pid = parent_lecture_id(d.name) + counts[pid] = counts.get(pid, 0) + 1 return counts diff --git a/tests/test_corpus_lectures.py b/tests/test_corpus_lectures.py index 0efbe64..1109b09 100644 --- a/tests/test_corpus_lectures.py +++ b/tests/test_corpus_lectures.py @@ -81,6 +81,17 @@ def test_lecture_partial_when_dirs_outnumber_transcripts(): assert lec.complete is False +def test_stub_transcripts_detected(tmp_path): + # 8 транскриптов корпуса — маркеры (демо без речи / битые), не текст + for marker in ("[нет распознанной речи]", "[битый файл]", "[БИТЫЙ ФАЙЛ]"): + p = tmp_path / f"{marker[1:4]}.txt" + p.write_text(f"{marker}\n", encoding="utf-8") + assert corpus._is_stub(p), marker + normal = tmp_path / "ok.txt" + normal.write_text("[00:01] обычный сегмент\n", encoding="utf-8") + assert not corpus._is_stub(normal) + + def test_lecture_complete_when_expected_unknown(): # без сведений с диска (ручные разборы, юнит-тесты) — полная по умолчанию lec = corpus.group_into_lectures([_t("_Романов_принцип")])[0]