MCPcopy Create free account
hub / github.com/LeapLabTHU/Absolute-Zero-Reasoner / clean_units

Function clean_units

evaluation/math_eval/eval/parser.py:433–455  ·  view source on GitHub ↗

Clean the units in the number.

(pred_str: str)

Source from the content-addressed store, hash-verified

431
432
433def clean_units(pred_str: str):
434 """Clean the units in the number."""
435
436 def convert_pi_to_number(code_string):
437 code_string = code_string.replace("\\pi", "π")
438 # Replace \pi or π not preceded by a digit or } with 3.14
439 code_string = re.sub(r"(?<![\d}])\\?π", "3.14", code_string)
440 # Replace instances where π is preceded by a digit but without a multiplication symbol, e.g., "3π" -> "3*3.14"
441 code_string = re.sub(r"(\d)(\\?π)", r"\1*3.14", code_string)
442 # Handle cases where π is within braces or followed by a multiplication symbol
443 # This replaces "{π}" with "3.14" directly and "3*π" with "3*3.14"
444 code_string = re.sub(r"\{(\\?π)\}", "3.14", code_string)
445 code_string = re.sub(r"\*(\\?π)", "*3.14", code_string)
446 return code_string
447
448 pred_str = convert_pi_to_number(pred_str)
449 pred_str = pred_str.replace("%", "/100")
450 pred_str = pred_str.replace("$", "")
451 pred_str = pred_str.replace("¥", "")
452 pred_str = pred_str.replace("°C", "")
453 pred_str = pred_str.replace(" C", "")
454 pred_str = pred_str.replace("°", "")
455 return pred_str
456
457
458

Callers

nothing calls this directly

Calls 1

convert_pi_to_numberFunction · 0.85

Tested by

no test coverage detected