16 lines
519 B
Python
16 lines
519 B
Python
"""Adaptive RAG shared lightweight text helpers."""
|
||
from __future__ import annotations
|
||
|
||
from .shared_imports import *
|
||
from .shared_utils import *
|
||
|
||
_LOOKUP_TRIM_CHARS = " \t\r\n,。,.!??::;;“”\"'()()[]【】<>《》`"
|
||
|
||
|
||
def normalize_lookup_fragment(value: Any, *, keep_spaces: bool = False, limit: int = 32) -> str:
|
||
text = str(value or "")
|
||
text = re.sub(r"\s+", " " if keep_spaces else "", text).strip(_LOOKUP_TRIM_CHARS)
|
||
if not text:
|
||
return ""
|
||
return text[: max(1, int(limit))]
|