text
stringlengths 0
15.3k
|
---|
new_str += substr |
else: |
try: |
assert len(substr) >= 2 |
except Exception: |
return string |
a = substr[0] |
b = substr[1] |
if b != '{': |
if len(substr) > 2: |
post_substr = substr[2:] |
new_str += '{' + a + '}{' + b + '}' + post_substr |
else: |
new_str += '{' + a + '}{' + b + '}' |
elif len(substr) > 2: |
post_substr = substr[2:] |
new_str += '{' + a + '}' + b + post_substr |
else: |
new_str += '{' + a + '}' + b |
string = new_str |
return string |
def _fix_a_slash_b(string): |
if len(string.split('/')) != 2: |
return string |
a = string.split('/')[0] |
b = string.split('/')[1] |
try: |
a = int(a) |
b = int(b) |
assert string == '{}/{}'.format(a, b) |
new_string = '\\frac{' + str(a) + '}{' + str(b) + '}' |
return new_string |
except Exception: |
return string |
def _remove_right_units(string): |
if '\\text{ ' in string: |
splits = string.split('\\text{ ') |
assert len(splits) == 2 |
return splits[0] |
else: |
return string |
def _fix_sqrt(string): |
if '\\sqrt' not in string: |
return string |
splits = string.split('\\sqrt') |
new_string = splits[0] |
for split in splits[1:]: |
if split[0] != '{': |
a = split[0] |
new_substr = '\\sqrt{' + a + '}' + split[1:] |
else: |
new_substr = '\\sqrt' + split |
new_string += new_substr |
return new_string |
def _strip_string(string): |
string = string.replace('\n', '') |
string = string.replace('\\!', '') |
string = string.replace('\\\\', '\\') |
string = string.replace('tfrac', 'frac') |
string = string.replace('dfrac', 'frac') |
string = string.replace('\\left', '') |
string = string.replace('\\right', '') |
string = string.replace('^{\\circ}', '') |
string = string.replace('^\\circ', '') |
string = string.replace('\\$', '') |
string = _remove_right_units(string) |
string = string.replace('\\%', '') |
string = string.replace('\\%', '') |
string = string.replace(' .', ' 0.') |
string = string.replace('{.', '{0.') |
if len(string) == 0: |
return string |
if string[0] == '.': |
string = '0' + string |
if len(string.split('=')) == 2: |
if len(string.split('=')[0]) <= 2: |
string = string.split('=')[1] |
string = _fix_sqrt(string) |
string = string.replace(' ', '') |
string = _fix_fracs(string) |
if string == '0.5': |
string = '\\frac{1}{2}' |
string = _fix_a_slash_b(string) |
return string |
def is_equiv(str1, str2, verbose=False): |
if str1 is None and str2 is None: |
print('WARNING: Both None') |
return True |
if str1 is None or str2 is None: |
return False |
(str1, str2) = (parse_math_answer(str1), parse_math_answer(str2)) |
try: |
ss1 = _strip_string(str1) |
ss2 = _strip_string(str2) |
if verbose: |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.