mirror of
https://github.com/deunix-educ/aventuriers-des-mots.git
synced 2026-10-13 02:11:58 +02:00
Add JSON schemas, data validator, and first CE1 content
Introduces a generic JSON-Schema-subset validator in GDScript (scripts/data/schema_validator.gd) used both by `make validate-data` and, later, by ExerciseEngine at load time, plus semantic_checks.gd for cross-field constraints a schema can't express (answer index bounds, at least one faulty token in sentence correction, word count matching between a dictation's target_text and its annotations). Schemas cover rule, exercise (dispatched per type: multiple_choice, sentence_correction), dictation, curriculum, and save (save.schema.json is not yet wired into validate-data; saves live in user://, handled at the Profiles/Saves step). First draft content for the CE1 "accord_adjectif" rule (one rule, two multiple-choice exercises, one sentence correction, one dictation, one curriculum entry) exercises the full pipeline end to end and seeds docs/review/content-review.md, regenerated by the new tools/generate_content_review.py (`make content-review`). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
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
|
||||
Reference in New Issue
Block a user