Skip to main content

Module generator

Module generator 

Source
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

SlotDescriptionExample 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§

AnswerType
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. None only on wasm before ensure_lexicon resolves — the LexiconGate component holds Learn content back until it has.