(cls, pred: str, extract_last_num=False)
| 135 | return opt |
| 136 | |
| 137 | def extract_answer(cls, pred: str, extract_last_num=False): |
| 138 | if pred.find('The final answer is ') >= 0: |
| 139 | x = pred[pred.find('The final answer is ') + |
| 140 | len('The final answer is '):] |
| 141 | x = x[1:x.find('$.')] |
| 142 | # print(x) |
| 143 | return cls.clean(x) |
| 144 | if pred.find('\n\nQuestion:') >= 0: |
| 145 | pred = pred.split('\n\nQuestion:')[0] |
| 146 | if pred.find('The answer is'): |
| 147 | pred = pred[pred.find('The answer is') + len('The answer is'):] |
| 148 | return cls.clean(pred) |
| 149 | if pred.find('# Answer') >= 0: |
| 150 | return cls.clean(pred[pred.find('# Answer') + len('# Answer'):]) |
| 151 | if pred.find('The answer is:') >= 0: |
| 152 | return cls.clean(pred[pred.find('The answer is:') + |
| 153 | len('The answer is:'):]) |
| 154 | if pred.find('####') >= 0: |
| 155 | return cls.clean(pred[pred.find('####') + 4:]) |
| 156 | left = '\\boxed{' |
| 157 | if pred.find(left) >= 0: |
| 158 | pred = pred[pred.find(left) + len(left):] |
| 159 | return cls.clean(cls.extract_matching_bracket(pred)) |
| 160 | |
| 161 | if extract_last_num: |
| 162 | nums = [] |
| 163 | opt = '' |
| 164 | |
| 165 | def contain_digit(opt): |
| 166 | for ch in opt: |
| 167 | if ch.isdigit(): |
| 168 | return True |
| 169 | return False |
| 170 | |
| 171 | for ch in pred: |
| 172 | if ch.isdigit() or ch in ' ,.': |
| 173 | opt = opt + ch |
| 174 | else: |
| 175 | if contain_digit(opt): |
| 176 | nums.append(opt) |
| 177 | opt = '' |
| 178 | if contain_digit(opt): |
| 179 | return cls.clean(opt) |
| 180 | if nums: |
| 181 | return cls.clean(nums[-1]) |
| 182 | return None |
| 183 | |
| 184 | |
| 185 | def fix_fracs(string): |
no test coverage detected