From fca7be6cc55ad5fbff3f73067ba686b49439f561 Mon Sep 17 00:00:00 2001 From: Butterscotch! Date: Fri, 13 Dec 2024 20:39:39 -0500 Subject: [PATCH] Add entry title as a dict key --- BingusLib/FaqHandling/FaqConfig.cs | 6 +++--- BingusLib/FaqHandling/FaqDict.cs | 26 +++++++++++++++++++------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/BingusLib/FaqHandling/FaqConfig.cs b/BingusLib/FaqHandling/FaqConfig.cs index b197e3c..08a81ba 100644 --- a/BingusLib/FaqHandling/FaqConfig.cs +++ b/BingusLib/FaqHandling/FaqConfig.cs @@ -15,7 +15,7 @@ public record FaqConfigEntry public string Answer { get; set; } = ""; [JsonPropertyName("matched_questions")] - public List Questions { get; set; } = []; + public string[] Questions { get; set; } = []; public FaqConfigEntry() { } @@ -28,12 +28,12 @@ public FaqConfigEntry(string answer) public FaqConfigEntry(string answer, IEnumerable questions) : this(answer) { - Questions.AddRange(questions); + Questions = questions.ToArray(); } } [JsonPropertyName("faqs")] - public List FaqEntries { get; set; } = []; + public FaqConfigEntry[] FaqEntries { get; set; } = []; public FaqConfigEntry? GetAnswerEntry(string answer) { diff --git a/BingusLib/FaqHandling/FaqDict.cs b/BingusLib/FaqHandling/FaqDict.cs index 69be6f7..1f056d8 100644 --- a/BingusLib/FaqHandling/FaqDict.cs +++ b/BingusLib/FaqHandling/FaqDict.cs @@ -1,3 +1,5 @@ +using static BingusLib.FaqHandling.FaqConfig; + namespace BingusLib.FaqHandling { public class FaqDict @@ -5,18 +7,28 @@ public class FaqDict private readonly Dictionary _faqDict = []; public FaqDict(FaqConfig faqConfig) - : this(faqConfig.QaEntryEnumerator()) { } + : this(faqConfig.FaqEntries) { } - public FaqDict(IEnumerable<(string title, string question, string answer)> tqaMapping) + public FaqDict(IEnumerable faqConfigEntries) { - foreach (var (title, question, answer) in tqaMapping) + foreach (var entry in faqConfigEntries) { - _faqDict[CleanQuery(question)] = new FaqEntry() + _faqDict[CleanQuery(entry.Title)] = new FaqEntry() { - Title = title, - Question = question, - Answer = answer, + Title = entry.Title, + Question = entry.Title, + Answer = entry.Answer, }; + + foreach (var question in entry.Questions) + { + _faqDict[CleanQuery(question)] = new FaqEntry() + { + Title = entry.Title, + Question = question, + Answer = entry.Answer, + }; + } } }