From f668e5c6ad6476a1b32b13c6351d992804163a04 Mon Sep 17 00:00:00 2001 From: Andrew Gradinari Date: Mon, 9 Jan 2023 12:28:45 +0000 Subject: [PATCH] [IT DateTimeV2] Fix for time expression [minutes] minuti alle [hour] --- .../Italian/DateTimeDefinitions.cs | 4 +- .../Parsers/ItalianTimeParserConfiguration.cs | 3 +- Patterns/Italian/Italian-DateTime.yaml | 4 +- .../date_time/italian/time_parser_config.py | 2 +- .../resources/italian_date_time.py | 4 +- Specs/DateTime/Italian/TimeExtractor.json | 48 +++++++++++ Specs/DateTime/Italian/TimeParser.json | 84 +++++++++++++++++++ 7 files changed, 141 insertions(+), 8 deletions(-) diff --git a/.NET/Microsoft.Recognizers.Definitions.Common/Italian/DateTimeDefinitions.cs b/.NET/Microsoft.Recognizers.Definitions.Common/Italian/DateTimeDefinitions.cs index 0cbbea1377..cbc9673959 100644 --- a/.NET/Microsoft.Recognizers.Definitions.Common/Italian/DateTimeDefinitions.cs +++ b/.NET/Microsoft.Recognizers.Definitions.Common/Italian/DateTimeDefinitions.cs @@ -139,9 +139,9 @@ public static class DateTimeDefinitions public const string AmRegex = @"\b(?((((la|alla|verso|per|della|di|in)\s+(la\s+)?)?(mattinata|mattina))|(((il|al|verso|per|del|di)\s+(il\s+)?)?(mattino))))\b"; public const string LunchRegex = @"\b(ora di pranzo)\b"; public const string NightRegex = @"\b(mezzanotte|notte)\b"; - public static readonly string LessThanOneHour = $@"(?(un\s+quarto|tre quarti?|mezz[oa]|mezz'ora|{BaseDateTime.DeltaMinuteRegex}(\s+(minut[oi]|min))?|{DeltaMinuteNumRegex}(\s+(minut[oi]|min))|(?<=(e|meno)\s+){DeltaMinuteNumRegex}))"; + public static readonly string LessThanOneHour = $@"(?(un\s+quarto|tre quarti?|mezz[oa]|mezz'ora|{BaseDateTime.DeltaMinuteRegex}|{DeltaMinuteNumRegex}))"; public static readonly string EngTimeRegex = $@"(?{HourNumRegex}\s+e\s+({MinuteNumRegex}|(?venti?|trenta?|quaranta?|cinquanta?){MinuteNumRegex}))"; - public static readonly string TimePrefix = $@"(?(e\s+{LessThanOneHour}|{LessThanOneHour}\s+(minut[oi]|min)\s+all[e']|meno {LessThanOneHour}))"; + public static readonly string TimePrefix = $@"(?((e|meno)\s+{LessThanOneHour}(\s+(minut[oi]|min))?|{LessThanOneHour}\s+(minut[oi]|min)\s+all[e']))"; public static readonly string TimeSuffix = $@"(?{AmRegex}|{PmRegex}|{OclockRegex})"; public static readonly string BasicTime = $@"\b(?{EngTimeRegex}|{HourNumRegex}|{BaseDateTime.HourRegex}:{BaseDateTime.MinuteRegex}(:{BaseDateTime.SecondRegex})?|{BaseDateTime.HourRegex})"; public const string MidnightRegex = @"(?mezzanotte|mezza notte)"; diff --git a/.NET/Microsoft.Recognizers.Text.DateTime/Italian/Parsers/ItalianTimeParserConfiguration.cs b/.NET/Microsoft.Recognizers.Text.DateTime/Italian/Parsers/ItalianTimeParserConfiguration.cs index 07558ac58f..2cef97b99a 100644 --- a/.NET/Microsoft.Recognizers.Text.DateTime/Italian/Parsers/ItalianTimeParserConfiguration.cs +++ b/.NET/Microsoft.Recognizers.Text.DateTime/Italian/Parsers/ItalianTimeParserConfiguration.cs @@ -81,7 +81,8 @@ public void AdjustByPrefix(string prefix, ref int hour, ref int min, ref bool ha } // 'to' i.e 'one to five' - if (trimmedPrefix.StartsWith("meno", StringComparison.Ordinal)) + if (trimmedPrefix.StartsWith("meno", StringComparison.Ordinal) || + trimmedPrefix.EndsWith("alle", StringComparison.Ordinal)) { deltaMin = -deltaMin; } diff --git a/Patterns/Italian/Italian-DateTime.yaml b/Patterns/Italian/Italian-DateTime.yaml index 9085adec71..64b9c2186f 100644 --- a/Patterns/Italian/Italian-DateTime.yaml +++ b/Patterns/Italian/Italian-DateTime.yaml @@ -303,13 +303,13 @@ LunchRegex: !simpleRegex NightRegex: !simpleRegex def: \b(mezzanotte|notte)\b LessThanOneHour: !nestedRegex - def: (?(un\s+quarto|tre quarti?|mezz[oa]|mezz'ora|{BaseDateTime.DeltaMinuteRegex}(\s+(minut[oi]|min))?|{DeltaMinuteNumRegex}(\s+(minut[oi]|min))|(?<=(e|meno)\s+){DeltaMinuteNumRegex})) + def: (?(un\s+quarto|tre quarti?|mezz[oa]|mezz'ora|{BaseDateTime.DeltaMinuteRegex}|{DeltaMinuteNumRegex})) references: [ BaseDateTime.DeltaMinuteRegex, DeltaMinuteNumRegex ] EngTimeRegex: !nestedRegex def: (?{HourNumRegex}\s+e\s+({MinuteNumRegex}|(?venti?|trenta?|quaranta?|cinquanta?){MinuteNumRegex})) references: [ HourNumRegex, MinuteNumRegex ] TimePrefix: !nestedRegex - def: (?(e\s+{LessThanOneHour}|{LessThanOneHour}\s+(minut[oi]|min)\s+all[e']|meno {LessThanOneHour})) + def: (?((e|meno)\s+{LessThanOneHour}(\s+(minut[oi]|min))?|{LessThanOneHour}\s+(minut[oi]|min)\s+all[e'])) references: [ LessThanOneHour ] TimeSuffix: !nestedRegex def: (?{AmRegex}|{PmRegex}|{OclockRegex}) diff --git a/Python/libraries/recognizers-date-time/recognizers_date_time/date_time/italian/time_parser_config.py b/Python/libraries/recognizers-date-time/recognizers_date_time/date_time/italian/time_parser_config.py index b5d735b54b..a34d3e2510 100644 --- a/Python/libraries/recognizers-date-time/recognizers_date_time/date_time/italian/time_parser_config.py +++ b/Python/libraries/recognizers-date-time/recognizers_date_time/date_time/italian/time_parser_config.py @@ -76,7 +76,7 @@ def adjust_by_prefix(self, prefix: str, adjust: AdjustParams): match, 'deltaminnum').lower() delta_min = self.numbers.get(min_str) - if trimmed_prefix.startswith('meno'): + if trimmed_prefix.startswith('meno') or trimmed_prefix.endswith('alle'): delta_min = delta_min * -1 adjust.minute += delta_min diff --git a/Python/libraries/recognizers-date-time/recognizers_date_time/resources/italian_date_time.py b/Python/libraries/recognizers-date-time/recognizers_date_time/resources/italian_date_time.py index 13741926eb..6469568b67 100644 --- a/Python/libraries/recognizers-date-time/recognizers_date_time/resources/italian_date_time.py +++ b/Python/libraries/recognizers-date-time/recognizers_date_time/resources/italian_date_time.py @@ -132,9 +132,9 @@ class ItalianDateTime: AmRegex = f'\\b(?((((la|alla|verso|per|della|di|in)\\s+(la\\s+)?)?(mattinata|mattina))|(((il|al|verso|per|del|di)\\s+(il\\s+)?)?(mattino))))\\b' LunchRegex = f'\\b(ora di pranzo)\\b' NightRegex = f'\\b(mezzanotte|notte)\\b' - LessThanOneHour = f'(?(un\\s+quarto|tre quarti?|mezz[oa]|mezz\'ora|{BaseDateTime.DeltaMinuteRegex}(\\s+(minut[oi]|min))?|{DeltaMinuteNumRegex}(\\s+(minut[oi]|min))|(?<=(e|meno)\\s+){DeltaMinuteNumRegex}))' + LessThanOneHour = f'(?(un\\s+quarto|tre quarti?|mezz[oa]|mezz\'ora|{BaseDateTime.DeltaMinuteRegex}|{DeltaMinuteNumRegex}))' EngTimeRegex = f'(?{HourNumRegex}\\s+e\\s+({MinuteNumRegex}|(?venti?|trenta?|quaranta?|cinquanta?){MinuteNumRegex}))' - TimePrefix = f'(?(e\\s+{LessThanOneHour}|{LessThanOneHour}\\s+(minut[oi]|min)\\s+all[e\']|meno {LessThanOneHour}))' + TimePrefix = f'(?((e|meno)\\s+{LessThanOneHour}(\\s+(minut[oi]|min))?|{LessThanOneHour}\\s+(minut[oi]|min)\\s+all[e\']))' TimeSuffix = f'(?{AmRegex}|{PmRegex}|{OclockRegex})' BasicTime = f'\\b(?{EngTimeRegex}|{HourNumRegex}|{BaseDateTime.HourRegex}:{BaseDateTime.MinuteRegex}(:{BaseDateTime.SecondRegex})?|{BaseDateTime.HourRegex})' MidnightRegex = f'(?mezzanotte|mezza notte)' diff --git a/Specs/DateTime/Italian/TimeExtractor.json b/Specs/DateTime/Italian/TimeExtractor.json index 95d8075b88..8c4fd4fbde 100644 --- a/Specs/DateTime/Italian/TimeExtractor.json +++ b/Specs/DateTime/Italian/TimeExtractor.json @@ -263,6 +263,54 @@ } ] }, + { + "Input": "Mancano 5 minuti alle 4", + "NotSupportedByDesign": "java,javascript", + "Results": [ + { + "Text": "5 minuti alle 4", + "Type": "time", + "Start": 8, + "Length": 15 + } + ] + }, + { + "Input": "Mancano 10 minuti alle quattro", + "NotSupportedByDesign": "java,javascript", + "Results": [ + { + "Text": "10 minuti alle quattro", + "Type": "time", + "Start": 8, + "Length": 22 + } + ] + }, + { + "Input": "Mancano cinque minuti alle 14", + "NotSupportedByDesign": "java,javascript", + "Results": [ + { + "Text": "cinque minuti alle 14", + "Type": "time", + "Start": 8, + "Length": 21 + } + ] + }, + { + "Input": "Mancano dieci minuti alle otto", + "NotSupportedByDesign": "java,javascript", + "Results": [ + { + "Text": "dieci minuti alle otto", + "Type": "time", + "Start": 8, + "Length": 22 + } + ] + }, { "Input": "Sono le sette e mezza", "NotSupportedByDesign": "javascript", diff --git a/Specs/DateTime/Italian/TimeParser.json b/Specs/DateTime/Italian/TimeParser.json index ad67f51a90..ec7177dfef 100644 --- a/Specs/DateTime/Italian/TimeParser.json +++ b/Specs/DateTime/Italian/TimeParser.json @@ -566,6 +566,90 @@ } ] }, + { + "Input": "Mancano 5 minuti alle 4", + "NotSupportedByDesign": "java,javascript", + "Results": [ + { + "Text": "5 minuti alle 4", + "Type": "time", + "Value": { + "Timex": "T03:55", + "FutureResolution": { + "time": "03:55:00" + }, + "PastResolution": { + "time": "03:55:00" + } + }, + "Start": 8, + "Length": 15 + } + ] + }, + { + "Input": "Mancano 10 minuti alle quattro", + "NotSupportedByDesign": "java,javascript", + "Results": [ + { + "Text": "10 minuti alle quattro", + "Type": "time", + "Value": { + "Timex": "T03:50", + "FutureResolution": { + "time": "03:50:00" + }, + "PastResolution": { + "time": "03:50:00" + } + }, + "Start": 8, + "Length": 22 + } + ] + }, + { + "Input": "Mancano cinque minuti alle 14", + "NotSupportedByDesign": "java,javascript", + "Results": [ + { + "Text": "cinque minuti alle 14", + "Type": "time", + "Value": { + "Timex": "T13:55", + "FutureResolution": { + "time": "13:55:00" + }, + "PastResolution": { + "time": "13:55:00" + } + }, + "Start": 8, + "Length": 21 + } + ] + }, + { + "Input": "Mancano dieci minuti alle otto", + "NotSupportedByDesign": "java,javascript", + "Results": [ + { + "Text": "dieci minuti alle otto", + "Type": "time", + "Value": { + "Timex": "T07:50", + "FutureResolution": { + "time": "07:50:00" + }, + "PastResolution": { + "time": "07:50:00" + } + }, + "Start": 8, + "Length": 22 + } + ] + }, { "Input": "Sono le sette e mezza", "NotSupportedByDesign": "javascript",