Skip to content

Commit fca7be6

Browse files
committed
Add entry title as a dict key
1 parent 2f4c0a6 commit fca7be6

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

BingusLib/FaqHandling/FaqConfig.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public record FaqConfigEntry
1515
public string Answer { get; set; } = "";
1616

1717
[JsonPropertyName("matched_questions")]
18-
public List<string> Questions { get; set; } = [];
18+
public string[] Questions { get; set; } = [];
1919

2020
public FaqConfigEntry() { }
2121

@@ -28,12 +28,12 @@ public FaqConfigEntry(string answer)
2828
public FaqConfigEntry(string answer, IEnumerable<string> questions)
2929
: this(answer)
3030
{
31-
Questions.AddRange(questions);
31+
Questions = questions.ToArray();
3232
}
3333
}
3434

3535
[JsonPropertyName("faqs")]
36-
public List<FaqConfigEntry> FaqEntries { get; set; } = [];
36+
public FaqConfigEntry[] FaqEntries { get; set; } = [];
3737

3838
public FaqConfigEntry? GetAnswerEntry(string answer)
3939
{

BingusLib/FaqHandling/FaqDict.cs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,34 @@
1+
using static BingusLib.FaqHandling.FaqConfig;
2+
13
namespace BingusLib.FaqHandling
24
{
35
public class FaqDict
46
{
57
private readonly Dictionary<string, FaqEntry> _faqDict = [];
68

79
public FaqDict(FaqConfig faqConfig)
8-
: this(faqConfig.QaEntryEnumerator()) { }
10+
: this(faqConfig.FaqEntries) { }
911

10-
public FaqDict(IEnumerable<(string title, string question, string answer)> tqaMapping)
12+
public FaqDict(IEnumerable<FaqConfigEntry> faqConfigEntries)
1113
{
12-
foreach (var (title, question, answer) in tqaMapping)
14+
foreach (var entry in faqConfigEntries)
1315
{
14-
_faqDict[CleanQuery(question)] = new FaqEntry()
16+
_faqDict[CleanQuery(entry.Title)] = new FaqEntry()
1517
{
16-
Title = title,
17-
Question = question,
18-
Answer = answer,
18+
Title = entry.Title,
19+
Question = entry.Title,
20+
Answer = entry.Answer,
1921
};
22+
23+
foreach (var question in entry.Questions)
24+
{
25+
_faqDict[CleanQuery(question)] = new FaqEntry()
26+
{
27+
Title = entry.Title,
28+
Question = question,
29+
Answer = entry.Answer,
30+
};
31+
}
2032
}
2133
}
2234

0 commit comments

Comments
 (0)