import re
NUM_MAP = {"0": "zéro", "1": "un", "2": "deux", "3": "trois", "4": "quatre",
"5": "cinq", "6": "six", "7": "sept", "8": "huit", "9": "neuf",
"10": "dix"}
def normalize_numbers(text):
def repl(m):
num = m.group(0)
if num in NUM_MAP:
return f"<num>{NUM_MAP[num]}</num>"
return num
return re.sub(r'\b\d{1,2}\b', repl, text)
def normalize_medications(text):
meds = ["dalacine", "norfloxacine", "amoxicilline", "paracétamol"]
for m in meds:
text = re.sub(rf'\b{re.escape(m)}\b', f'<med>{m}</med>', text, flags=re.IGNORECASE)
return text
def normalize_units(text):
units = {"mg": "milligramme", "ml": "millilitre", "g": "gramme"}
for short, long in units.items():
text = re.sub(rf'\b{re.escape(short)}\b', f'<unit>{long}</unit>', text, flags=re.IGNORECASE)
return text
def normalize_abbreviations(text):
abbrevs = {"ml": "millilitre"}
for short, long in abbrevs.items():
text = re.sub(rf'\b{re.escape(short)}\b', f'<abbrev>{long}</abbrev>', text, flags=re.IGNORECASE)
return text