(pred: str, answer_flag: bool = True)
| 17 | |
| 18 | |
| 19 | def extract_theoremqa_answer(pred: str, answer_flag: bool = True): |
| 20 | from latex2sympy2_extended import latex2sympy |
| 21 | |
| 22 | if any([option in pred.lower() for option in ['yes', 'true']]): |
| 23 | pred = 'True' |
| 24 | elif any([option in pred.lower() for option in ['no', 'false']]): |
| 25 | pred = 'False' |
| 26 | elif any([option in pred.lower() for option in ['(a)', '(b)', '(c)', '(d)', '(e)', '(f)']]): |
| 27 | pass |
| 28 | else: |
| 29 | if answer_flag: |
| 30 | # Extract the numbers out of the string |
| 31 | pred = pred.split('=')[-1].strip() |
| 32 | pred = clean_units(pred) |
| 33 | try: |
| 34 | with time_limit(1): |
| 35 | tmp = str(latex2sympy(pred)) |
| 36 | pred = eval(tmp) |
| 37 | if isinstance(pred, tuple): |
| 38 | pred = str(list(pred)) |
| 39 | else: |
| 40 | pred = str(pred) |
| 41 | |
| 42 | except Exception: |
| 43 | if re.match(r'-?[\d\.]+\s\D+$', pred): |
| 44 | pred = pred.split(' ')[0] |
| 45 | elif re.match(r'-?[\d\.]+\s[^\s]+$', pred): |
| 46 | pred = pred.split(' ')[0] |
| 47 | else: |
| 48 | # desparate search over the last number |
| 49 | preds = re.findall(r'-?\d*\.?\d+', pred) |
| 50 | if(len(preds) >= 1): |
| 51 | pred = preds[-1] |
| 52 | else: |
| 53 | pred = '' |
| 54 | return pred |
| 55 | |
| 56 | def answer_clean(direct_answer_trigger_for_fewshot: tuple, pred: str): |
| 57 | pred = pred.strip('\n') |
no test coverage detected