2026-07-07 17:12:38 +05:30
|
|
|
using FluentAssertions;
|
|
|
|
|
using PiiRedaction.Core.Models;
|
|
|
|
|
using PiiRedaction.Infrastructure.Onnx;
|
|
|
|
|
using PiiRedaction.Tests.Shared;
|
|
|
|
|
|
|
|
|
|
namespace PiiRedaction.Infrastructure.Tests.Onnx;
|
|
|
|
|
|
|
|
|
|
[TestFixture]
|
|
|
|
|
[Category("TamilNer")]
|
|
|
|
|
public sealed class RealTamilNerModelRunnerTests : RealTamilNerModelFixture
|
|
|
|
|
{
|
|
|
|
|
[Test]
|
|
|
|
|
public void IsModelAvailable_LoadsOnnxAndTokenizer()
|
|
|
|
|
{
|
|
|
|
|
Runner.IsModelAvailable.Should().BeTrue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestCase("வாடிக்கையாளர் ராஜேஷ் குமார் அழைத்தார்.", "ராஜேஷ்", "ராஜேஷ் குமார்")]
|
|
|
|
|
public void PredictEntities_TamilScript_DetectsPersonEntity(
|
|
|
|
|
string prompt,
|
|
|
|
|
string expectedNamePart,
|
|
|
|
|
string expectedValue)
|
|
|
|
|
{
|
2026-07-08 12:18:27 +05:30
|
|
|
var result = Runner.PredictEntities(prompt);
|
|
|
|
|
var entities = result.Entities;
|
2026-07-07 17:12:38 +05:30
|
|
|
|
|
|
|
|
entities.Should().Contain(entity =>
|
|
|
|
|
entity.Type == PiiEntityType.Person &&
|
|
|
|
|
entity.Source == PiiDetectionSource.Ner &&
|
2026-07-08 12:18:27 +05:30
|
|
|
entity.ModelOrigin == NerModelOrigin.Tamil &&
|
2026-07-07 17:12:38 +05:30
|
|
|
entity.Value.Contains(expectedNamePart, StringComparison.Ordinal) &&
|
|
|
|
|
prompt.AsSpan(entity.StartIndex, entity.Length).ToString() == entity.Value);
|
|
|
|
|
|
|
|
|
|
entities.Should().Contain(entity => entity.Value == expectedValue);
|
2026-07-08 12:18:27 +05:30
|
|
|
result.InvokedModels.Should().Equal(NerModelOrigin.Tamil);
|
2026-07-07 17:12:38 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void PredictEntities_TamilWithPhone_DetectsPersonAndLeavesPhoneToRegex()
|
|
|
|
|
{
|
|
|
|
|
const string prompt = "வாடிக்கையாளர் ராஜேஷ் குமார் தொலைபேசி 9876543210";
|
|
|
|
|
|
2026-07-08 12:18:27 +05:30
|
|
|
var entities = Runner.PredictEntities(prompt).Entities;
|
2026-07-07 17:12:38 +05:30
|
|
|
|
|
|
|
|
entities.Should().Contain(entity =>
|
|
|
|
|
entity.Type == PiiEntityType.Person &&
|
|
|
|
|
entity.Source == PiiDetectionSource.Ner &&
|
2026-07-08 12:18:27 +05:30
|
|
|
entity.ModelOrigin == NerModelOrigin.Tamil &&
|
2026-07-07 17:12:38 +05:30
|
|
|
entity.Value.Contains("ராஜேஷ்", StringComparison.Ordinal));
|
|
|
|
|
entities.Should().NotContain(entity => entity.Type == PiiEntityType.Phone);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void PredictEntities_CleanTamilQuestion_ReturnsNoEntities()
|
|
|
|
|
{
|
|
|
|
|
const string prompt = "பணத்தை திரும்பப் பெறுவது எப்படி?";
|
|
|
|
|
|
2026-07-08 12:18:27 +05:30
|
|
|
Runner.PredictEntities(prompt).Entities.Should().BeEmpty();
|
2026-07-07 17:12:38 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestCase("Customer Senthil phone 9876543210", "Senthil")]
|
|
|
|
|
public void PredictEntities_TanglishLatinScript_DoesNotInvokeTamilRunner(
|
|
|
|
|
string prompt,
|
|
|
|
|
string expectedNamePart)
|
|
|
|
|
{
|
|
|
|
|
// TamilOnnxNerRunner is script-scoped; Tanglish is handled by English routing in pipeline tests.
|
|
|
|
|
// Direct Tamil runner on Latin-only text should not emit person spans.
|
2026-07-08 12:18:27 +05:30
|
|
|
var entities = Runner.PredictEntities(prompt).Entities;
|
2026-07-07 17:12:38 +05:30
|
|
|
|
|
|
|
|
entities.Should().NotContain(entity =>
|
|
|
|
|
entity.Type == PiiEntityType.Person &&
|
|
|
|
|
entity.Value.Contains(expectedNamePart, StringComparison.OrdinalIgnoreCase));
|
|
|
|
|
}
|
|
|
|
|
}
|