From 98c55e9162e47ba7d6200b7106de421885e80cf9 Mon Sep 17 00:00:00 2001 From: Andrew Gradinari Date: Thu, 13 Apr 2023 15:04:05 +0100 Subject: [PATCH] Fix for German invalid dates --- .../German/DateTimeDefinitions.cs | 2 +- .../datetime/resources/GermanDateTime.java | 2 +- Patterns/German/German-DateTime.yaml | 2 +- .../resources/german_date_time.py | 2 +- Specs/DateTime/German/DateExtractor.json | 11 ++++ .../DateTime/German/DatePeriodExtractor.json | 14 ++++- Specs/DateTime/German/DateTimeModel.json | 52 +++++++++++++++++-- 7 files changed, 77 insertions(+), 8 deletions(-) diff --git a/.NET/Microsoft.Recognizers.Definitions.Common/German/DateTimeDefinitions.cs b/.NET/Microsoft.Recognizers.Definitions.Common/German/DateTimeDefinitions.cs index d396075583..19a22dac48 100644 --- a/.NET/Microsoft.Recognizers.Definitions.Common/German/DateTimeDefinitions.cs +++ b/.NET/Microsoft.Recognizers.Definitions.Common/German/DateTimeDefinitions.cs @@ -104,7 +104,7 @@ public static class DateTimeDefinitions public static readonly string DateExtractor4 = $@"\b({DayRegex}\s*{MonthNumRegex}\s*{DateYearRegex})\b"; public static readonly string DateExtractor5 = $@"\b(({WeekDayRegex})(\s+|\s*,\s*))?({DayRegex}\s*[/\\\-\.]\s*({MonthNumRegex}|{MonthRegex})\s*[/\\\-\.]\s*{DateYearRegex})\b(?!\s*[/\\\-\.]\s*\d+)"; public static readonly string DateExtractor6 = $@"^[.]"; - public static readonly string DateExtractor7 = $@"({DayRegex}\s*[\.]\s*{MonthNumRegex}[\.]){BaseDateTime.CheckDecimalRegex}"; + public static readonly string DateExtractor7 = $@"\b({DayRegex}\s*[\.]\s*{MonthNumRegex}[\.]){BaseDateTime.CheckDecimalRegex}"; public static readonly string DateExtractor8 = $@"(?<=\b(am)\s+){DayRegex}[/\\\.]{MonthNumRegex}([/\\\.]{DateYearRegex})?{BaseDateTime.CheckDecimalRegex}\b"; public static readonly string DateExtractor9 = $@"\b({DayRegex}\s*/\s*{MonthNumRegex}((\s+|\s*,\s*){DateYearRegex})?){BaseDateTime.CheckDecimalRegex}\b"; public static readonly string DateExtractor10 = $@"^[.]"; diff --git a/Java/libraries/recognizers-text-date-time/src/main/java/com/microsoft/recognizers/text/datetime/resources/GermanDateTime.java b/Java/libraries/recognizers-text-date-time/src/main/java/com/microsoft/recognizers/text/datetime/resources/GermanDateTime.java index a6c7b3dda5..d46fb4fd22 100644 --- a/Java/libraries/recognizers-text-date-time/src/main/java/com/microsoft/recognizers/text/datetime/resources/GermanDateTime.java +++ b/Java/libraries/recognizers-text-date-time/src/main/java/com/microsoft/recognizers/text/datetime/resources/GermanDateTime.java @@ -276,7 +276,7 @@ public class GermanDateTime { public static final String DateExtractor6 = "^[.]" .replace("{WeekDayRegex}", WeekDayRegex); - public static final String DateExtractor7 = "({DayRegex}\\s*[\\.]\\s*{MonthNumRegex}[\\.]){BaseDateTime.CheckDecimalRegex}" + public static final String DateExtractor7 = "\\b({DayRegex}\\s*[\\.]\\s*{MonthNumRegex}[\\.]){BaseDateTime.CheckDecimalRegex}" .replace("{MonthNumRegex}", MonthNumRegex) .replace("{DayRegex}", DayRegex) .replace("{BaseDateTime.CheckDecimalRegex}", BaseDateTime.CheckDecimalRegex); diff --git a/Patterns/German/German-DateTime.yaml b/Patterns/German/German-DateTime.yaml index 9cb9f2cf99..19c2d601b9 100644 --- a/Patterns/German/German-DateTime.yaml +++ b/Patterns/German/German-DateTime.yaml @@ -218,7 +218,7 @@ DateExtractor6: !nestedRegex def: ^[.] references: [ WeekDayRegex ] DateExtractor7: !nestedRegex - def: ({DayRegex}\s*[\.]\s*{MonthNumRegex}[\.]){BaseDateTime.CheckDecimalRegex} + def: \b({DayRegex}\s*[\.]\s*{MonthNumRegex}[\.]){BaseDateTime.CheckDecimalRegex} references: [ MonthNumRegex, DayRegex, BaseDateTime.CheckDecimalRegex ] DateExtractor8: !nestedRegex def: (?<=\b(am)\s+){DayRegex}[/\\\.]{MonthNumRegex}([/\\\.]{DateYearRegex})?{BaseDateTime.CheckDecimalRegex}\b diff --git a/Python/libraries/recognizers-date-time/recognizers_date_time/resources/german_date_time.py b/Python/libraries/recognizers-date-time/recognizers_date_time/resources/german_date_time.py index 62c37728a8..a457282efe 100644 --- a/Python/libraries/recognizers-date-time/recognizers_date_time/resources/german_date_time.py +++ b/Python/libraries/recognizers-date-time/recognizers_date_time/resources/german_date_time.py @@ -97,7 +97,7 @@ class GermanDateTime: DateExtractor4 = f'\\b({DayRegex}\\s*{MonthNumRegex}\\s*{DateYearRegex})\\b' DateExtractor5 = f'\\b(({WeekDayRegex})(\\s+|\\s*,\\s*))?({DayRegex}\\s*[/\\\\\\-\\.]\\s*({MonthNumRegex}|{MonthRegex})\\s*[/\\\\\\-\\.]\\s*{DateYearRegex})\\b(?!\\s*[/\\\\\\-\\.]\\s*\\d+)' DateExtractor6 = f'^[.]' - DateExtractor7 = f'({DayRegex}\\s*[\\.]\\s*{MonthNumRegex}[\\.]){BaseDateTime.CheckDecimalRegex}' + DateExtractor7 = f'\\b({DayRegex}\\s*[\\.]\\s*{MonthNumRegex}[\\.]){BaseDateTime.CheckDecimalRegex}' DateExtractor8 = f'(?<=\\b(am)\\s+){DayRegex}[/\\\\\\.]{MonthNumRegex}([/\\\\\\.]{DateYearRegex})?{BaseDateTime.CheckDecimalRegex}\\b' DateExtractor9 = f'\\b({DayRegex}\\s*/\\s*{MonthNumRegex}((\\s+|\\s*,\\s*){DateYearRegex})?){BaseDateTime.CheckDecimalRegex}\\b' DateExtractor10 = f'^[.]' diff --git a/Specs/DateTime/German/DateExtractor.json b/Specs/DateTime/German/DateExtractor.json index 3ca097d27a..96303d29bd 100644 --- a/Specs/DateTime/German/DateExtractor.json +++ b/Specs/DateTime/German/DateExtractor.json @@ -350,5 +350,16 @@ "Length": 26 } ] + }, + { + "Input": "Mein Geburtsdatum ist der 22.04.1990", + "Results": [ + { + "Text": "der 22.04.1990", + "Type": "date", + "Start": 22, + "Length": 14 + } + ] } ] diff --git a/Specs/DateTime/German/DatePeriodExtractor.json b/Specs/DateTime/German/DatePeriodExtractor.json index 92ae29d618..73ede453f1 100644 --- a/Specs/DateTime/German/DatePeriodExtractor.json +++ b/Specs/DateTime/German/DatePeriodExtractor.json @@ -778,5 +778,17 @@ "Length": 10 } ] + }, + { + "Input": "Ich komme am 32.04.2023 wieder.", + "NotSupported": "javascript", + "Results": [ + { + "Text": "04.2023", + "Type": "daterange", + "Start": 16, + "Length": 7 + } + ] } -] \ No newline at end of file +] diff --git a/Specs/DateTime/German/DateTimeModel.json b/Specs/DateTime/German/DateTimeModel.json index 0ae05fbf12..441f6a0a38 100644 --- a/Specs/DateTime/German/DateTimeModel.json +++ b/Specs/DateTime/German/DateTimeModel.json @@ -286,7 +286,6 @@ "Context": { "ReferenceDateTime": "2016-11-07T00:00:00" }, - "NotSupported": "python", "Results": [ { "Text": "vom 12. januar 2016 bis zum 22.01.2016", @@ -3947,7 +3946,7 @@ "Context": { "ReferenceDateTime": "2018-11-07T00:00:00" }, - "NotSupported": "java, javascript, python", + "NotSupported": "java, javascript", "Results": [ { "Text": "so 27.02.2022", @@ -5641,5 +5640,52 @@ } } ] + }, + { + "Input": "Ich komme am 32.04.2023 wieder.", + "Context": { + "ReferenceDateTime": "2016-11-07T00:00:00" + }, + "Results": [ + { + "Text": "04.2023", + "Start": 16, + "End": 22, + "TypeName": "datetimeV2.daterange", + "Resolution": { + "values": [ + { + "timex": "2023-04", + "type": "daterange", + "start": "2023-04-01", + "end": "2023-05-01" + } + ] + } + } + ] + }, + { + "Input": "Mein Geburtsdatum ist der 22.04.1990", + "Context": { + "ReferenceDateTime": "2016-11-07T00:00:00" + }, + "Results": [ + { + "Text": "der 22.04.1990", + "Start": 22, + "End": 35, + "TypeName": "datetimeV2.date", + "Resolution": { + "values": [ + { + "timex": "1990-04-22", + "type": "date", + "value": "1990-04-22" + } + ] + } + } + ] } -] \ No newline at end of file +]