Muttersprache koppeln und russischen A1-Kurs ergänzen
GUI und neue Erklärungen verwenden gemeinsam native_language. Deutsch und Russisch sind die beiden Muttersprachen; Englisch bleibt die Lernsprache. Kompatibilitätsfelder werden atomar gekoppelt, widersprüchliche Eingaben abgewiesen und bestehende Profile sowie eingefrorene Inhalte erhalten. Ergänzt vollständige russische GUI-Kataloge und 840 geprüfte Aufgabenansichten in sieben Modulen einschließlich A1-Test, mit getrennten Sprachrollen für Ausgangs- und Lernmaterial. Äquivalente Ansichten teilen ihre Nachweisidentität. Stabile API-Fehlercodes, neue deterministische Hilfen und Trainingsbegründungen berücksichtigen die Muttersprache. Dokumentiert das Sprachmodell in AGENTS.md. Validierung: Go-Race-Suite mit eigener lokaler PostgreSQL-Testdatenbank, go vet, Web-Build, Offline-Bank-/Variantenaudit, Diff-Prüfung sowie lokale Browser-Smokes für Sprachen, Kurs, Administration, Aussprache und Aufnahme. Keine Live-Anbieter, Produktionsprofile, Deployment-Schritte oder historischen Neubewertungen.
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"speech-learning-api/internal/domain"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type nativeLanguageKey struct{}
|
||||
|
||||
// Request-scoped native language also applies to deterministic feedback; target
|
||||
// texts and Azure measurements are never translated by this presentation step.
|
||||
func WithNativeLanguage(ctx context.Context, language string) context.Context {
|
||||
return context.WithValue(ctx, nativeLanguageKey{}, language)
|
||||
}
|
||||
func nativeLanguage(ctx context.Context) string {
|
||||
language, _ := ctx.Value(nativeLanguageKey{}).(string)
|
||||
return language
|
||||
}
|
||||
|
||||
func localizedFeedback(ctx context.Context, text string, result domain.PronunciationResult) domain.TeacherResponse {
|
||||
if nativeLanguage(ctx) != "ru-RU" {
|
||||
return mockFeedback(text, result)
|
||||
}
|
||||
response := domain.TeacherResponse{ExerciseType: "repeat_sentence", TargetText: text, TTSText: text,
|
||||
TeacherFeedback: "Предложение стоит ещё потренировать. Повторите его вслух.", NextRecommendation: "Повторите это упражнение."}
|
||||
weakWord, phonemeWord := "", ""
|
||||
var weak domain.PhonemeScore
|
||||
for _, word := range result.WordScores {
|
||||
if word.Highlight == "weak" && weakWord == "" {
|
||||
weakWord = word.Word
|
||||
}
|
||||
if strings.EqualFold(word.ErrorType, "Omission") {
|
||||
continue
|
||||
}
|
||||
for _, phoneme := range word.PhonemeScores {
|
||||
if phoneme.Accuracy < 75 && (phonemeWord == "" || phoneme.Accuracy < weak.Accuracy) {
|
||||
weak = phoneme
|
||||
phonemeWord = word.Word
|
||||
}
|
||||
}
|
||||
}
|
||||
switch {
|
||||
case result.OverallScore >= 95 && result.AccuracyScore >= 95 && result.FluencyScore >= 95 && result.CompletenessScore >= 95:
|
||||
response.TeacherFeedback = "Отлично! Произношение этого предложения получило очень высокую оценку."
|
||||
response.NextRecommendation = "Можно перейти к новому упражнению."
|
||||
case phonemeWord != "":
|
||||
response.TeacherFeedback = fmt.Sprintf("В слове %q звук /%s/ получил %.0f из 100 баллов.", phonemeWord, weak.Phoneme, weak.Accuracy)
|
||||
response.NextRecommendation = fmt.Sprintf("Повторите предложение, уделяя внимание слову %q.", phonemeWord)
|
||||
case weakWord != "":
|
||||
response.TeacherFeedback = fmt.Sprintf("Слово %q получило невысокую оценку. Потренируйте его ещё раз в предложении.", weakWord)
|
||||
response.NextRecommendation = fmt.Sprintf("Повторите предложение, уделяя внимание слову %q.", weakWord)
|
||||
case result.OverallScore >= 85:
|
||||
response.TeacherFeedback = "Хорошо! Произношение этого предложения получило высокую оценку."
|
||||
response.NextRecommendation = "Можно перейти к новому упражнению."
|
||||
}
|
||||
return response
|
||||
}
|
||||
Reference in New Issue
Block a user