Skip to content

Commit

Permalink
Fix for German invalid dates
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-gradinari committed Apr 19, 2023
1 parent a5d3a23 commit 98c55e9
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = $@"^[.]";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Patterns/German/German-DateTime.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'^[.]'
Expand Down
11 changes: 11 additions & 0 deletions Specs/DateTime/German/DateExtractor.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
]
}
]
14 changes: 13 additions & 1 deletion Specs/DateTime/German/DatePeriodExtractor.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
]
}
]
]
52 changes: 49 additions & 3 deletions Specs/DateTime/German/DateTimeModel.json
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,6 @@
"Context": {
"ReferenceDateTime": "2016-11-07T00:00:00"
},
"NotSupported": "python",
"Results": [
{
"Text": "vom 12. januar 2016 bis zum 22.01.2016",
Expand Down Expand Up @@ -3947,7 +3946,7 @@
"Context": {
"ReferenceDateTime": "2018-11-07T00:00:00"
},
"NotSupported": "java, javascript, python",
"NotSupported": "java, javascript",
"Results": [
{
"Text": "so 27.02.2022",
Expand Down Expand Up @@ -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"
}
]
}
}
]
}
]
]

0 comments on commit 98c55e9

Please sign in to comment.