"""答案解析与结果判定(终端与 Web 共用)。"""
from __future__ import annotations
import re
def extract_final_answer(text: str) -> str:
match = re.search(r"最终答案[::]\s*(.+)", text)
if match:
return match.group(1).strip()
lines = [line.strip() for line in text.splitlines() if line.strip()]
return lines[-1] if lines else "(未识别到最终答案)"
def has_reasoning_steps(text: str) -> bool:
markers = ("第一步", "第二步", "第三步", "step 1", "Step 1", "推理过程", "对齐小数")
return any(marker in text for marker in markers)
def is_answer_correct(final_answer: str, expected: str) -> bool:
numbers = re.findall(r"\d+\.?\d*", expected)
return all(num in final_answer for num in numbers)