Spaces:
Paused
Paused
Download src/utils/format_normalizer.py from sam2009897/AstraWeave: direct link, hf CLI and curl.
- Browser
- Download file 767 Bytes
-
https://huggingface.co/spaces/sam2009897/AstraWeave/resolve/main/src/utils/format_normalizer.py
- Command line
-
hf download hf://spaces/sam2009897/AstraWeave/src/utils/format_normalizer.py
-
curl -L -o format_normalizer.py https://huggingface.co/spaces/sam2009897/AstraWeave/resolve/main/src/utils/format_normalizer.py
767 Bytes
| import re | |
| def normalize_number(text: str) -> str: | |
| digits = re.sub(r'[^\d.]', '', text.strip()) | |
| return digits | |
| def normalize_date(text: str) -> str: | |
| patterns = [ | |
| (r'(\d{4})-(\d{2})-(\d{2})', r'\1-\2-\3'), | |
| (r'(\d{2})/(\d{2})/(\d{4})', r'\3-\1-\2'), | |
| (r'([A-Z][a-z]+)\s+(\d{1,2}),?\s+(\d{4})', r'\3-\1-\2'), | |
| ] | |
| for pattern, replacement in patterns: | |
| match = re.search(pattern, text) | |
| if match: | |
| return re.sub(pattern, replacement, text) | |
| return text.strip() | |
| def normalize_list(text: str) -> str: | |
| items = re.split(r'[,;]\s*', text.strip()) | |
| items = [i.strip() for i in items if i.strip()] | |
| return ', '.join(items) | |
| def normalize_name(text: str) -> str: | |
| return text.strip().title() | |