MCPcopy Create free account
hub / github.com/InternScience/SciReason / strip_string

Function strip_string

opencompass/datasets/math_intern.py:257–327  ·  view source on GitHub ↗
(string)

Source from the content-addressed store, hash-verified

255
256
257def strip_string(string):
258 # linebreaks
259 string = string.replace('\n', '')
260
261 # remove inverse spaces
262 string = string.replace('\\!', '')
263
264 # replace \\ with \
265 string = string.replace('\\\\', '\\')
266
267 # replace tfrac and dfrac with frac
268 string = string.replace('tfrac', 'frac')
269 string = string.replace('dfrac', 'frac')
270
271 # remove \left and \right
272 string = string.replace('\\left', '')
273 string = string.replace('\\right', '')
274
275 # Remove circ (degrees)
276 string = string.replace('^{\\circ}', '')
277 string = string.replace('^\\circ', '')
278
279 # remove dollar signs
280 string = string.replace('\\$', '')
281
282 # remove units (on the right)
283 string = remove_right_units(string)
284
285 # remove percentage
286 string = string.replace('\\%', '')
287 string = string.replace('\%', '') # noqa: W605
288
289 string = string.replace(' .', ' 0.')
290 string = string.replace('{.', '{0.')
291 # if empty, return empty string
292 if len(string) == 0:
293 return string
294 if string[0] == '.':
295 string = '0' + string
296
297 # to consider: get rid of e.g. "k = " or "q = " at beginning
298 if len(string.split('=')) == 2:
299 if len(string.split('=')[0]) <= 2:
300 string = string.split('=')[1]
301
302 # fix sqrt3 --> sqrt{3}
303 string = fix_sqrt(string)
304
305 # remove spaces
306 string = string.replace(' ', '')
307
308 string = fix_fracs(string)
309
310 # manually change 0.5 --> \frac{1}{2}
311 if string == '0.5':
312 string = '\\frac{1}{2}'
313
314 string = fix_a_slash_b(string)

Callers 1

is_equivFunction · 0.85

Calls 5

remove_right_unitsFunction · 0.85
fix_sqrtFunction · 0.85
fix_fracsFunction · 0.85
fix_a_slash_bFunction · 0.85
replaceMethod · 0.80

Tested by

no test coverage detected