Time - #444 Handle 2-digit date in existing d/m/y rule

Summary:
The pattern laied out in the bug report
https://github.com/facebook/duckling/issues/444
is actually already handled by the pattern
`<day-of-month>(ordinal or number)/<named-month>/year`.

The problem is purely that the regular expression doesn't
match 2-digit years, so the pattern is getting skipped rather
than evaluated. This diff fixes the regexp and adds a new example
with a 2-digit pattern.

This fixes the bug report:
```
> debug (makeLocale EN Nothing) "10-Apr-15" [Seal Time]
<day-of-month>(ordinal or number)/<named-month>/year (10-Apr-15)
-- integer (numeric) (10)
-- -- regex (10)
-- regex (-)
-- April (Apr)
-- -- regex (Apr)
-- regex (-)
-- regex (15)
[Entity {dim = "time", body = "10-Apr-15", value = RVal Time (TimeValue (SimpleValue (InstantValue {vValue = 2015-04-10 00:00:00 -0200, vGrain = Day})) [SimpleValue (InstantValue {vValue = 2015-04-10 00:00:00 -0200, vGrain = Day})] Nothing), start = 0, end = 9, latent = False, enode = Node {nodeRange = Range 0 9, token = Token Time TimeData{latent=False, grain=Day, form=Nothing, direction=Nothing, holiday=Nothing, hasTimezone=False}, children = [Node {nodeRange = Range 0 2, token = Token Numeral (NumeralData {value = 10.0, grain = Nothing, multipliable = False, okForAnyTime = True}), children = [Node {nodeRange = Range 0 2, token = Token RegexMatch (GroupMatch ["10"]), children = [], rule = Nothing}], rule = Just "integer (numeric)"},Node {nodeRange = Range 2 3, token = Token RegexMatch (GroupMatch []), children = [], rule = Nothing},Node {nodeRange = Range 3 6, token = Token Time TimeData{latent=False, grain=Month, form=Just (Month {month = 4}), direction=Nothing, holiday=Nothing, hasTimezone=False}, children = [Node {nodeRange = Range 3 6, token = Token RegexMatch (GroupMatch []), children = [], rule = Nothing}], rule = Just "April"},Node {nodeRange = Range 6 7, token = Token RegexMatch (GroupMatch []), children = [], rule = Nothing},Node {nodeRange = Range 7 9, token = Token RegexMatch (GroupMatch ["15"]), children = [], rule = Nothing}], rule = Just "<day-of-month>(ordinal or number)/<named-month>/year"}}]
```

Reviewed By: chessai

Differential Revision: D27106007

fbshipit-source-id: 4751672aef807464febef87f6d22d7270bd335df
This commit is contained in:
Steven Troxler 2021-03-17 10:29:56 -07:00 committed by Facebook GitHub Bot
parent 56fd7b0aaf
commit 78904b6680
2 changed files with 2 additions and 1 deletions

View File

@ -44,6 +44,7 @@ defaultCorpus = (testContext, testOptions, allExamples ++ custom)
, "10-31-74"
, "10.31.1974"
, "31/Oct/1974"
, "31-Oct-74"
, "31st Oct 1974"
]
, examples (datetime (2013, 4, 25, 16, 0, 0) Minute)

View File

@ -520,7 +520,7 @@ ruleDOMMonthYear = Rule
, regex "[-/\\s]"
, Predicate isAMonth
, regex "[-/\\s]"
, regex "(\\d{4})"
, regex "(\\d{2,4})"
]
, prod = \tokens -> case tokens of
(token: