Repository navigation
6. Exam Generator
Important
The details presented in this document are generated in part automatically by AI. Because this document is not regenerated systematically, it may not reflect the latest version of the source code.
| Technical identity | Value |
|---|---|
| Audience | Software developers and functional analysts |
| Namespace | JbtiEvolution.OraklLearn.Generator.Exams |
| Main class | ExamGenerator |
| Question-format component | ExamQuestionGenerator |
The Exam Generator turns the learning content of a generated book into a configurable assessment. It distributes question production across the book’s content chapters, validates the returned questions, balances the result against the requested volume and formats, then publishes one structured exam artifact.
It uses ExamQuestionGenerator for question-format-specific generation.
- Functional journey
- Source and outputs
- Processing architecture
- Question formats
- Distribution and quality controls
- Publication and transaction boundary
- Operational controls
- Code map
flowchart LR
A[Completed book] --> B[Select book BID]
B --> C[Choose count, language, score, timer, and formats]
C --> D[Credit preauthorization]
D --> E[Question generation and validation]
E --> F[Shuffle and index]
F --> G[Publish structured exam]
G --> H[Attach exam to user profile and claim credits]
H --> I[Review, edit, or practice]
The exam stays anchored to a particular book identifier (BID). Its questions retain section and chapter references, which makes it possible to connect practice results to the source learning content.
| Artifact | Role |
|---|---|
| Initial book snapshot | The generator loads the initial structured snapshot saved by the Book Generator, not a newly rendered PDF or EPUB. |
ExamSettings |
Supplies source BID, requested question count, language, question-type weights, score configuration, and countdown choice. |
| Generated questions | Carry section and chapter names and indices before aggregation. |
| Published exam JSON | The completed Exam object serialized to catalog storage. |
| User-profile entry | Adds the exam reference after publishing and credit claim. |
Introduction and conclusion are deliberately removed from the source before question distribution. Assessment generation uses the content sections between them.
flowchart TD
A[Exam settings and BID] --> B[Load initial book snapshot]
B --> C[Remove introduction and conclusion]
C --> D[Calculate content-chapter distribution]
D --> E[Process one content section at a time]
E --> F[Generate chapter questions in parallel]
F --> G[Generate enabled question types in parallel]
G --> H[Validate and tag chapter provenance]
H --> I[Merge, backfill, or trim]
I --> J[Shuffle and index]
J --> K[Create and publish Exam JSON]
K --> L[Claim credits and complete]
Process(Guid jobId) is the orchestration entry point. It changes state from Pending to Running, then performs all admission, production, publication, and billing steps. A failed check or exception ends the process in Error; completion occurs only after the exam is published and claimed.
Question type weights in ExamSettings select the formats to generate. At least two formats must be enabled.
| Family | Formats handled by the implementation | Learner interaction |
|---|---|---|
| Mixed questions | Choice, yes/no, text, select. | Select or enter an answer. |
| Word box | Missing-word sentences with correct and distractor words. | Fill blanks from a word set. |
| Find error | Statements that contain an error. | Identify the incorrect information. |
| Line link | Causes, effects, or related pairs. | Match the connected elements. |
| Matrix categories | Vectors assigned to one or more categories. | Classify elements in a matrix. |
| Flow | Ordered process stages. | Put stages in the right sequence. |
| Scrambled | A word reconstructed from scrambled letters. | Rebuild the word. |
| Intruder | One item does not belong to a group. | Find the odd item out. |
The question generator requests structured JSON for each format. It validates each response before it is added to the chapter result; the matrix-category generator also verifies that categories, vectors, and explanations are internally consistent.
The generator counts chapters after removing the introduction and conclusion. It derives:
- a target count per chapter, with at least one question per chapter;
- an overproduction count of the target plus two questions per chapter;
- a weighted distribution across the enabled formats; and
- a random allocation of rounding remainders to enabled formats for each chapter.
This overproduction is intentional. Generative responses can be incomplete or structurally invalid; generating a small margin gives the pipeline candidates to validate and retain.
flowchart LR
A[Requested exam count] --> B[Count content chapters]
B --> C[Target and margin per chapter]
C --> D[Apply format weights]
D --> E[Generate candidates]
E --> F[Keep structurally valid questions]
F --> G{Total reaches target?}
G -->|surplus| H[Randomly trim]
G -->|shortage| I[Backfill from valid reserve]
H --> J[Final question set]
I --> J
Sections are processed one after another. Within a section, its chapters run in parallel. Within a chapter, each enabled question-format generator can run in parallel.
For every chapter result, the generator:
- Requires at least one returned question.
- Randomizes the candidate order.
- Retains only questions for which
IsValid()succeeds. - Adds the source section and chapter references before discarding excess candidates.
- Keeps surplus valid questions in a reserve for later shortages.
- Fails the chapter if the invalid-question loss exceeds
SystemSettings.PercentToleranceQuestionCount.
Each format request permits up to three retry attempts after the initial request when no response or invalid structured data is received. The response guard accepts only a complete JSON document matching the expected question schema; it does not extract a plausible fragment from unrelated prose.
After all sections finish, valid questions are merged. The generator first backfills any shortage from the reserve, then removes any excess at random. If the total still differs from the requested number, it records that discrepancy in the trace rather than silently inventing unsupported questions.
It then shuffles questions and answer choices 40 times to avoid chapter order or answer-position bias. Word-box answer order is preserved because it encodes the blank sequence. Finally, it assigns:
- a one-based question index;
- a one-based answer index;
- a new ETag to every question and answer; and
- reference ETags for matrix-category questions.
sequenceDiagram
participant EG as Exam Generator
participant CS as Catalog storage
participant PS as Profile and credit service
EG->>CS: Read initial book snapshot by BID
EG->>EG: Create, validate, balance, shuffle, and index questions
EG->>CS: Write published exam JSON
CS-->>EG: Storage reference
EG->>PS: Add exam reference and claim cost
PS-->>EG: Claim accepted
EG->>EG: Set Completed
The exam is serialized only after its final metadata is assembled: EID, source BID, title, questions, score values, date, countdown configuration, and language. The user profile and cost claim are updated only after publication succeeds.
| Control | Implementation effect |
|---|---|
| Source grounding | Reads the initial structured source saved for the selected BID. |
| Minimum format variety | Rejects configurations with fewer than two active question types. |
| Chapter coverage | Calculates production from all chapters in content sections. |
| Output integrity | Requires complete structured data and validates question structures before use. |
| Tolerance threshold | Stops a chapter when invalid generated questions exceed the configured loss ratio. |
| Reserve and trimming | Uses valid surplus candidates to cover shortages and removes surplus at random. |
| Answer fairness | Randomizes question and answer order while preserving WordBox semantics. |
| Traceability | Adds source section/chapter fields and unique tags to the completed exam. |
| Transaction discipline | Preauthorizes first, publishes before billing, and ends in Completed only on success. |
| Concern | Main implementation point |
|---|---|
| End-to-end lifecycle | ExamGenerator.Process |
| Initial book-source loading | CanLoadInitialBookContent |
| Content-section selection and distribution |
CanPresetValues and CanCalculateDistribution
|
| Weighting and rounding |
BuildWeightingList, ApplyDistribution, and GenerateRandomStats
|
| Section and chapter execution |
CanProcessSections and CanGenerateChapterQuestions
|
| Format-specific generation | ExamQuestionGenerator |
| Strict question-response validation and retries | ExamQuestionGenerator.RequestAIJson |
| Final shuffle and indexing |
CanRandomQuestionsAndAnswers and IndexQuestions
|
| Publication and claim |
CanPublishExam and CanClaim
|
The Exam Generator is a controlled assessment-production pipeline: it combines generative question creation with source grounding, structural validation, distribution rules, fairness randomization, traceability, publication, and credit management.

https://orakllearn.com · Author: Jimmy Bourque · https://jbti-evolution.com
- Main page
- Overview
- Foundation
- Integration
- Flow
- Using OraklLearn
- Configuration
- Monitoring