Enhance event occurrence parsing to skip unmatched high school section headers
This commit introduces a new property to track skipped high school section headers in the EventOccurrenceParseResult and EventOccurrenceParserResult classes. The EventOccurrenceParser has been updated to gracefully skip HS section headers that do not match any event definitions, improving the parsing logic. Additionally, the LocationParsingConfiguration has been removed from the EventOccurrenceParser, simplifying its constructor. Unit tests have been updated to reflect these changes and ensure correct behavior during parsing.
This commit is contained in:
@@ -51,42 +51,23 @@ public class LineClassifier_Tests
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IsContinuationLine_StartsWithLowercaseContinuationWord_ReturnsTrue()
|
||||
public void IsContinuationLine_StartsWithAsterisk_ReturnsTrue()
|
||||
{
|
||||
// Act & Assert
|
||||
Assert.That(LineClassifier.IsContinuationLine("the event will be held"), Is.True);
|
||||
Assert.That(LineClassifier.IsContinuationLine("and participants should arrive"), Is.True);
|
||||
Assert.That(LineClassifier.IsContinuationLine("be sure to register"), Is.True);
|
||||
Assert.That(LineClassifier.IsContinuationLine("or contact the coordinator"), Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IsContinuationLine_StartsWithLowercase_NonContinuationWord_ReturnsFalse()
|
||||
{
|
||||
// Act & Assert
|
||||
Assert.That(LineClassifier.IsContinuationLine("important: bring materials"), Is.False);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IsContinuationLine_StartsWithUppercase_ReturnsFalse()
|
||||
{
|
||||
// Act & Assert
|
||||
Assert.That(LineClassifier.IsContinuationLine("Important Event March 15"), Is.False);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IsContinuationLine_ContainsSchedulePosted_ReturnsTrue()
|
||||
{
|
||||
// Act & Assert
|
||||
Assert.That(LineClassifier.IsContinuationLine("Schedule Posted on website"), Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IsContinuationLine_ContainsNote_ReturnsTrue()
|
||||
{
|
||||
// Act & Assert
|
||||
Assert.That(LineClassifier.IsContinuationLine("Note: Additional information"), Is.True);
|
||||
Assert.That(LineClassifier.IsContinuationLine("*The books of semifinalist teams"), Is.True);
|
||||
Assert.That(LineClassifier.IsContinuationLine("*Note: Important details"), Is.True);
|
||||
Assert.That(LineClassifier.IsContinuationLine("*This is a continuation line"), Is.True);
|
||||
Assert.That(LineClassifier.IsContinuationLine(" *Line with leading whitespace"), Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IsContinuationLine_DoesNotStartWithAsterisk_ReturnsFalse()
|
||||
{
|
||||
// Act & Assert
|
||||
Assert.That(LineClassifier.IsContinuationLine("The event will be held"), Is.False);
|
||||
Assert.That(LineClassifier.IsContinuationLine("Note: Additional information"), Is.False);
|
||||
Assert.That(LineClassifier.IsContinuationLine("Important Event March 15"), Is.False);
|
||||
Assert.That(LineClassifier.IsContinuationLine("Schedule Posted on website"), Is.False);
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using Core.Models;
|
||||
using Core.Parsers.EventOccurrence;
|
||||
using NUnit.Framework;
|
||||
|
||||
@@ -10,110 +9,69 @@ public class TimeLocationParser_Tests
|
||||
[Test]
|
||||
public void Parse_TimeAndLocation_ExtractsBoth()
|
||||
{
|
||||
// Arrange
|
||||
var locationConfig = new LocationParsingConfiguration
|
||||
{
|
||||
LocationPatterns = new List<string> { "Room *" }
|
||||
};
|
||||
|
||||
// Act
|
||||
TimeLocationParser.Parse("10:30 a.m. Room 101", locationConfig,
|
||||
out string time, out string location, out bool locationParseSuccess);
|
||||
TimeLocationParser.Parse("10:30 a.m. Room 101",
|
||||
out string time, out string location);
|
||||
|
||||
// Assert
|
||||
Assert.That(time, Is.EqualTo("10:30 a.m."));
|
||||
Assert.That(location, Is.EqualTo("Room 101"));
|
||||
Assert.That(locationParseSuccess, Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Parse_TimeRangeAndLocation_ExtractsTimeRangeAndLocation()
|
||||
{
|
||||
// Arrange
|
||||
var locationConfig = new LocationParsingConfiguration
|
||||
{
|
||||
LocationPatterns = new List<string> { "Room *" }
|
||||
};
|
||||
|
||||
// Act
|
||||
TimeLocationParser.Parse("10:00 a.m. - 12:00 p.m. Room 202", locationConfig,
|
||||
out string time, out string location, out bool locationParseSuccess);
|
||||
TimeLocationParser.Parse("10:00 a.m. - 12:00 p.m. Room 202",
|
||||
out string time, out string location);
|
||||
|
||||
// Assert
|
||||
Assert.That(time, Is.EqualTo("10:00 a.m. - 12:00 p.m."));
|
||||
Assert.That(location, Is.EqualTo("Room 202"));
|
||||
Assert.That(locationParseSuccess, Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Parse_NOONAndLocation_ExtractsBoth()
|
||||
{
|
||||
// Arrange
|
||||
var locationConfig = new LocationParsingConfiguration
|
||||
{
|
||||
LocationPatterns = new List<string> { "Hall *" }
|
||||
};
|
||||
|
||||
// Act
|
||||
TimeLocationParser.Parse("NOON Hall C", locationConfig,
|
||||
out string time, out string location, out bool locationParseSuccess);
|
||||
TimeLocationParser.Parse("NOON Hall C",
|
||||
out string time, out string location);
|
||||
|
||||
// Assert
|
||||
Assert.That(time, Is.EqualTo("NOON"));
|
||||
Assert.That(location, Is.EqualTo("Hall C"));
|
||||
Assert.That(locationParseSuccess, Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Parse_TimeOnly_NoLocation()
|
||||
{
|
||||
// Arrange
|
||||
var locationConfig = new LocationParsingConfiguration
|
||||
{
|
||||
LocationPatterns = new List<string> { "Room *" }
|
||||
};
|
||||
|
||||
// Act
|
||||
TimeLocationParser.Parse("3:00 p.m.", locationConfig,
|
||||
out string time, out string location, out bool locationParseSuccess);
|
||||
TimeLocationParser.Parse("3:00 p.m.",
|
||||
out string time, out string location);
|
||||
|
||||
// Assert
|
||||
Assert.That(time, Is.EqualTo("3:00 p.m."));
|
||||
Assert.That(location, Is.Empty);
|
||||
Assert.That(locationParseSuccess, Is.True); // No location is valid
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Parse_LocationNotMatchingPattern_StillReturnsLocation_ReportsFailure()
|
||||
public void Parse_AnyLocation_ExtractsLocationWithoutValidation()
|
||||
{
|
||||
// Arrange
|
||||
var locationConfig = new LocationParsingConfiguration
|
||||
{
|
||||
LocationPatterns = new List<string> { "Room *" }
|
||||
};
|
||||
|
||||
// Act
|
||||
TimeLocationParser.Parse("10:00 a.m. Unknown Location", locationConfig,
|
||||
out string time, out string location, out bool locationParseSuccess);
|
||||
TimeLocationParser.Parse("10:00 a.m. Unknown Location",
|
||||
out string time, out string location);
|
||||
|
||||
// Assert
|
||||
Assert.That(time, Is.EqualTo("10:00 a.m."));
|
||||
Assert.That(location, Is.EqualTo("Unknown Location"));
|
||||
Assert.That(locationParseSuccess, Is.False);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Parse_LocationWithTimeComponent_CleansTimeComponent()
|
||||
{
|
||||
// Arrange
|
||||
var locationConfig = new LocationParsingConfiguration
|
||||
{
|
||||
LocationPatterns = new List<string> { "Exhibit Hall *" }
|
||||
};
|
||||
|
||||
// Act
|
||||
TimeLocationParser.Parse("10:00 a.m. - 12:15 p.m. Exhibit Hall C", locationConfig,
|
||||
out string time, out string location, out bool locationParseSuccess);
|
||||
TimeLocationParser.Parse("10:00 a.m. - 12:15 p.m. Exhibit Hall C",
|
||||
out string time, out string location);
|
||||
|
||||
// Assert
|
||||
Assert.That(time, Is.EqualTo("10:00 a.m. - 12:15 p.m."));
|
||||
@@ -121,16 +79,15 @@ public class TimeLocationParser_Tests
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Parse_NoLocationConfig_StillExtractsTimeAndLocation()
|
||||
public void Parse_AnyLocation_ExtractsAsIs()
|
||||
{
|
||||
// Act
|
||||
TimeLocationParser.Parse("3:00 p.m. Room A", null,
|
||||
out string time, out string location, out bool locationParseSuccess);
|
||||
TimeLocationParser.Parse("3:00 p.m. Room A",
|
||||
out string time, out string location);
|
||||
|
||||
// Assert
|
||||
Assert.That(time, Is.EqualTo("3:00 p.m."));
|
||||
Assert.That(location, Is.EqualTo("Room A"));
|
||||
Assert.That(locationParseSuccess, Is.False); // No patterns to match against
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
Reference in New Issue
Block a user