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:
@@ -1,62 +0,0 @@
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Core.Parsers.EventOccurrence;
|
||||
|
||||
/// <summary>
|
||||
/// Matches location strings against configurable patterns.
|
||||
/// Supports exact matches and wildcard patterns (e.g., "Room *", "Exhibit Hall *").
|
||||
/// </summary>
|
||||
public static class LocationPatternMatcher
|
||||
{
|
||||
/// <summary>
|
||||
/// Matches location text against configured patterns and returns the matched location.
|
||||
/// </summary>
|
||||
/// <param name="locationText">The location text to match.</param>
|
||||
/// <param name="patterns">The list of patterns to match against.</param>
|
||||
/// <returns>The matched location if a pattern matches, or empty string if no match is found.</returns>
|
||||
public static string Match(string locationText, IReadOnlyList<string> patterns)
|
||||
{
|
||||
// Normalize location text for matching (trim and handle variations)
|
||||
var normalizedLocation = locationText.Trim();
|
||||
|
||||
// If location is empty after normalization, return empty
|
||||
if (string.IsNullOrWhiteSpace(normalizedLocation))
|
||||
return string.Empty;
|
||||
|
||||
foreach (var pattern in patterns)
|
||||
{
|
||||
var normalizedPattern = pattern.Trim();
|
||||
|
||||
// Skip empty patterns
|
||||
if (string.IsNullOrWhiteSpace(normalizedPattern))
|
||||
continue;
|
||||
|
||||
// Handle exact matches (patterns without wildcards like "Online", "Virtual", "TBD")
|
||||
if (!normalizedPattern.Contains('*'))
|
||||
{
|
||||
if (string.Equals(normalizedPattern, normalizedLocation, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return normalizedLocation;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// Convert pattern to regex: escape special chars, replace * with .*
|
||||
// This handles patterns like "Exhibit Hall *", "Room *", "Mtg. Room *", etc.
|
||||
var escapedPattern = Regex.Escape(normalizedPattern);
|
||||
escapedPattern = escapedPattern.Replace(@"\*", ".*?");
|
||||
|
||||
// Use case-insensitive matching
|
||||
// Note: For dynamic patterns, we compile on demand. This is acceptable since patterns
|
||||
// are configured and reused across parsing sessions.
|
||||
var regex = new Regex($"^{escapedPattern}$", RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
||||
if (regex.IsMatch(normalizedLocation))
|
||||
{
|
||||
return normalizedLocation; // Return the full matched location
|
||||
}
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user