Запрос на слияние 'task' (#1) из task в master
This commit is contained in:
1 parent
3c4e8e6cee
commit
e3f6084527
19 files changed
+725
-115
No files matched your search
@@ -0,0 +1,33 @@
|
||||
"""Препроцессор: фильтрация пустого и слишком короткого текста."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from src.prepare.base_prepare import PreProcessor
|
||||
|
||||
DEFAULT_MIN_WORDS = 20
|
||||
|
||||
|
||||
class MinWordsPreProcessor(PreProcessor):
|
||||
"""Пропускает пустой текст и текст короче ``min_words`` слов.
|
||||
|
||||
Слова разделяются пробельными символами (``str.split``).
|
||||
|
||||
Args:
|
||||
min_words: Минимальное количество слов в тексте.
|
||||
Текст с меньшим числом слов отбрасывается.
|
||||
"""
|
||||
|
||||
def __init__(self, min_words: int = DEFAULT_MIN_WORDS) -> None:
|
||||
if min_words <= 0:
|
||||
raise ValueError("min_words должен быть положительным")
|
||||
|
||||
self._min_words = min_words
|
||||
|
||||
async def prepare(self, text: str, metadata: dict) -> str | None:
|
||||
if not text:
|
||||
return None
|
||||
|
||||
if len(text.split()) < self._min_words:
|
||||
return None
|
||||
|
||||
return text
|
||||
Reference in new issue
Block a user