Spaces:
Running on Zero
Running on Zero
Download src/components/query/normalization.py from yashvasudeva/Adaptive_Rag: direct link, hf CLI and curl.
- Browser
- Download file 545 Bytes
-
https://huggingface.co/spaces/yashvasudeva/Adaptive_Rag/resolve/main/src/components/query/normalization.py
- Command line
-
hf download hf://spaces/yashvasudeva/Adaptive_Rag/src/components/query/normalization.py
-
curl -L -o normalization.py https://huggingface.co/spaces/yashvasudeva/Adaptive_Rag/resolve/main/src/components/query/normalization.py
545 Bytes
| from __future__ import annotations | |
| import re | |
| def normalize_query(query: str) -> str: | |
| """ | |
| Sanitize and normalize user queries. | |
| Removes extraneous whitespace, non-printable characters, | |
| and common delimiter injections. | |
| """ | |
| if not query: | |
| return "" | |
| # Remove non-printable control characters except standard space | |
| cleaned = re.sub(r"[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]", "", query) | |
| # Collapse multiple whitespace | |
| cleaned = re.sub(r"\s+", " ", cleaned).strip() | |
| return cleaned | |