Remove LocationParsingConfiguration and LocationPatternMatcher classes, along with related tests and UI components. Update EventOccurrenceParserService to include location validation logic, enhancing warning reporting for long locations and potential date/time patterns. Adjust appsettings and UI to reflect the removal of location parsing settings.

This commit is contained in:
2026-01-09 09:10:22 -05:00
parent 2eae3f205c
commit ea1a4a04ad
9 changed files with 95 additions and 547 deletions
@@ -1,4 +1,5 @@
using System.Text;
using System.Text.RegularExpressions;
using Core.Entities;
using Core.Models;
using Core.Parsers;
@@ -93,6 +94,9 @@ public class EventOccurrenceParserService : IEventOccurrenceParserService
// Copy skipped HS section headers from parser result
result.SkippedHSSectionHeaders.AddRange(parserResult.SkippedHSSectionHeaders);
// Validate locations and add warnings for problematic ones
ValidateLocations(result);
}
finally
{
@@ -121,5 +125,48 @@ public class EventOccurrenceParserService : IEventOccurrenceParserService
return result;
}
/// <summary>
/// Validates locations from parsed occurrences and adds warnings for problematic locations.
/// </summary>
private static void ValidateLocations(EventOccurrenceParseResult result)
{
// Collect all unique locations
var locations = result.Occurrences.Values
.SelectMany(list => list)
.Select(eo => eo.Location)
.Where(loc => !string.IsNullOrWhiteSpace(loc))
.Distinct()
.ToList();
if (!locations.Any())
return;
// Check for long locations (>50 chars)
var longLocations = locations.Where(loc => loc != null && loc.Length > 50).ToList();
foreach (var loc in longLocations)
{
if (loc != null)
{
result.Warnings.Add($"Location '{loc}' is unusually long ({loc.Length} characters) and may contain multiple lines or extra text");
}
}
// Check for date/time patterns
// Pattern matches: month names with day numbers, time patterns (HH:MM AM/PM), and NOON
var dateTimePattern = new Regex(
@"\b(January|February|March|April|May|June|July|August|September|October|November|December)\s+\d{1,2}\b|\b\d{1,2}:\d{2}\s*(a|p)\.?m\.?\b|\bNOON\b",
RegexOptions.IgnoreCase | RegexOptions.Compiled);
var locationsWithDateTime = locations.Where(loc => loc != null && dateTimePattern.IsMatch(loc)).ToList();
foreach (var loc in locationsWithDateTime)
{
if (loc != null)
{
var match = dateTimePattern.Match(loc);
result.Warnings.Add($"Location '{loc}' may contain date/time information: '{match.Value}'");
}
}
}
}