Medica_DecisionSupportAI / column_resolver.py
Rajan Sharma
Update column_resolver.py
f027b47 verified
raw
history blame
555 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)
return [alias.get(_norm(r), r) for r in requested]