diff --git a/backend/DramaLing.Api/Controllers/AIController.cs b/backend/DramaLing.Api/Controllers/AIController.cs index 4fc5b2b..a8eb13b 100644 --- a/backend/DramaLing.Api/Controllers/AIController.cs +++ b/backend/DramaLing.Api/Controllers/AIController.cs @@ -98,21 +98,19 @@ public class AIController : ControllerBase var finalText = aiAnalysis.GrammarCorrection.HasErrors ? aiAnalysis.GrammarCorrection.CorrectedText : request.InputText; - // 3. 準備AI分析響應資料(包含個人化資訊) + // 3. 準備AI分析響應資料 var baseResponseData = new { AnalysisId = Guid.NewGuid(), InputText = request.InputText, - UserLevel = userLevel, // 新增:顯示使用的程度 - HighValueCriteria = CEFRLevelService.GetTargetLevelRange(userLevel), // 新增:顯示高價值判定範圍 + UserLevel = userLevel, GrammarCorrection = aiAnalysis.GrammarCorrection, SentenceMeaning = new { Translation = aiAnalysis.Translation }, FinalAnalysisText = finalText ?? request.InputText, - WordAnalysis = PostProcessWordAnalysisWithUserLevel(aiAnalysis.WordAnalysis, userLevel), - HighValueWords = ExtractHighValueWords(aiAnalysis.WordAnalysis, userLevel), + WordAnalysis = aiAnalysis.WordAnalysis, PhrasesDetected = new object[0] // 暫時簡化 }; @@ -146,7 +144,6 @@ public class AIController : ControllerBase }, FinalAnalysisText = finalText, WordAnalysis = analysis.WordAnalysis, - HighValueWords = analysis.HighValueWords, PhrasesDetected = analysis.PhrasesDetected }; @@ -253,7 +250,7 @@ public class AIController : ControllerBase Translation = card.Translation, Explanation = card.Definition, // 使用 AI 生成的定義作為解釋 WordAnalysis = GenerateWordAnalysisForSentence(text), - HighValueWords = GetHighValueWordsForSentence(text), + HighValueWords = new string[0], // 移除高價值詞彙判定,由前端負責 PhrasesDetected = new[] { new @@ -318,7 +315,7 @@ public class AIController : ControllerBase Translation = translation, Explanation = explanation, WordAnalysis = GenerateWordAnalysisForSentence(text), - HighValueWords = GetHighValueWordsForSentence(text), + HighValueWords = new string[0], // 移除高價值詞彙判定,由前端負責 PhrasesDetected = new[] { new @@ -480,8 +477,6 @@ public class AIController : ControllerBase var cleanWord = word.Trim(); if (string.IsNullOrEmpty(cleanWord) || cleanWord.Length < 2) continue; - // 判斷是否為高價值詞彙 - var isHighValue = IsHighValueWordDynamic(cleanWord); var difficulty = GetWordDifficulty(cleanWord); analysis[cleanWord] = new @@ -494,10 +489,7 @@ public class AIController : ControllerBase synonyms = GetSynonyms(cleanWord), antonyms = new string[0], isPhrase = false, - isHighValue = isHighValue, - learningPriority = isHighValue ? "high" : "low", - difficultyLevel = difficulty, - costIncurred = isHighValue ? 0 : 1 + difficultyLevel = difficulty }; } @@ -510,29 +502,9 @@ public class AIController : ControllerBase private string[] GetHighValueWordsForSentence(string text) { var words = text.ToLower().Split(new[] { ' ', '.', ',', '!', '?' }, StringSplitOptions.RemoveEmptyEntries); - return words.Where(w => IsHighValueWordDynamic(w.Trim())).ToArray(); + return new string[0]; // 移除高價值詞彙判定,由前端負責 } - /// - /// 動態判斷高價值詞彙 - /// - private bool IsHighValueWordDynamic(string word) - { - // B1+ 詞彙或特殊概念詞彙視為高價值 - var highValueWords = new[] - { - "animals", "instincts", "safe", "food", "find", - "brought", "meeting", "agreed", "thing", - "study", "learn", "important", "necessary", - "beautiful", "wonderful", "amazing", - "problem", "solution", "different", "special", - "cut", "slack", "job", "new", "think", "should", - "ashamed", "mistake", "apologized", "felt", - "strong", "wind", "knocked", "tree", "park" - }; - - return highValueWords.Contains(word.ToLower()); - } /// /// 獲取詞彙翻譯 @@ -689,73 +661,7 @@ public class AIController : ControllerBase }; } - /// - /// 後處理詞彙分析,根據用戶程度重新判定重點學習詞彙 - /// - private Dictionary PostProcessWordAnalysisWithUserLevel( - Dictionary originalAnalysis, string userLevel) - { - var processedAnalysis = new Dictionary(); - foreach (var wordPair in originalAnalysis) - { - var wordData = wordPair.Value; - - // 從AI分析結果取得詞彙難度等級 - string wordLevel = wordData.DifficultyLevel ?? "A2"; - - // 使用CEFRLevelService重新判定是否為重點學習詞彙 - bool isHighValue = CEFRLevelService.IsHighValueForUser(wordLevel, userLevel); - - // 檢查AI例句 - _logger.LogInformation("🔍 詞彙 {Word}: AI例句={Example}, AI翻譯={ExampleTranslation}", - wordPair.Key, wordData.Example ?? "null", wordData.ExampleTranslation ?? "null"); - - // 保留AI分析的其他資料,只重新設定isHighValue - processedAnalysis[wordPair.Key] = new - { - word = wordData.Word ?? wordPair.Key, - translation = wordData.Translation ?? "", - definition = wordData.Definition ?? "", - partOfSpeech = wordData.PartOfSpeech ?? "noun", - pronunciation = wordData.Pronunciation ?? $"/{wordPair.Key}/", - isHighValue = isHighValue, // 重新判定 - difficultyLevel = wordLevel, - synonyms = GetSynonyms(wordPair.Key), // 補充同義詞 - example = !string.IsNullOrEmpty(wordData.Example) ? - wordData.Example : - GetQualityExampleSentence(wordPair.Key), // 優先使用AI例句 - exampleTranslation = !string.IsNullOrEmpty(wordData.ExampleTranslation) ? - wordData.ExampleTranslation : - GetQualityExampleTranslation(wordPair.Key) // 優先使用AI翻譯 - }; - } - - return processedAnalysis; - } - - /// - /// 從詞彙分析中提取重點學習詞彙 - /// - private string[] ExtractHighValueWords(Dictionary wordAnalysis, string userLevel) - { - var highValueWords = new List(); - - foreach (var wordPair in wordAnalysis) - { - var wordData = wordPair.Value; - - string wordLevel = wordData.DifficultyLevel ?? "A2"; - - // 使用CEFRLevelService判定 - if (CEFRLevelService.IsHighValueForUser(wordLevel, userLevel)) - { - highValueWords.Add(wordPair.Key); - } - } - - return highValueWords.ToArray(); - } /// /// 取得有學習價值的例句