fix: фильтр транскриптов-маркеров (демо без речи / битые файлы)
8 транскриптов корпуса — маркеры, не текст: пропускаются при итерации и не считаются «ожидаемыми» фрагментами лекций (иначе 6 лекций вечно частичные). Итог: 780 массовых, все 69 лекций полные. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
+21
-5
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user