Skip to content

Commit

Permalink
[IT DateTimeV2] Fix for time expression [minutes] minuti alle [hour]
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-gradinari committed Jan 10, 2023
1 parent 4451a53 commit f668e5c
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ public static class DateTimeDefinitions
public const string AmRegex = @"\b(?<am>((((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 = $@"(?<lth>(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 = $@"(?<lth>(un\s+quarto|tre quarti?|mezz[oa]|mezz'ora|{BaseDateTime.DeltaMinuteRegex}|{DeltaMinuteNumRegex}))";
public static readonly string EngTimeRegex = $@"(?<engtime>{HourNumRegex}\s+e\s+({MinuteNumRegex}|(?<tens>venti?|trenta?|quaranta?|cinquanta?){MinuteNumRegex}))";
public static readonly string TimePrefix = $@"(?<prefix>(e\s+{LessThanOneHour}|{LessThanOneHour}\s+(minut[oi]|min)\s+all[e']|meno {LessThanOneHour}))";
public static readonly string TimePrefix = $@"(?<prefix>((e|meno)\s+{LessThanOneHour}(\s+(minut[oi]|min))?|{LessThanOneHour}\s+(minut[oi]|min)\s+all[e']))";
public static readonly string TimeSuffix = $@"(?<suffix>{AmRegex}|{PmRegex}|{OclockRegex})";
public static readonly string BasicTime = $@"\b(?<basictime>{EngTimeRegex}|{HourNumRegex}|{BaseDateTime.HourRegex}:{BaseDateTime.MinuteRegex}(:{BaseDateTime.SecondRegex})?|{BaseDateTime.HourRegex})";
public const string MidnightRegex = @"(?<midnight>mezzanotte|mezza notte)";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions Patterns/Italian/Italian-DateTime.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,13 @@ LunchRegex: !simpleRegex
NightRegex: !simpleRegex
def: \b(mezzanotte|notte)\b
LessThanOneHour: !nestedRegex
def: (?<lth>(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: (?<lth>(un\s+quarto|tre quarti?|mezz[oa]|mezz'ora|{BaseDateTime.DeltaMinuteRegex}|{DeltaMinuteNumRegex}))
references: [ BaseDateTime.DeltaMinuteRegex, DeltaMinuteNumRegex ]
EngTimeRegex: !nestedRegex
def: (?<engtime>{HourNumRegex}\s+e\s+({MinuteNumRegex}|(?<tens>venti?|trenta?|quaranta?|cinquanta?){MinuteNumRegex}))
references: [ HourNumRegex, MinuteNumRegex ]
TimePrefix: !nestedRegex
def: (?<prefix>(e\s+{LessThanOneHour}|{LessThanOneHour}\s+(minut[oi]|min)\s+all[e']|meno {LessThanOneHour}))
def: (?<prefix>((e|meno)\s+{LessThanOneHour}(\s+(minut[oi]|min))?|{LessThanOneHour}\s+(minut[oi]|min)\s+all[e']))
references: [ LessThanOneHour ]
TimeSuffix: !nestedRegex
def: (?<suffix>{AmRegex}|{PmRegex}|{OclockRegex})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ class ItalianDateTime:
AmRegex = f'\\b(?<am>((((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'(?<lth>(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'(?<lth>(un\\s+quarto|tre quarti?|mezz[oa]|mezz\'ora|{BaseDateTime.DeltaMinuteRegex}|{DeltaMinuteNumRegex}))'
EngTimeRegex = f'(?<engtime>{HourNumRegex}\\s+e\\s+({MinuteNumRegex}|(?<tens>venti?|trenta?|quaranta?|cinquanta?){MinuteNumRegex}))'
TimePrefix = f'(?<prefix>(e\\s+{LessThanOneHour}|{LessThanOneHour}\\s+(minut[oi]|min)\\s+all[e\']|meno {LessThanOneHour}))'
TimePrefix = f'(?<prefix>((e|meno)\\s+{LessThanOneHour}(\\s+(minut[oi]|min))?|{LessThanOneHour}\\s+(minut[oi]|min)\\s+all[e\']))'
TimeSuffix = f'(?<suffix>{AmRegex}|{PmRegex}|{OclockRegex})'
BasicTime = f'\\b(?<basictime>{EngTimeRegex}|{HourNumRegex}|{BaseDateTime.HourRegex}:{BaseDateTime.MinuteRegex}(:{BaseDateTime.SecondRegex})?|{BaseDateTime.HourRegex})'
MidnightRegex = f'(?<midnight>mezzanotte|mezza notte)'
Expand Down
48 changes: 48 additions & 0 deletions Specs/DateTime/Italian/TimeExtractor.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
84 changes: 84 additions & 0 deletions Specs/DateTime/Italian/TimeParser.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit f668e5c

Please sign in to comment.