Generalize mm/dd rules to accept spaces like '05 / 27', '05/ 27'

Summary:
The existing "mm/dd" rules only accepts format like "05/27"; However, in practice there might be extra spaces like "05 / 27", "05/ 27". The pull requests tweaks the regex to accept extra space.
Closes https://github.com/facebookincubator/duckling/pull/31

Reviewed By: niteria

Differential Revision: D5147118

Pulled By: patapizza

fbshipit-source-id: f6a5069
This commit is contained in:
chao pan 2017-05-30 09:19:47 -07:00 committed by Facebook Github Bot
parent 92a3e16886
commit 292a94128f
3 changed files with 8 additions and 8 deletions

View File

@ -59,11 +59,11 @@ classifiers
likelihoods = HashMap.fromList [], n = 0}}),
("integer (numeric)",
Classifier{okData =
ClassData{prior = -0.840653317668535, unseen = -5.030437921392435,
ClassData{prior = -0.8463513387831728, unseen = -5.030437921392435,
likelihoods = HashMap.fromList [("", 0.0)], n = 151},
koData =
ClassData{prior = -0.5646283297589669, unseen = -5.303304908059076,
likelihoods = HashMap.fromList [("", 0.0)], n = 199}}),
ClassData{prior = -0.5603262675390213, unseen = -5.313205979041787,
likelihoods = HashMap.fromList [("", 0.0)], n = 201}}),
("<duration> hence|ago",
Classifier{okData =
ClassData{prior = 0.0, unseen = -3.784189633918261,
@ -225,11 +225,10 @@ classifiers
likelihoods = HashMap.fromList [], n = 0}}),
("mm/dd",
Classifier{okData =
ClassData{prior = -1.6739764335716716,
unseen = -1.6094379124341003,
likelihoods = HashMap.fromList [("", 0.0)], n = 3},
ClassData{prior = -1.4469189829363254, unseen = -1.791759469228055,
likelihoods = HashMap.fromList [("", 0.0)], n = 4},
koData =
ClassData{prior = -0.2076393647782445, unseen = -2.70805020110221,
ClassData{prior = -0.2682639865946794, unseen = -2.70805020110221,
likelihoods = HashMap.fromList [("", 0.0)], n = 13}}),
("at <time-of-day>",
Classifier{okData =

View File

@ -116,6 +116,7 @@ allExamples = concat
, "2/15"
, "on 2/15"
, "February 15"
, "2 / 15"
]
, examples (datetime (2013, 8, 8, 0, 0, 0) Day)
["Aug 8"]

View File

@ -699,7 +699,7 @@ ruleYYYYMMDD = Rule
ruleMMDD :: Rule
ruleMMDD = Rule
{ name = "mm/dd"
, pattern = [regex "(0?[1-9]|1[0-2])/(3[01]|[12]\\d|0?[1-9])"]
, pattern = [regex "(0?[1-9]|1[0-2])\\s?/\\s?(3[01]|[12]\\d|0?[1-9])"]
, prod = \tokens -> case tokens of
(Token RegexMatch (GroupMatch (mm:dd:_)):_) -> do
m <- parseInt mm