File size: 487 Bytes
0e7a159
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
from __future__ import annotations

import re
import unicodedata


def norm_term(term: str) -> str:
    if not term:
        return ""
    text = unicodedata.normalize("NFKC", str(term)).casefold().strip()
    text = text.lstrip("*")
    text = text.replace("₂", "2").replace("₃", "3").replace("₁", "1").replace("₄", "4")
    text = text.replace("h₂", "h2").replace("h₃", "h3").replace("h₁", "h1").replace("h₄", "h4")
    text = re.sub(r"\s+", " ", text)
    return text