MCPcopy Create free account
hub / github.com/Alpha-VLLM/LLaMA2-Accessory / strip_string

Function strip_string

light-eval/src/eval_utils/math_util.py:163–225  ·  view source on GitHub ↗
(string)

Source from the content-addressed store, hash-verified

161
162
163def strip_string(string):
164 # linebreaks
165 string = string.replace("\n", "")
166
167 # remove inverse spaces
168 string = string.replace("\\!", "")
169
170 # replace \\ with \
171 string = string.replace("\\\\", "\\")
172
173 # replace tfrac and dfrac with frac
174 string = string.replace("tfrac", "frac")
175 string = string.replace("dfrac", "frac")
176
177 # remove \left and \right
178 string = string.replace("\\left", "")
179 string = string.replace("\\right", "")
180
181 # Remove circ (degrees)
182 string = string.replace("^{\\circ}", "")
183 string = string.replace("^\\circ", "")
184
185 # remove dollar signs
186 string = string.replace("\\$", "")
187
188 # remove units (on the right)
189 string = remove_right_units(string)
190
191 # remove percentage
192 string = string.replace("\\%", "")
193 string = string.replace("\%", "") # noqa: W605
194
195 # " 0." equivalent to " ." and "{0." equivalent to "{." Alternatively, add "0" if "." is the start of the string
196 string = string.replace(" .", " 0.")
197 string = string.replace("{.", "{0.")
198 # if empty, return empty string
199 if len(string) == 0:
200 return string
201 if string[0] == ".":
202 string = "0" + string
203
204 # to consider: get rid of e.g. "k = " or "q = " at beginning
205 if len(string.split("=")) == 2:
206 if len(string.split("=")[0]) <= 2:
207 string = string.split("=")[1]
208
209 # fix sqrt3 --> sqrt{3}
210 string = fix_sqrt(string)
211
212 # remove spaces
213 string = string.replace(" ", "")
214
215 # \frac1b or \frac12 --> \frac{1}{b} and \frac{1}{2}, etc. Even works with \frac1{72} (but not \frac{72}1). Also does a/b --> \\frac{a}{b}
216 string = fix_fracs(string)
217
218 # manually change 0.5 --> \frac{1}{2}
219 if string == "0.5":
220 string = "\\frac{1}{2}"

Callers 1

is_equivFunction · 0.85

Calls 4

remove_right_unitsFunction · 0.85
fix_sqrtFunction · 0.85
fix_fracsFunction · 0.85
fix_a_slash_bFunction · 0.85

Tested by

no test coverage detected