Normalize text by removing articles, punctuation, and extra whitespace, and converting to lowercase.
(s)
| 216 | Candidate Answers: |
| 217 | """ |
| 218 | def normalize_answer(s): |
| 219 | """ |
| 220 | Normalize text by removing articles, punctuation, and extra whitespace, and converting to lowercase. |
| 221 | """ |
| 222 | def remove_articles(text): |
| 223 | return re.sub(r'\b(a|an|the)\b', ' ', text) |
| 224 | def remove_punctuation(text): |
| 225 | return ''.join(ch for ch in text if ch not in string.punctuation) |
| 226 | def whitespace_fix(text): |
| 227 | return ' '.join(text.split()) |
| 228 | def lower(text): |
| 229 | return text.lower() |
| 230 | return whitespace_fix(remove_articles(remove_punctuation(lower(s)))) |
| 231 | def extract_candidate_answers_strict(llm_output): |
| 232 | # 检查输入合法性 |
| 233 | if not isinstance(llm_output, str) or not llm_output.strip(): |
no test coverage detected