Spaces:
Running
Running
fix math cornercase
Browse files
utils.py
CHANGED
|
@@ -33,12 +33,12 @@ def sync_pipe(func, progress=False):
|
|
| 33 |
return sync_func
|
| 34 |
|
| 35 |
|
| 36 |
-
def
|
| 37 |
-
def wrapper(
|
| 38 |
try:
|
| 39 |
-
return func(
|
| 40 |
except Exception:
|
| 41 |
-
return
|
| 42 |
|
| 43 |
return wrapper
|
| 44 |
|
|
@@ -136,17 +136,20 @@ def extract_numeric(string, pattern=NUMERIC_IN_EN) -> str:
|
|
| 136 |
|
| 137 |
|
| 138 |
def remove_boxed(s):
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
|
|
|
|
|
|
|
|
|
| 150 |
|
| 151 |
|
| 152 |
def last_boxed_only_string(string):
|
|
@@ -179,6 +182,7 @@ def last_boxed_only_string(string):
|
|
| 179 |
return retval
|
| 180 |
|
| 181 |
|
|
|
|
| 182 |
def get_answer(string):
|
| 183 |
if boxed := last_boxed_only_string(string):
|
| 184 |
return remove_boxed(boxed)
|
|
|
|
| 33 |
return sync_func
|
| 34 |
|
| 35 |
|
| 36 |
+
def asis_backup(func):
|
| 37 |
+
def wrapper(sample):
|
| 38 |
try:
|
| 39 |
+
return func(sample)
|
| 40 |
except Exception:
|
| 41 |
+
return sample
|
| 42 |
|
| 43 |
return wrapper
|
| 44 |
|
|
|
|
| 136 |
|
| 137 |
|
| 138 |
def remove_boxed(s):
|
| 139 |
+
try:
|
| 140 |
+
if (left := "\\boxed ") in s:
|
| 141 |
+
assert s[: len(left)] == left, s
|
| 142 |
+
return s[len(left) :]
|
| 143 |
+
elif (left := "\\boxed{") in s:
|
| 144 |
+
assert s[: len(left)] == left, s
|
| 145 |
+
return s[len(left) : -1]
|
| 146 |
+
|
| 147 |
+
elif (left := "\\fbox{") in s:
|
| 148 |
+
assert s[: len(left)] == left, s
|
| 149 |
+
return s[len(left) : -1]
|
| 150 |
+
raise ValueError(f"Cannot remove boxed from {s}")
|
| 151 |
+
except AssertionError:
|
| 152 |
+
return s
|
| 153 |
|
| 154 |
|
| 155 |
def last_boxed_only_string(string):
|
|
|
|
| 182 |
return retval
|
| 183 |
|
| 184 |
|
| 185 |
+
@asis_backup
|
| 186 |
def get_answer(string):
|
| 187 |
if boxed := last_boxed_only_string(string):
|
| 188 |
return remove_boxed(boxed)
|