Medica_DecisionSupportAI / column_resolver.py
Rajan Sharma
Create column_resolver.py
7935397 verified
raw
history blame
609 Bytes
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