Lower text and remove punctuation, articles and extra whitespace.
(s)
| 10 | from rouge import Rouge |
| 11 | |
| 12 | def normalize_answer(s): |
| 13 | """Lower text and remove punctuation, articles and extra whitespace.""" |
| 14 | |
| 15 | def remove_articles(text): |
| 16 | return re.sub(r"\b(a|an|the)\b", " ", text) |
| 17 | |
| 18 | def white_space_fix(text): |
| 19 | return " ".join(text.split()) |
| 20 | |
| 21 | def remove_punc(text): |
| 22 | exclude = set(string.punctuation) |
| 23 | return "".join(ch for ch in text if ch not in exclude) |
| 24 | |
| 25 | def lower(text): |
| 26 | return text.lower() |
| 27 | |
| 28 | return white_space_fix(remove_articles(remove_punc(lower(s)))) |
| 29 | |
| 30 | |
| 31 | def normalize_zh_answer(s): |
no test coverage detected