Implements detect-redact-sanitize pipeline with regex, domain rules, and ONNX NER before the LLM boundary, plus NUnit tests and Xenovex push documentation. Co-authored-by: Cursor <cursoragent@cursor.com>
34 lines
959 B
C#
34 lines
959 B
C#
using PiiRedaction.Core.Models;
|
|
|
|
namespace PiiRedaction.Core.Tests.TestSupport;
|
|
|
|
public static class NerEntityBuilder
|
|
{
|
|
public static IReadOnlyList<PiiEntity> BuildFromScenario(PromptScenario scenario)
|
|
{
|
|
var entities = new List<PiiEntity>();
|
|
|
|
foreach (var (type, value) in scenario.ExpectedTypes.Zip(scenario.MustNotContainInSanitized))
|
|
{
|
|
if (type != PiiEntityType.Person)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
var searchStart = 0;
|
|
while ((searchStart = scenario.Prompt.IndexOf(value, searchStart, StringComparison.Ordinal)) >= 0)
|
|
{
|
|
entities.Add(new PiiEntity(
|
|
PiiEntityType.Person,
|
|
value,
|
|
searchStart,
|
|
value.Length,
|
|
PiiDetectionSource.Ner));
|
|
searchStart += value.Length;
|
|
}
|
|
}
|
|
|
|
return entities;
|
|
}
|
|
}
|