Lower text and remove punctuation, articles and extra whitespace.
(input_text)
| 42 | |
| 43 | |
| 44 | def normalize_text(input_text): |
| 45 | """Lower text and remove punctuation, articles and extra whitespace.""" |
| 46 | |
| 47 | def remove_articles(s): |
| 48 | return re.sub(r'\b(a|an|the)\b', ' ', s) |
| 49 | |
| 50 | def replace_punctuation(s): |
| 51 | to_replace = set(string.punctuation) |
| 52 | # TODO(danielandor): Fix annotation tokenization artifacts here as well. |
| 53 | return ''.join('' if ch in to_replace else ch for ch in s) |
| 54 | |
| 55 | def white_space_fix(s): |
| 56 | return ' '.join(s.split()) |
| 57 | |
| 58 | text = input_text.lower() |
| 59 | text = replace_punctuation(text) |
| 60 | text = remove_articles(text) |
| 61 | text = white_space_fix(text) |
| 62 | return text |
| 63 | |
| 64 | |
| 65 | _DEFAULT_TEXT_NORMALIZER_FN = normalize_text |
nothing calls this directly
no test coverage detected
searching dependent graphs…