def repair(text): text = text.lower().replace('.', '').replace('n/a', _NOISE_).replace(' ', ' ').strip().strip('"').strip() for suf in ['th', 'st', 'nd', 'rd']: text = text.replace(' %s ' % suf, '%s ' % suf) words = text.split() for suf in ['th', 'st', 'nd', 'rd']: for i, w in enumerate(words): if w.endswith(suf) and w.rstrip(suf).isdigit(): words[i] = every_word_for_number(int(w.rstrip(suf)), True) words = [every_word_for_number(int(w)) if w.isdigit() else w for w in words] return " ".join(words)
def spell_if_number(word, use_coupling, ordinal=True): for suf in ['th', 'st', 'nd', 'rd']: if word.endswith(suf): word_stripped = word.rstrip(suf) if word_stripped.isdigit(): return every_word_for_number(int(word_stripped), ordinal, use_coupling) if word.startswith('#'): word = word.lstrip('#') if word.isdigit(): return 'number ' + every_word_for_number(int(word), False, use_coupling) if word.isdigit(): return every_word_for_number(int(word), ordinal, use_coupling) else: return word
def spell_if_number(word, use_coupling, ordinal=True): for suf in ['th', 'st', 'nd', 'rd', "'"]: if word.endswith(suf): word_stripped = word.rstrip(suf) if word_stripped.isdigit() and int(word_stripped) <= 1000: return every_word_for_number(int(word_stripped), ordinal, use_coupling) if word.startswith('#'): word = word.lstrip('#') if word.isdigit() and int(word) <= 1000: return 'number ' + every_word_for_number(int(word), False, use_coupling) if word.isdigit() and int(word) <= 1000: return every_word_for_number(int(word), ordinal, use_coupling) else: return word