File size: 767 Bytes
26fe5b4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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()