- norm = self.trans.transliterate(self.norm.transliterate(name))
- norm = RE_DIGIT_ALPHA.sub(r'\1␣\2', norm)
- norm = RE_ALPHA_DIGIT.sub(r'\1␣\2', norm)
+ norm = cast(str, self.trans.transliterate(self.norm.transliterate(name)))
+ # If there is a significant non-numeric part, use as is.
+ if RE_NAMED_PART.search(norm) is None:
+ # Otherwise add optional spaces between digits and letters.
+ (norm_opt, cnt1) = RE_DIGIT_ALPHA.subn(r'\1␣\2', norm)
+ (norm_opt, cnt2) = RE_ALPHA_DIGIT.subn(r'\1␣\2', norm_opt)
+ # Avoid creating too many variants per number.
+ if cnt1 + cnt2 <= 4:
+ return norm_opt