namespace AIStudio.Assistants.BeyondFactsLab; /// /// A text after the anonymizer of the BeyondFacts Lab ran over it, with what it replaced. /// /// The anonymized text. /// What the anonymizer replaced, in the order it first found each. public sealed record BflAnonymization(string Text, IReadOnlyList Replacements) { /// /// Gets the result of a later run over the text, e.g., after the person edited it, together with what this run /// replaced already. /// /// The later run. /// The text of the later run and the replacements of both runs, counted together. public BflAnonymization CombinedWith(BflAnonymization later) { var combined = this.Replacements.ToList(); foreach (var replacement in later.Replacements) { var index = combined.FindIndex(candidate => candidate.Placeholder == replacement.Placeholder && candidate.Original == replacement.Original); if (index < 0) combined.Add(replacement); else combined[index] = combined[index] with { Count = combined[index].Count + replacement.Count }; } return new BflAnonymization(later.Text, combined); } }