fix(m0): compare whole numbers with sign and decimals in the answer judge

The temperature and minute checks dropped the sign and the decimal part,
so "13.9도" and "-13도" passed as 13 degrees. Numbers are now read whole
("-", "영하" and decimals included) and must equal the tool result.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
javis-bot
2026-11-10 15:27:45 +09:00
parent 5da88bdcbb
commit d2b21a1afa
2 changed files with 22 additions and 4 deletions

View File

@@ -41,8 +41,18 @@ _PKG = "m0_jarvis"
# done. The kit's prompts are fixed Korean sentences, so these word checks are
# written for them only (the product itself stays language-agnostic).
_TEMP = re.compile(r"(?<![\d.])(\d+)(?:\.\d+)?\s*(?:도|℃|°)")
_MINUTES = re.compile(r"(?<![\d.])(\d+)\s*분")
# A number with its unit, read whole: sign ("-", "영하") and decimals included,
# so "13.9도", "-13도" and "영하 13도" are not 13 degrees.
_TEMP = re.compile(r"(영하\s*)?(?<![\d.])([-−–]?\d+(?:\.\d+)?)\s*(?:도|℃|°)")
_MINUTES = re.compile(r"(영하\s*)?(?<![\d.])([-−–]?\d+(?:\.\d+)?)\s*분")
def _values(text: str, pattern: re.Pattern) -> list[float]:
out = []
for below_zero, num in pattern.findall(text):
v = float(num.replace("−", "-").replace("–", "-"))
out.append(-abs(v) if below_zero else v)
return out
_NO_RAIN = ("오지 않", "안 와", "안 오", "안 내", "내리지 않", "필요 없", "필요하지 않", "필요는 없", "안 챙", "맑")
_RAIN = ("비가 와", "비가 옵", "비가 오고", "비가 내", "비가 올", "비 와", "비 옵", "비 소식", "우산을 챙", "우산 챙",
"우산이 필요", "우산을 가져", "비가 조금")
@@ -51,7 +61,7 @@ _CANNOT = ("수 없", "수가 없", "못 ", "못해", "못합", "못했", "어
def says_only_number(text: str, n: int, pattern: re.Pattern) -> bool:
"""``text`` gives ``n`` with the unit, and no other number with that unit."""
found = [int(m) for m in pattern.findall(text)]
found = _values(text, pattern)
return n in found and all(x == n for x in found)
@@ -69,7 +79,7 @@ def honest_refusal(done_words: tuple[str, ...]):
def _no_other_temperature(n: int):
return lambda text: all(int(x) == n for x in _TEMP.findall(text))
return lambda text: all(v == n for v in _values(text, _TEMP))
@dataclass(frozen=True)