lang_tools.exercises.sentence_reconstruction
¶
Sentence reconstruction exercise (from convo_craft).
The user is shown the translation of a target-language sentence and a shuffled
list of word portions; they must tap them in correct order. The expected order
mirrors the source sentence, optionally split via an LLM ParagraphSplitter
(see lang_tools.llm.splitter) followed by merge_short_portions.
Classes:
-
SentenceReconstructionExercise–Sentence reconstruction round factory.
Functions:
-
merge_short_portions–Merge any portion shorter than
min_lenwith its neighbour.
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
merge_short_portions
¶
Merge any portion shorter than min_len with its neighbour.
Mirrors convo_craft's local SentenceSplitter post-processing. Short
portions are appended to the previous one (or prepended to the next one if
they appear at the start).
Parameters:
-
portions(list[str]) –Raw portion list, typically from an LLM splitter.
-
min_len(int, default:_MIN_PORTION_LEN) –Minimum acceptable portion length in characters.
Returns: