Files
aventuriers-des-mots/scripts/data/semantic_checks.gd
T
Denis Defolie 2fe455f5d1 Add pure correction and pedagogy logic with full test coverage
scripts/correction/: AnswerValidator (multiple choice, sentence
correction via tap-the-faulty-word + retype) and DictationAnalyzer
build the CorrectionResult structure from cahier des charges §6.
Dictation analysis aligns words with WordAligner (Wagner-Fischer edit
distance) before any character comparison, so an omitted or added
word doesn't cascade into false errors on every following word.
TextNormalizer handles non-breaking spaces, typographic apostrophes,
and decomposed-vs-composed French accented characters via an
explicit table (GDScript has no built-in NFC/NFD normalization).
Error classification follows the data annotations only (rule_id
present -> grammatical, absent -> unclassified), never a runtime
linguistic guess.

scripts/pedagogy/: DifficultyManager (per-skill difficulty from
recent results), AttemptFlow (3-attempt graduated aid: hint, then
explanation, then reveal, matching exercise-lifecycle.md's second
gap), and ReviewScheduler (the five mastery states from §9, with
session-counted spaced review intervals [1, 3, 6, 12] rather than
wall-clock dates, since a family device's clock isn't trustworthy).

All of it is pure: no scene tree, no clock or RNG read directly,
every effectful input (session number, attempt outcome) is a
parameter. 65 headless tests across both layers, including the
word-omission-doesn't-cascade regression and the full
decouverte -> acquise -> a_reviser -> acquise path.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-11 17:03:14 +02:00

53 lines
2.0 KiB
GDScript

class_name SemanticChecks
extends RefCounted
## Contraintes croisees entre champs qu'un schema JSON (voir SchemaValidator) ne
## peut pas exprimer : index valide, coherence entre deux tableaux, etc.
## Appele uniquement apres une validation de schema reussie : ces fonctions
## supposent une structure deja conforme.
static func check_multiple_choice(data: Dictionary, path: String) -> Array[String]:
var errors: Array[String] = []
var answers: Array = data.get("answers", [])
var correct_answer: int = data.get("correct_answer", -1)
if correct_answer < 0 or correct_answer >= answers.size():
errors.append(
(
"%s : correct_answer (%d) hors des bornes de answers (%d element(s))"
% [path, correct_answer, answers.size()]
)
)
return errors
static func check_sentence_correction(data: Dictionary, path: String) -> Array[String]:
var errors: Array[String] = []
var tokens: Array = data.get("tokens", [])
var has_error_token := false
for i in tokens.size():
var token: Dictionary = tokens[i]
if token.get("correct", true) == false:
has_error_token = true
if not token.has("expected"):
errors.append(
"%s.tokens[%d] : token fautif sans correction attendue ('expected')" % [path, i]
)
if not has_error_token:
errors.append("%s : aucun token fautif, rien a corriger" % path)
return errors
static func check_dictation(data: Dictionary, path: String) -> Array[String]:
var errors: Array[String] = []
var target_text: String = data.get("target_text", "")
var words: Array = data.get("words", [])
var expected_word_count := target_text.split(" ", false).size()
if words.size() != expected_word_count:
errors.append(
(
"%s : %d mot(s) annote(s) pour %d mot(s) dans target_text"
% [path, words.size(), expected_word_count]
)
)
return errors