MCPcopy Create free account
hub / github.com/nlpxucan/WizardLM / strip_string

Function strip_string

WizardMath/inference/util.py:164–226  ·  view source on GitHub ↗
(string)

Source from the content-addressed store, hash-verified

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