Spaces:
Running
Running
File size: 543 Bytes
729a1f7 6d2a17c 729a1f7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
import re
import unicodedata
from utils.logger import get_logger
logger = get_logger("COMMON", __name__)
def split_sentences(text: str):
return re.split(r"(?<=[\.\!\?])\s+", text.strip())
def slugify(value: str):
value = str(value)
value = unicodedata.normalize("NFKD", value).encode("ascii", "ignore").decode("ascii")
value = re.sub(r"[^\w\s-]", "", value).strip().lower()
return re.sub(r"[-\s]+", "-", value)
def trim_text(s: str, n: int):
s = s or ""
if len(s) <= n:
return s
return s[:n] + "…" |