MCPcopy
hub / github.com/deepseek-ai/DeepSeek-Coder / strip_string

Function strip_string

Evaluation/PAL-Math/utils/parser.py:62–160  ·  view source on GitHub ↗
(string)

Source from the content-addressed store, hash-verified

60
61
62def strip_string(string):
63 string = str(string).strip()
64 # linebreaks
65 string = string.replace("\n", "")
66
67 # right "."
68 string = string.rstrip(".")
69
70 # remove inverse spaces
71 string = string.replace("\\!", "")
72 string = string.replace("\\ ", "")
73
74 # replace \\ with \
75 string = string.replace("\\\\", "\\")
76 string = string.replace("\\\\", "\\")
77
78 # replace tfrac and dfrac with frac
79 string = string.replace("tfrac", "frac")
80 string = string.replace("dfrac", "frac")
81
82 # remove \left and \right
83 string = string.replace("\\left", "")
84 string = string.replace("\\right", "")
85
86 # Remove unit: miles, dollars if after is not none
87 _string = re.sub(r"\\text{.*?}$", "", string).strip()
88 if _string != "" and _string != string:
89 # print("Warning: unit not removed: '{}' -> '{}'".format(string, _string))
90 string = _string
91
92 # Remove circ (degrees)
93 string = string.replace("^{\\circ}", "")
94 string = string.replace("^\\circ", "")
95
96 # remove dollar signs
97 string = string.replace("\\$", "")
98 string = string.replace("$", "")
99
100 string = string.replace("\\text", "")
101 string = string.replace("x\\in", "")
102
103 # remove percentage
104 string = string.replace("\\%", "")
105 string = string.replace("\%", "")
106 string = string.replace("%", "")
107
108 # " 0." equivalent to " ." and "{0." equivalent to "{." Alternatively, add "0" if "." is the start of the string
109 string = string.replace(" .", " 0.")
110 string = string.replace("{.", "{0.")
111
112 # cdot
113 string = string.replace("\\cdot", "")
114
115 # inf
116 string = string.replace("infinity", "\\infty")
117 if "\\infty" not in string:
118 string = string.replace("inf", "\\infty")
119 string = string.replace("+\\inity", "\\infty")

Callers 4

inferenceFunction · 0.85
extract_answerFunction · 0.85
parse_ground_truthFunction · 0.85
run_executeFunction · 0.85

Calls 3

_fix_sqrtFunction · 0.85
_fix_fracsFunction · 0.85
_fix_a_slash_bFunction · 0.85

Tested by

no test coverage detected