Handle percent/decimal convention in Number-Match

This commit is contained in:
Yiorgis Gozadinos 2026-06-04 14:30:35 +03:00
parent c2a48b55c0
commit 80594cd38c
No known key found for this signature in database
3 changed files with 14 additions and 2 deletions

View file

@ -47,6 +47,10 @@ def extract_numbers(text: str) -> list[float]:
value = _to_float(token)
if value is not None:
numbers.append(value)
if "%" in token:
# Gold answers store ratios as either a percent (24.69) or a
# decimal (0.935); offer both readings of a percent figure.
numbers.append(value / 100)
for number, scale in _SCALED_RE.findall(text):
value = _to_float(number)
if value is not None:

View file

@ -82,6 +82,14 @@ class TestNumberMatchEvaluator:
ctx = self._make_ctx("50.3", "In 2008 it grew from 27.0 to 50.3 percent")
assert self.evaluator.evaluate(ctx) == 1.0
def test_percent_answer_matches_decimal_gold(self) -> None:
ctx = self._make_ctx("0.935", "the cumulative total return was 93.5%")
assert self.evaluator.evaluate(ctx) == 1.0
def test_percent_answer_matches_percent_gold(self) -> None:
ctx = self._make_ctx("24.691358024691358", "approximately 24.69% of production")
assert self.evaluator.evaluate(ctx) == 1.0
def test_non_numeric_prediction(self) -> None:
ctx = self._make_ctx("127.4", "I cannot determine the value")
assert self.evaluator.evaluate(ctx) == 0.0

View file

@ -8,8 +8,8 @@ class TestExtractNumbers:
def test_currency_and_thousands(self) -> None:
assert extract_numbers("$1,234.5") == [1234.5]
def test_percent_stripped(self) -> None:
assert extract_numbers("margin was 50.3%") == [50.3]
def test_percent_yields_both_readings(self) -> None:
assert extract_numbers("margin was 50.3%") == [50.3, 0.503]
def test_parenthesised_negative(self) -> None:
assert extract_numbers("loss of (123)") == [-123.0]