microsoft / Recognizers-Text

Microsoft.Recognizers.Text provides recognition and resolution of numbers, units, date/time, etc. in multiple languages (ZH, EN, FR, ES, PT, DE, IT, TR, HI, NL. Partial support for JA, KO, AR, SV). Packages available at: https://www.nuget.org/profiles/Recognizers.Text, https://www.npmjs.com/~recognizers.text
MIT License
1.68k stars 431 forks source link

[DE DateTimeV2] Fix occasionally NullReferenceException in German DateTimeModel test when input is tag der Arbeit #3175

Closed MichaelMWW closed 1 month ago

MichaelMWW commented 1 month ago

Fix occasionally NullReferenceException in German DateTimeModel test when input is tag der Arbeit, the test and message as below.

Test: Microsoft.Recognizers.Text.DateTime.Tests.TestDateTime_German DateTimeModel 

Message:  Test method Microsoft.Recognizers.Text.DateTime.Tests.TestDateTime_German.DateTimeModel threw exception: System.ApplicationException: Input: "Tag der Arbeit, ersten Weihnachtsfeiertag, zweiten Weihnachtstag" ---> System.NullReferenceException: Object reference not set to an instance of an object.

MichaelMWW commented 1 month ago

This issue only happened sometimes and this fixes it? That's strange. The corresponding test case is already in DateTimeModel?

The reason for the occasionally fail is that in line of code https://github.com/microsoft/Recognizers-Text/blob/master/.NET/Microsoft.Recognizers.Text.DateTime/German/Parsers/HolidayParserGer.cs#L578, there is a dictionary this.config.HolidayNames, it has below 3 items that contains tagderarbeit.

Then it will check the value which contains tagderarbeit from this.config.HolidayNames and return the key of the first matched item as holidayKey. So the holidayKey value can be labour/mayday/laborday, it will use the key to map from another dictionary FixedHolidaysDict. In FixedHolidaysDict, it lacks laborday, so it will leads to failure when holidayKey is laborday. When holidayKey is labour/mayday, it works fine.