added character stripping

This commit is contained in:
grimsace
2026-07-02 12:36:45 -05:00
parent b94b23e46f
commit 4c87d51f2d
2 changed files with 31 additions and 20 deletions
+17 -6
View File
@@ -860,7 +860,7 @@ namespace finder2e_foundry_converter.Converters
// Validate against constraints if available
if (!string.IsNullOrWhiteSpace(constraints))
{
var (isValid, normalizedResponse) = ValidateResponse(trimmed, constraints);
var (isValid, normalizedResponse) = ValidateResponse(trimmed, constraints, promptKey);
if (isValid)
{
Console.WriteLine($"✓ Response is valid: '{normalizedResponse}'");
@@ -972,8 +972,19 @@ namespace finder2e_foundry_converter.Converters
/// <summary>
/// Validate a response against constraints and return normalized response
/// </summary>
private (bool isValid, string normalizedResponse) ValidateResponse(string response, string constraints)
private (bool isValid, string normalizedResponse) ValidateResponse(string response, string constraints, string promptKey = "")
{
// Strip punctuation characters for validation (except for name and description prompts)
var isNameOrDescriptionPrompt = promptKey.Contains("name") || promptKey.Contains("description");
var cleanedResponse = response;
if (!isNameOrDescriptionPrompt)
{
// Strip: _ , ; - ' . ! ? "
var charsToStrip = "_,;-'.!?\"";
cleanedResponse = new string(response.Where(c => !charsToStrip.Contains(c)).ToArray()).Trim();
}
var allowed = constraints.Trim();
var optionsStart = allowed.IndexOf(":");
@@ -996,13 +1007,13 @@ namespace finder2e_foundry_converter.Converters
if (options.Count > 0)
{
// Check exact match
if (options.Any(o => string.Equals(o, response, StringComparison.OrdinalIgnoreCase)))
if (options.Any(o => string.Equals(o, cleanedResponse, StringComparison.OrdinalIgnoreCase)))
{
return (true, response);
return (true, cleanedResponse);
}
// Try first word match
var firstWord = response.Split(new[] { ' ', '\t', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault() ?? string.Empty;
var firstWord = cleanedResponse.Split(new[] { ' ', '\t', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault() ?? string.Empty;
if (options.Any(o => string.Equals(o, firstWord, StringComparison.OrdinalIgnoreCase)))
{
return (true, firstWord);
@@ -1012,7 +1023,7 @@ namespace finder2e_foundry_converter.Converters
}
// No options parsed, accept any non-empty response
return (!string.IsNullOrWhiteSpace(response), response);
return (!string.IsNullOrWhiteSpace(cleanedResponse), cleanedResponse);
}
}
}