DEV Community

Tianqi Li
Tianqi Li

Posted on Fully Autonomous

How a German browser quiz decides whether Koeln means Köln

KÖLN and Köln should receive the same result in a timed quiz. So should a version of Köln in which the umlaut is stored as a combining character. Koeln takes a different decision. It is a spelling the quiz can explicitly accept for that city. And if a future question contains both Maße and Masse, the matcher needs to keep those words apart.

Krillion auf Deutsch is an independent fan-made browser quiz with original German-language questions. Each question gives players 25 seconds to enter a correct answer. Here is how its answer matcher separates equivalent text from spellings that require a decision by the question author.

Normalize the representation

The game normalizes both the input and the expected answer to Unicode NFC and then lowercases them using the German locale. It also tidies surrounding whitespace, repeated internal whitespace and trailing sentence punctuation. That handles cases where keyboards or copy and paste produce different representations of the same text. NFC leaves the umlaut intact, so a plain o stays distinct from ö.

This JavaScript example isolates the Unicode part of that behavior:

const key = text => text.normalize('NFC').toLocaleLowerCase('de');

console.assert(key('KÖLN') === key('Köln'));
console.assert(key('Ko\u0308ln') === key('Köln'));
console.assert(key('Koln') !== key('Köln'));
Enter fullscreen mode Exit fullscreen mode

Keep aliases with the answers they name

Each accepted answer carries its canonical spelling and can also carry explicit aliases. The matcher compares normalized input against both. When Koeln matches an alias, the match refers to the canonical answer Köln; it does not need a separate entry or score. The matcher reports whether it matched an alias, so the interface can show the stored spelling if the player has enabled spelling confirmation.

A general replacement rule would be harder to reason about. Automatically rewriting every ß to ss, for instance, makes Maße and Masse collide. An explicit alias can still allow Strasse for Straße where that spelling makes sense. The scope of the decision stays with one answer to one question.

Test the boundary with near misses

The project's test suite checks that capital letters and a combining umlaut both work, that Koeln resolves as an alias, and that Koln is rejected when it has not been added. It separately checks that Masse does not get accepted for Maße. Positive cases protect the forgiving input experience. Negative cases protect the meaning of the question.

If you add this approach to a quiz of your own, check for aliases that normalize to the same key within a question. A matcher that returns the first hit would otherwise assign an ambiguous input according to answer order. Test both the spelling variants you mean to accept and nearby inputs you mean to reject before the question enters rotation.

AI disclosure: This article was generated with AI and checked against the project source and its matching tests.

Top comments (0)