lang_tools.exercises.pair_matching
¶
Pair matching exercise (from brazilian-bites).
Given N words, the user matches each one to its translation drawn from a
shuffled column. Each submit call evaluates a single (left, right) tap.
Classes:
-
MissingTranslationError–Raised when a word does not carry a translation in the target language.
-
PairMatchingExercise–Pair-matching round factory.
MissingTranslationError
¶
Bases: KeyError
Raised when a word does not carry a translation in the target language.
Initialize with the offending word and the missing target language.
Parameters:
-
word(Word) –The
Wordthat lacks a translation. -
target_language(str) –Target ISO 639-1 code that was requested.
Source code in src/lang_tools/exercises/pair_matching.py
PairMatchingExercise
dataclass
¶
Bases: _BaseExercise
Pair-matching round factory.
Attributes:
-
target_language(str) –ISO 639-1 code for the translations side.
-
rng(Random) –Optional
random.Randomfor deterministic shuffles.
Initialize with the translation language and an optional RNG.
Parameters:
-
target_language(str, default:'en') –ISO 639-1 code used to look up
Word.translations. -
rng(Random | None, default:None) –Optional
random.Random; defaults torandom.SystemRandom. -
**kwargs(object, default:{}) –Forwarded to
_BaseExercise.
Methods:
Source code in src/lang_tools/exercises/pair_matching.py
start
¶
Build a round from a list of words.
Parameters:
Returns:
-
ExerciseRound–ExerciseRoundwhosepromptcarries the left/right columns and -
ExerciseRound–expectedthe correct mapping{left_text: right_text}.
Raises:
-
MissingTranslationError–When any word lacks a translation in
target_language.
Source code in src/lang_tools/exercises/pair_matching.py
submit
¶
Score a single (left_word, right_word) tap.
Parameters:
-
round_(ExerciseRound) –The round returned by
start. -
selected_pair(tuple[str, str]) –The user's chosen
(left, right)pair.
Returns:
-
RoundResult–RoundResultreflecting whether the right value matches the -
RoundResult–expected translation for the left word. Includes one
WordResult -
RoundResult–for the left word.