MCPcopy Create free account
hub / github.com/CERT-Lab/lora-sb / strip_string

Function strip_string

instruction_tuning_eval/utils.py:172–234  ·  view source on GitHub ↗
(string)

Source from the content-addressed store, hash-verified

170
171
172def strip_string(string):
173 # linebreaks
174 string = string.replace("\n", "")
175
176 # remove inverse spaces
177 string = string.replace("\\!", "")
178
179 # replace \\ with \
180 string = string.replace("\\\\", "\\")
181
182 # replace tfrac and dfrac with frac
183 string = string.replace("tfrac", "frac")
184 string = string.replace("dfrac", "frac")
185
186 # remove \left and \right
187 string = string.replace("\\left", "")
188 string = string.replace("\\right", "")
189
190 # Remove circ (degrees)
191 string = string.replace("^{\\circ}", "")
192 string = string.replace("^\\circ", "")
193
194 # remove dollar signs
195 string = string.replace("\\$", "")
196
197 # remove units (on the right)
198 string = remove_right_units(string)
199
200 # remove percentage
201 string = string.replace("\\%", "")
202 string = string.replace("\%", "") # noqa: W605
203
204 # " 0." equivalent to " ." and "{0." equivalent to "{." Alternatively, add "0" if "." is the start of the string
205 string = string.replace(" .", " 0.")
206 string = string.replace("{.", "{0.")
207 # if empty, return empty string
208 if len(string) == 0:
209 return string
210 if string[0] == ".":
211 string = "0" + string
212
213 # to consider: get rid of e.g. "k = " or "q = " at beginning
214 if len(string.split("=")) == 2:
215 if len(string.split("=")[0]) <= 2:
216 string = string.split("=")[1]
217
218 # fix sqrt3 --> sqrt{3}
219 string = fix_sqrt(string)
220
221 # remove spaces
222 string = string.replace(" ", "")
223
224 # \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}
225 string = fix_fracs(string)
226
227 # manually change 0.5 --> \frac{1}{2}
228 if string == "0.5":
229 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