Expand description
Exercise generation from templates.
Transforms exercise configurations from the curriculum into concrete challenges by filling template slots with words from the lexicon.
§Template Syntax
Templates use curly braces for slots: {SlotType} or {SlotType:Modifier}.
§Slot Types
| Slot | Description | Example Output |
|---|---|---|
{ProperName} | Random proper noun | “Alice”, “Bob” |
{Noun} | Random common noun (singular) | “cat”, “dog” |
{Noun:Plural} | Pluralized common noun | “cats”, “dogs” |
{Verb} | Base form verb | “run”, “eat” |
{Verb:Past} | Past tense | “ran”, “ate” |
{Verb:Present3s} | Third person singular | “runs”, “eats” |
{Verb:Gerund} | Present participle | “running”, “eating” |
{Adjective} | Intersective adjective | “tall”, “red” |
§Constraints
Constraints filter word selection by semantic features. They’re specified
in the exercise config’s constraints map:
{
"Verb": ["Intransitive"],
"Noun": ["Animate"]
}§Example
Template: "{ProperName} {Verb:Present3s}."
With constraint Verb: ["Intransitive"]
Output: "Alice runs."
§Usage
use logicaffeine_web::generator::Generator;
use logicaffeine_web::content::ExerciseConfig;
use rand::SeedableRng;
let generator = Generator::new();
let mut rng = rand::rngs::StdRng::seed_from_u64(42);
if let Some(challenge) = generator.generate(&exercise_config, &mut rng) {
println!("Sentence: {}", challenge.sentence);
}Structs§
- Challenge
- A generated exercise instance ready for display and grading.
- Generator
- Exercise generator that fills templates with lexicon words.
Enums§
- Answer
Type - Expected answer format for a challenge.
Functions§
- ensure_
lexicon - Resolves once the lexicon is pinned — instant on native and on repeat calls.
- lexicon
- The pinned lexicon.
Noneonly on wasm beforeensure_lexiconresolves — theLexiconGatecomponent holds Learn content back until it has.