MCPcopy Create free account
hub / github.com/RUC-NLPIR/WebThinker / _strip_string

Function _strip_string

scripts/utils/math_equivalence.py:69–136  ·  view source on GitHub ↗
(string)

Source from the content-addressed store, hash-verified

67 return new_string
68
69def _strip_string(string):
70 # linebreaks
71 string = string.replace("\n", "")
72 #print(string)
73
74 # remove inverse spaces
75 string = string.replace("\\!", "")
76 #print(string)
77
78 # replace \\ with \
79 string = string.replace("\\\\", "\\")
80 #print(string)
81
82 # replace tfrac and dfrac with frac
83 string = string.replace("tfrac", "frac")
84 string = string.replace("dfrac", "frac")
85 #print(string)
86
87 # remove \left and \right
88 string = string.replace("\\left", "")
89 string = string.replace("\\right", "")
90 #print(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
99 # remove units (on the right)
100 string = _remove_right_units(string)
101
102 # remove percentage
103 string = string.replace("\\%", "")
104 string = string.replace("\%", "")
105
106 # " 0." equivalent to " ." and "{0." equivalent to "{." Alternatively, add "0" if "." is the start of the string
107 string = string.replace(" .", " 0.")
108 string = string.replace("{.", "{0.")
109 # if empty, return empty string
110 if len(string) == 0:
111 return string
112 if string[0] == ".":
113 string = "0" + string
114
115 # to consider: get rid of e.g. "k = " or "q = " at beginning
116 if len(string.split("=")) == 2:
117 if len(string.split("=")[0]) <= 2:
118 string = string.split("=")[1]
119
120 # fix sqrt3 --> sqrt{3}
121 string = _fix_sqrt(string)
122
123 # remove spaces
124 string = string.replace(" ", "")
125
126 # \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}

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