lang_tools.exercises
¶
Exercise framework: shared interface and per-mechanic implementations.
Public API
EXERCISE_TYPES: tuple of supported exercise type strings. ExerciseType: literal alias. ExerciseRound, RoundResult, WordResult, SessionSummary: shared data shapes. SentenceReconstructionExercise, PairMatchingExercise, DiacriticTypingExercise, WordleExercise, ConversationalTutorExercise: concrete exercise classes. HintLevel: literal for diacritic-typing hint levels. WordleConfig: configuration for a Wordle exercise session.
Modules:
-
base–Common exercise interface shared by every mechanic.
-
conversational_tutor–Conversational tutor exercise (from
fala-comigo-ai-tutor). -
diacritic_typing–Diacritic typing exercise (from
go-accenter). -
pair_matching–Pair matching exercise (from
brazilian-bites). -
sentence_reconstruction–Sentence reconstruction exercise (from
convo_craft). -
wordle–Wordle exercise (from
worldly-words). -
wordle_config–Wordle exercise configuration.
Classes:
-
ConversationalTutorExercise–Conversational tutor session driven by a caller-supplied chain.
-
DiacriticTypingExercise–Diacritic typing round factory.
-
ExerciseRound–Generic round container.
-
LetterResult–Per-letter evaluation of a guess.
-
PairMatchingExercise–Pair-matching round factory.
-
RoundResult–Outcome of one
submit()call. -
SentenceReconstructionExercise–Sentence reconstruction round factory.
-
SessionSummary–Aggregate stats produced by
finish(). -
TutorMessage–One message in the tutor conversation history.
-
WordResult–Per-word outcome of a single round.
-
WordleConfig–Configuration for a Wordle exercise session.
-
WordleExercise–Wordle round factory.
ConversationalTutorExercise
dataclass
¶
Bases: _BaseExercise
Conversational tutor session driven by a caller-supplied chain.
Attributes:
-
chain(TutorChain | None) –Callable matching the
TutorChainsignature. -
topic(str) –Conversation topic shown to the user.
-
history(list[TutorMessage]) –Live conversation history; mutated in place.
Initialize with an optional chain and topic.
Parameters:
-
chain(TutorChain | None, default:None) –Callable matching
TutorChain. May beNoneif the exercise will be driven manually. -
topic(str, default:'') –Conversation topic.
-
**kwargs(object, default:{}) –Forwarded to
_BaseExercise.
Methods:
-
start–Open the session with an optional tutor greeting.
-
submit–Send a user message and append the tutor reply.
Source code in src/lang_tools/exercises/conversational_tutor.py
start
¶
Open the session with an optional tutor greeting.
Parameters:
-
greeting(TutorMessage | None, default:None) –Initial tutor message; appended to history if provided.
Returns:
-
ExerciseRound–ExerciseRoundwhosepromptis the livehistoryreference.
Source code in src/lang_tools/exercises/conversational_tutor.py
submit
¶
Send a user message and append the tutor reply.
Parameters:
-
round_(ExerciseRound) –The round returned by
start. -
user_text(str) –The user's target-language message.
Returns:
-
RoundResult–RoundResultwhosefeedbackcarries the correction block (if any) -
RoundResult–and
correctis True when no correction was returned.
Raises:
-
RuntimeError–If
chainis None when the user submits a message.
Source code in src/lang_tools/exercises/conversational_tutor.py
DiacriticTypingExercise
dataclass
¶
Bases: _BaseExercise
Diacritic typing round factory.
Initialize the exercise.
Parameters:
-
**kwargs(object, default:{}) –Forwarded to
_BaseExercise(e.g.progress_callback).
Methods:
Source code in src/lang_tools/exercises/diacritic_typing.py
start
¶
Build a round for a single word.
Parameters:
-
word(Word) –Target word; must contain accented characters for the exercise to be meaningful.
-
hint_level(HintLevel, default:'off') –Initial hint level (see
HintLevel).
Returns:
-
ExerciseRound–ExerciseRoundwhoseexpectedis the internal_DiacriticState.
Source code in src/lang_tools/exercises/diacritic_typing.py
submit
¶
Score a single keystroke.
Parameters:
-
round_(ExerciseRound) –The round returned by
start. -
character(str) –The character the user pressed.
Returns:
-
RoundResult–RoundResultwhosecorrectis True for that keystroke. Once the -
RoundResult–word is complete, a
WordResultwith overall correctness (no -
RoundResult–errors) is added to
word_results.
Source code in src/lang_tools/exercises/diacritic_typing.py
ExerciseRound
¶
LetterResult
¶
Bases: BaseModel
Per-letter evaluation of a guess.
Attributes:
-
letter(str) –The character (in the guess form, accent-stripped).
-
state(LetterState) –One of
"correct","misplaced","wrong".
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.
Source code in src/lang_tools/exercises/pair_matching.py
RoundResult
¶
Bases: BaseModel
Outcome of one submit() call.
Attributes:
-
correct(bool) –Whether the round overall counts as correct.
-
feedback(str | None) –Optional human-readable feedback message.
-
word_results(list[WordResult]) –Per-word outcomes for progress tracking.
SentenceReconstructionExercise
dataclass
¶
Bases: _BaseExercise
Sentence reconstruction round factory.
Attributes:
-
rng(Random) –Optional
random.Randomfor deterministic shuffles.
Initialize the exercise with a deterministic RNG by default.
Parameters:
-
rng(Random | None, default:None) –Optional
random.Random; defaults torandom.SystemRandom. -
**kwargs(object, default:{}) –Forwarded to
_BaseExercise(e.g.progress_callback).
Methods:
Source code in src/lang_tools/exercises/sentence_reconstruction.py
start
¶
Build a round from a target-language sentence.
Parameters:
-
sentence(str) –Target-language sentence the user must reconstruct.
-
translation(str) –User-language translation shown as the prompt.
-
portions(list[str] | None, default:None) –Pre-split portions; defaults to a whitespace split.
Returns:
-
ExerciseRound–ExerciseRoundwhosepromptis a dict with shuffled portions.
Source code in src/lang_tools/exercises/sentence_reconstruction.py
submit
¶
Score a user-submitted ordering.
Parameters:
-
round_(ExerciseRound) –The round returned by
start. -
selected_order(list[str]) –User's chosen portion order.
Returns:
-
RoundResult–RoundResultwhosecorrectflag is True iff orderings match.
Source code in src/lang_tools/exercises/sentence_reconstruction.py
SessionSummary
¶
Bases: BaseModel
Aggregate stats produced by finish().
Attributes:
-
exercise_type(ExerciseType) –Tag of the originating exercise.
-
total_rounds(int) –Number of rounds played.
-
correct_rounds(int) –Number of rounds the user completed correctly.
-
words_practiced(list[str]) –Distinct word IDs touched during the session.
-
duration_seconds(float) –Wall-clock duration in seconds.
TutorMessage
¶
Bases: BaseModel
One message in the tutor conversation history.
Attributes:
-
role(Literal['user', 'tutor']) –"user"or"tutor". -
content(str) –Target-language text.
-
translation(str | None) –Optional user-language translation.
-
correction(str | None) –Optional correction block (tutor messages only).
WordResult
¶
WordleConfig
¶
Bases: BaseModelKwargs
Configuration for a Wordle exercise session.
Attributes:
-
word_lengths(list[int]) –Allowed word lengths offered in the word-length selector. Defaults to
[4, 5, 6, 7]. -
default_word_length(int) –Pre-selected word length when no user preference is stored. Defaults to
5.
WordleExercise
dataclass
¶
Bases: _BaseExercise
Wordle round factory.
Initialize the exercise.
Parameters:
-
**kwargs(object, default:{}) –Forwarded to
_BaseExercise.
Methods:
Source code in src/lang_tools/exercises/wordle.py
start
¶
Build a Wordle round around target.
Parameters:
-
target(Word) –The hidden word.
-
max_attempts(int | None, default:None) –Override for the default
len(target) + 1.
Returns:
-
ExerciseRound–ExerciseRoundwhoseexpectedis the internal_WordleState.
Source code in src/lang_tools/exercises/wordle.py
submit
¶
Evaluate a single guess.
Parameters:
-
round_(ExerciseRound) –The round returned by
start. -
guess(str) –User's guess. Compared against the normalized target.
Returns:
-
RoundResult–RoundResultflagging this guess. When the round terminates (win -
RoundResult–or attempts exhausted) a
WordResultis appended.