MCPcopy Create free account
hub / github.com/Yuan-Li-FNLP/R3-RAG / normalize_answer

Function normalize_answer

benchmark/batch_check/batch_check.py:218–230  ·  view source on GitHub ↗

Normalize text by removing articles, punctuation, and extra whitespace, and converting to lowercase.

(s)

Source from the content-addressed store, hash-verified

216Candidate Answers:
217"""
218def 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))))
231def extract_candidate_answers_strict(llm_output):
232 # 检查输入合法性
233 if not isinstance(llm_output, str) or not llm_output.strip():

Callers 1

compute_em_f1Function · 0.70

Calls 4

whitespace_fixFunction · 0.70
remove_articlesFunction · 0.70
remove_punctuationFunction · 0.70
lowerFunction · 0.70

Tested by

no test coverage detected