facat commited on
Commit
32ae64f
1 Parent(s): 84e1d00

fix math cornercase

Browse files
Files changed (1) hide show
  1. utils.py +19 -15
utils.py CHANGED
@@ -33,12 +33,12 @@ def sync_pipe(func, progress=False):
33
  return sync_func
34
 
35
 
36
- def return_blank_if_exception(func):
37
- def wrapper(*args, **kwargs):
38
  try:
39
- return func(*args, **kwargs)
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
- if (left := "\\boxed ") in s:
140
- assert s[: len(left)] == left, s
141
- return s[len(left) :]
142
- elif (left := "\\boxed{") in s:
143
- assert s[: len(left)] == left, s
144
- return s[len(left) : -1]
145
-
146
- elif (left := "\\fbox{") in s:
147
- assert s[: len(left)] == left, s
148
- return s[len(left) : -1]
149
- raise ValueError(f"Cannot remove boxed from {s}")
 
 
 
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)