Skip to content

Commit

Permalink
Add entry title as a dict key
Browse files Browse the repository at this point in the history
  • Loading branch information
ButterscotchV committed Dec 14, 2024
1 parent 2f4c0a6 commit fca7be6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
6 changes: 3 additions & 3 deletions BingusLib/FaqHandling/FaqConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public record FaqConfigEntry
public string Answer { get; set; } = "";

[JsonPropertyName("matched_questions")]
public List<string> Questions { get; set; } = [];
public string[] Questions { get; set; } = [];

public FaqConfigEntry() { }

Expand All @@ -28,12 +28,12 @@ public FaqConfigEntry(string answer)
public FaqConfigEntry(string answer, IEnumerable<string> questions)
: this(answer)
{
Questions.AddRange(questions);
Questions = questions.ToArray();
}
}

[JsonPropertyName("faqs")]
public List<FaqConfigEntry> FaqEntries { get; set; } = [];
public FaqConfigEntry[] FaqEntries { get; set; } = [];

public FaqConfigEntry? GetAnswerEntry(string answer)
{
Expand Down
26 changes: 19 additions & 7 deletions BingusLib/FaqHandling/FaqDict.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,34 @@
using static BingusLib.FaqHandling.FaqConfig;

namespace BingusLib.FaqHandling
{
public class FaqDict
{
private readonly Dictionary<string, FaqEntry> _faqDict = [];

public FaqDict(FaqConfig faqConfig)
: this(faqConfig.QaEntryEnumerator()) { }
: this(faqConfig.FaqEntries) { }

public FaqDict(IEnumerable<(string title, string question, string answer)> tqaMapping)
public FaqDict(IEnumerable<FaqConfigEntry> 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,
};
}
}
}

Expand Down

0 comments on commit fca7be6

Please sign in to comment.