Add textbook reader, exercise grading, stem-change toggle, extraction pipeline
Major changes: - Textbook UI: chapter list, reader, and interactive exercise view (keyboard + Apple Pencil) surfaced under the Course tab. 30 chapters, 251 exercises. - Stem-change conjugation toggle on Week 4 flashcard decks (E-IE, E-I, O-UE). Uses existing VerbForm + IrregularSpan data to render highlighted present tense conjugations inline. - Deterministic on-device answer grader with partial credit (correct / close for accent-stripped or single-char-typo / wrong). 11 unit tests cover it. - SharedModels: TextbookChapter (local), TextbookExerciseAttempt (cloud- synced), AnswerGrader helpers. Bumped schema. - DataLoader: textbook seeder (version 8) + refresh helpers that preserve LanGo course decks when textbook data is re-seeded. - Local extraction pipeline in Conjuga/Scripts/textbook/ — XHTML chapter parser, answer-key parser, macOS Vision image OCR + PDF page OCR, merger, NSSpellChecker validator, language-aware auto-fixer, and repair pass that re-pairs quarantined vocab rows using bounding-box coordinates. - UI test target (ConjugaUITests) with three tests: end-to-end textbook flow, all-chapters screenshot audit, and stem-change toggle verification. Generated textbook content (textbook_data.json, textbook_vocab.json) and third-party source files are gitignored — re-run Scripts/textbook/run_pipeline.sh locally to regenerate. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
import Testing
|
||||
@testable import SharedModels
|
||||
|
||||
@Suite("AnswerGrader")
|
||||
struct AnswerGraderTests {
|
||||
|
||||
@Test("exact match is correct")
|
||||
func exact() {
|
||||
#expect(AnswerGrader.grade(userText: "tengo", canonical: "tengo") == .correct)
|
||||
#expect(AnswerGrader.grade(userText: "Tengo", canonical: "tengo") == .correct)
|
||||
#expect(AnswerGrader.grade(userText: " tengo ", canonical: "tengo") == .correct)
|
||||
}
|
||||
|
||||
@Test("missing accent is close")
|
||||
func missingAccent() {
|
||||
#expect(AnswerGrader.grade(userText: "esta", canonical: "está") == .close)
|
||||
#expect(AnswerGrader.grade(userText: "nino", canonical: "niño") == .close)
|
||||
#expect(AnswerGrader.grade(userText: "asi", canonical: "así") == .close)
|
||||
}
|
||||
|
||||
@Test("single-char typo is close")
|
||||
func singleCharTypo() {
|
||||
// deletion
|
||||
#expect(AnswerGrader.grade(userText: "tngo", canonical: "tengo") == .close)
|
||||
// insertion
|
||||
#expect(AnswerGrader.grade(userText: "tengoo", canonical: "tengo") == .close)
|
||||
// substitution
|
||||
#expect(AnswerGrader.grade(userText: "tengu", canonical: "tengo") == .close)
|
||||
}
|
||||
|
||||
@Test("two-char typo is wrong")
|
||||
func twoCharTypo() {
|
||||
#expect(AnswerGrader.grade(userText: "tngu", canonical: "tengo") == .wrong)
|
||||
}
|
||||
|
||||
@Test("empty is wrong")
|
||||
func empty() {
|
||||
#expect(AnswerGrader.grade(userText: "", canonical: "tengo") == .wrong)
|
||||
#expect(AnswerGrader.grade(userText: " ", canonical: "tengo") == .wrong)
|
||||
}
|
||||
|
||||
@Test("alternates accepted")
|
||||
func alternates() {
|
||||
#expect(AnswerGrader.grade(userText: "flaca", canonical: "delgada", alternates: ["flaca"]) == .correct)
|
||||
#expect(AnswerGrader.grade(userText: "flacca", canonical: "delgada", alternates: ["flaca"]) == .close)
|
||||
}
|
||||
|
||||
@Test("punctuation stripped")
|
||||
func punctuation() {
|
||||
#expect(AnswerGrader.grade(userText: "el libro.", canonical: "el libro") == .correct)
|
||||
#expect(AnswerGrader.grade(userText: "¿dónde?", canonical: "dónde") == .correct)
|
||||
}
|
||||
|
||||
@Test("very different text is wrong")
|
||||
func wrong() {
|
||||
#expect(AnswerGrader.grade(userText: "hola", canonical: "tengo") == .wrong)
|
||||
#expect(AnswerGrader.grade(userText: "casa", canonical: "perro") == .wrong)
|
||||
}
|
||||
|
||||
@Test("normalize produces expected output")
|
||||
func normalize() {
|
||||
#expect(AnswerGrader.normalize(" Hola ") == "hola")
|
||||
#expect(AnswerGrader.normalize("ABC!") == "abc")
|
||||
}
|
||||
|
||||
@Test("stripAccents handles common Spanish diacritics")
|
||||
func stripAccents() {
|
||||
#expect(AnswerGrader.stripAccents("niño") == "nino")
|
||||
#expect(AnswerGrader.stripAccents("está") == "esta")
|
||||
#expect(AnswerGrader.stripAccents("güero") == "guero")
|
||||
}
|
||||
|
||||
@Test("levenshtein computes edit distance")
|
||||
func levenshtein() {
|
||||
#expect(AnswerGrader.levenshtein("kitten", "sitting") == 3)
|
||||
#expect(AnswerGrader.levenshtein("flaw", "lawn") == 2)
|
||||
#expect(AnswerGrader.levenshtein("abc", "abc") == 0)
|
||||
#expect(AnswerGrader.levenshtein("", "abc") == 3)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user