Accept elided corrections (j'achèterais) and fix the expected answer (0.8.1)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Denis Defolie
2026-10-12 11:41:49 +02:00
parent 42dd170a5d
commit 8584249d78
6 changed files with 93 additions and 10 deletions
+36
View File
@@ -113,3 +113,39 @@ func test_sentence_correction_accepts_decomposed_accented_correction() -> void:
exercise_with_accent, [0], {0: "école"}
)
assert_true(result.is_correct)
func _elision_exercise() -> Dictionary:
return {
"rule_id": "regle_x",
"hint": "indice",
"explanation": "explication",
"tokens":
[
{"text": "Si", "correct": true},
{"text": "j'achèterai", "correct": false, "expected": "j'achèterais"},
{"text": "une", "correct": true},
],
}
func test_elided_token_accepts_the_whole_word_or_only_the_verb() -> void:
var exercise := _elision_exercise()
for typed in ["j'achèterais", "J'achèterais", "j’achèterais", "achèterais", " achèterais "]:
var result := AnswerValidator.validate_sentence_correction(exercise, [1], {1: typed})
assert_true(result.is_correct, "« %s » doit etre accepte" % typed)
func test_elided_token_still_rejects_a_wrong_correction() -> void:
var exercise := _elision_exercise()
for typed in ["j'achèterai", "achèterai", "achetterais", ""]:
var result := AnswerValidator.validate_sentence_correction(exercise, [1], {1: typed})
assert_false(result.is_correct, "« %s » ne doit pas etre accepte" % typed)
func test_expected_without_elision_accepts_the_prefix_of_the_touched_word() -> void:
var exercise := _elision_exercise()
exercise["tokens"][1]["expected"] = "achèterais"
for typed in ["achèterais", "j'achèterais"]:
var result := AnswerValidator.validate_sentence_correction(exercise, [1], {1: typed})
assert_true(result.is_correct, "« %s » doit etre accepte" % typed)
+27
View File
@@ -79,3 +79,30 @@ func test_correct_answer_position_is_not_always_the_same() -> void:
1,
"bonne reponse toujours au meme rang : %s" % rule_id
)
func test_elided_wrong_tokens_keep_the_same_prefix_unless_the_word_changes() -> void:
# Regression : « j'achèterai » avait pour attendu « achèterais » (sans « j' »),
# donc la reponse naturelle « j'achèterais » etait refusee. Un mot touche avec
# elision doit avoir un attendu qui garde le prefixe d'elision, sauf si c'est
# l'elision elle-meme qui est l'objet de l'exercice (la/l'a, qu'elle/quelle...).
for rule_id: String in ExerciseEngine._rules:
for exercise: Dictionary in ExerciseEngine._candidates_for(rule_id, "sentence_correction"):
for token: Dictionary in exercise["tokens"]:
if token.get("correct", true):
continue
var text: String = token["text"]
var expected: String = token["expected"]
if not text.contains("'") or expected.contains("'"):
continue
# Le mot change de nature (ex. « Qu'elle » -> « Quelle ») : seules
# les corrections ou l'elision est conservee sont concernees.
var prefix := text.split("'")[0]
var stem := text.substr(prefix.length() + 1)
assert_false(
expected.to_lower().begins_with(stem.substr(0, 3).to_lower()),
(
"%s : attendu « %s » sans le prefixe de « %s »"
% [exercise["id"], expected, text]
)
)