MCPcopy Create free account
hub / github.com/PRIME-RL/PRIME / normalize

Function normalize

data_preprocessing/math_util/grader.py:109–126  ·  view source on GitHub ↗
(answer, pi)

Source from the content-addressed store, hash-verified

107
108
109def normalize(answer, pi) -> str:
110 # checking if answer is $<number> and removing $ in that case to compare
111 if isinstance(answer, str) and bool(re.match(r'\$\d+(\.\d+)?', answer)):
112 return answer[1:]
113
114 # checking if answer is <number>% or <number>\\% and removing %
115 if isinstance(answer, str) and (
116 bool(re.match(r'^\d+(\.\d+)?%$', answer)) or bool(re.match(r'^\d+(\.\d+)?\\%$', answer))
117 ):
118 return answer.replace("\\%", "").replace("%", "")
119
120 # handle base
121 answer = handle_base(answer)
122
123 # handle pi
124 answer = handle_pi(answer, pi)
125
126 return answer
127
128def handle_base(x) -> str:
129 if isinstance(x, str) and "_" in x:

Callers 1

math_equalFunction · 0.70

Calls 2

handle_baseFunction · 0.70
handle_piFunction · 0.70

Tested by

no test coverage detected