using System.Text.RegularExpressions; using Core.Entities; using Core.Models; using FuzzySharp; namespace Core.Parsers; /// /// Result of parsing event occurrence file, containing both occurrences and parsing issues. /// public class EventOccurrenceParserResult { public IDictionary> Occurrences { get; set; } = new Dictionary>(); public List Issues { get; set; } = new(); } public class EventOccurrenceParser { private FileSystemInfo _txtFile; private ICollection _events; private LocationParsingConfiguration? _locationConfig; public EventOccurrenceParser(FileSystemInfo txtFile, ICollection events, LocationParsingConfiguration? locationConfig = null) { _events = events; _txtFile = txtFile; _locationConfig = locationConfig; } private Regex _re = new ( @"" + // @"(?^[^#].*)\s" + @"(?January|February|March|April|May|June|July|August|September|October|November|December)\s" + @"(?\d{1,2});?\s" + @"(?.*)" ); private readonly Regex _timeRe = new(@"(?\d{1,2}):?(?\d{2})?\s?(?(?:a|p)\.?m\.?)"); // Regex to match time ranges like "10:30 a.m. - 12:00 p.m." or "10:30 a.m. - NOON" // Matches: time1 (optional dash time2/NOON), then location // The time group captures the full time range (including " - NOON" if present) // Pattern breakdown: // - First time: (?:NOON|\d{1,2}:?\d{0,2}\s*(?:[AaPp]\.?[Mm]\.?)) - matches NOON or time with AM/PM (more flexible whitespace) // - Optional range: (?:\s*[–-]\s*(?:NOON|\d{1,2}:?\d{0,2}\s*(?:[AaPp]\.?[Mm]\.?))) - matches dash followed by NOON or time // - Location: (?:\s+(?.+))? - optional whitespace followed by location (capture group with explicit name) private readonly Regex _timeLocationRegex = new(@"(?