Hebrew text anonymization service for detecting and anonymizing PII/PCI data in Hebrew text with cultural awareness and typo tolerance.
$ dotnet add package NextGenPowerToys.DataPrivacy.HebrewA comprehensive Hebrew text anonymization service for detecting and anonymizing PII/PCI data in Hebrew text with cultural awareness and typo tolerance.
dotnet add package NextGenPowerToys.DataPrivacy.Hebrew
using NextGenPowerToys.DataPrivacy.Hebrew.BusinessServices;
// In Program.cs or Startup.cs
builder.Services.AddHebrewAnonymizationServices();
using NextGenPowerToys.DataPrivacy.Hebrew.Abstractions.Interfaces;
public class MyService
{
private readonly IHebrewAnonymizationService _anonymizer;
public MyService(IHebrewAnonymizationService anonymizer)
{
_anonymizer = anonymizer;
}
public async Task<string> ProcessHebrewText(string hebrewText)
{
var result = await _anonymizer.AnonymizeAsync(hebrewText);
return result.AnonymizedText;
}
}
var hebrewText = "שלום, מספר הכרטיס שלי הוא ארבע חמש שש שבע שמונה תשע אחד שתיים";
var result = await anonymizer.AnonymizeAsync(hebrewText);
Console.WriteLine(result.AnonymizedText);
// Output: "שלום, מספר הכרטיס שלי הוא [כרטיס אשראי]"
Console.WriteLine($"Detected {result.DetectedEntities?.Count} entities");
// Output: "Detected 1 entities"
var result = await anonymizer.AnalyzeAsync("הטלפון שלי הוא אפס חמש שתיים אחד שלוש ארבע חמש שש שבע");
foreach (var entity in result.DetectedEntities ?? [])
{
Console.WriteLine($"Found {entity.EntityType} at position {entity.Start}-{entity.End}");
}
// Output: "Found PHONE_NUMBER at position 15-45"
var isValid = await anonymizer.ValidateInputAsync("טקסט בעברית");
Console.WriteLine($"Text is valid: {isValid}");
// Output: "Text is valid: True"
var entities = await anonymizer.GetSupportedEntitiesAsync();
foreach (var entity in entities)
{
Console.WriteLine($"Supported: {entity}");
}
// Output: CREDIT_CARD, PHONE_NUMBER, ADDRESS, etc.
| Entity Type | Hebrew Placeholder | Example Pattern |
|---|---|---|
| Credit Card | [כרטיס אשראי] | כרטיס + Hebrew numbers |
| Phone Number | [טלפון] | טלפון/נייד + Hebrew numbers |
| Address | [כתובת] | רחוב + Hebrew text + numbers |
| Israeli ID | [תעודת זהות] | 9-digit Israeli format |
| Bank Account | [חשבון בנק] | Israeli bank formats |
| Passport | [דרכון] | Mixed alphanumeric |
[מייל] | Standard email format | |
| Password | [סיסמה] | Hebrew context + numbers |
| Person Name | [שם פרטי] | Hebrew name patterns |
| Driver License | [רישיון נהיגה] | Israeli license format |
The service recognizes Hebrew numbers with typo tolerance:
// All these variations are recognized:
"אחד שתיים שלוש" // Standard
"אחה שתים שלש" // Common typos
"אחד 2 שלוש" // Mixed Hebrew-digits
"אחד שתיים שלוש" // Variable spacing
builder.Services.AddHebrewAnonymizationServices(options =>
{
options.EnableTypoTolerance = true;
options.MinimumConfidenceScore = 0.8;
options.PreserveHebrewContext = true;
});
public class HebrewTextProcessor
{
private readonly IHebrewAnonymizationService _anonymizer;
private readonly ILogger<HebrewTextProcessor> _logger;
public HebrewTextProcessor(
IHebrewAnonymizationService anonymizer,
ILogger<HebrewTextProcessor> logger)
{
_anonymizer = anonymizer;
_logger = logger;
}
public async Task<ProcessingResult> ProcessBankConversation(string conversation)
{
try
{
// Validate input
if (!await _anonymizer.ValidateInputAsync(conversation))
{
return ProcessingResult.Invalid("Invalid Hebrew text");
}
// Anonymize
var result = await _anonymizer.AnonymizeAsync(conversation);
_logger.LogInformation("Processed conversation with {EntityCount} entities",
result.DetectedEntities?.Count ?? 0);
return ProcessingResult.Success(result.AnonymizedText, result.DetectedEntities);
}
catch (Exception ex)
{
_logger.LogError(ex, "Failed to process Hebrew conversation");
return ProcessingResult.Error(ex.Message);
}
}
}
All services are thread-safe and can be used in concurrent scenarios:
var tasks = hebrewTexts.Select(async text =>
await anonymizer.AnonymizeAsync(text));
var results = await Task.WhenAll(tasks);
try
{
var result = await anonymizer.AnonymizeAsync(hebrewText);
}
catch (InvalidHebrewTextException ex)
{
// Handle invalid Hebrew text
logger.LogWarning("Invalid Hebrew text: {Message}", ex.Message);
}
catch (HebrewProcessingException ex)
{
// Handle processing errors
logger.LogError(ex, "Hebrew processing failed");
}
MIT License - see LICENSE file for details.
Contributions are welcome! Please read our contributing guidelines and submit pull requests to our GitHub repository.
For issues and questions, please visit our GitHub repository or contact the NextGenPowerToys team.