fix(learning): ignore the abbreviation dot in unit words

"4,5 Mio" and "4,5 Mio." were different units and so not comparable,
and the quiz viewer marked the dotless answer wrong. Both ports now
drop a trailing dot from the unit word before comparing.

Signed-off-by: Benjamin Schwing <63053132+BenjiAvH@users.noreply.github.com>
This commit is contained in:
Benjamin Schwing
2026-11-25 00:31:35 +00:00
parent 943dd37c8c
commit 0cba402415
3 changed files with 8 additions and 4 deletions

View File

@@ -78,7 +78,7 @@ _PREFIX = re.compile(
_CURRENCY = {"€": "eur", "euro": "eur", "$": "usd", "£": "gbp", "eur": "eur", "usd": "usd"}
_CURRENCY |= {"gbp": "gbp", "chf": "chf"}
# Words that change the magnitude or meaning and so may never be dropped.
_FIXED_UNITS = {"tsd", "tsd.", "teur", "mio", "mio.", "mrd", "mrd.", "bn", "pi", "dozen", "dutzend"}
_FIXED_UNITS = {"tsd", "teur", "mio", "mrd", "bn", "pi", "dozen", "dutzend"}
_FIXED_UNITS |= {"hundred", "hundert", "thousand", "tausend", "million", "millionen"}
_FIXED_UNITS |= {"milliarde", "milliarden", "billion", "billionen"}
# A part outcome that matches only once the key is rounded to the answer's
@@ -186,7 +186,8 @@ def _parse_number(text: str) -> _Number | None:
sign = -1 if "-" in match["pre"] else 1
scale = Fraction(1, 100) if percent else 1
readings = {k: (sign * v * scale, d) for k, (v, d) in readings.items()}
return _Number(readings, implied, percent, "".join(currencies), "".join(units), text.strip())
unit = "".join(units).rstrip(".") # "Mio." is "Mio"
return _Number(readings, implied, percent, "".join(currencies), unit, text.strip())
def _numeric_parts(text: str) -> list[tuple[str | None, _Number]] | None:

View File

@@ -165,6 +165,9 @@
{"user": "1.251.000", "expected": "1.250", "comparable": true, "correct": false, "note": "a scale mismatch must be exact"},
{"user": "1.250.400", "expected": "1.250", "comparable": true, "correct": false},
{"user": "1.250.000 %", "expected": "1.250 %", "comparable": true, "correct": false, "note": "rates have no unit scale"},
{"user": "4,5 Mio", "expected": "4,5 Mio.", "comparable": true, "correct": true, "note": "the abbreviation dot does not change a unit"},
{"user": "12 Tsd.", "expected": "12 Tsd", "comparable": true, "correct": true},
{"user": "5 Stk", "expected": "5 Stk.", "comparable": true, "correct": true},
{"user": "photosynthesis", "expected": "photosynthesis", "comparable": false, "correct": false},
{"user": "12", "expected": "twelve", "comparable": false, "correct": false},
{"user": "", "expected": "5", "comparable": false, "correct": false}

View File

@@ -52,7 +52,7 @@ CURRENCY.set('gbp', 'gbp').set('chf', 'chf')
// Words that change the magnitude or meaning and so may never be dropped.
const FIXED_UNITS = new Set(
(
'tsd tsd. teur mio mio. mrd mrd. bn pi dozen dutzend hundred hundert thousand tausend ' +
'tsd teur mio mrd bn pi dozen dutzend hundred hundert thousand tausend ' +
'million millionen milliarde milliarden billion billionen'
).split(' ')
)
@@ -147,7 +147,7 @@ function parseNumber(text: string): NumberToken | null {
implied,
percent,
currency: [...currencies].join(''),
unit: units.join(''),
unit: units.join('').replace(/\.$/, ''), // "Mio." is "Mio"
text: text.trim(),
}
}