def extract_answer()

in DianJin-R1/src/rl/reward_score_cflue.py [0:0]


def extract_answer(solution_str):
    box_pattern = r"\\boxed\{(.*?)\}"
    think_pattern = r"<think>(.*?)</think>"
    answer_pattern = r"<answer>(.*?)</answer>"

    think_matches = re.findall(think_pattern, solution_str, re.DOTALL)
    if len(think_matches) != 1:
        return None

    answer_matches = re.findall(answer_pattern, solution_str, re.DOTALL)
    if len(answer_matches) != 1:
        return None

    box_matches = re.findall(box_pattern, answer_matches[0], re.DOTALL)
    if len(box_matches) == 0:
        return None

    return get_choices(box_matches[-1])