File size: 609 Bytes
7935397
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import re
from typing import List, Dict

def _norm(s: str) -> str:
    return re.sub(r'[^a-z0-9]+', '', s.lower())

def build_alias_map(columns: List[str]) -> Dict[str, str]:
    m = {}
    for c in columns:
        n = _norm(c)
        m[n] = c
        if n.endswith('s') and n[:-1] not in m: m[n[:-1]] = c
        if not n.endswith('s') and n+'s' not in m: m[n+'s'] = c
    return m

def resolve_cols(requested: List[str], available: List[str]) -> List[str]:
    alias = build_alias_map(available)
    out = []
    for r in requested:
        n = _norm(r)
        out.append(alias.get(n, r))
    return out