Skip to content

Commit 1ab5f44

Browse files
patapizzafacebook-github-bot
authored andcommitted
en_CA + fix Canadian Thanksgiving
Summary: * `en_CA` locale * In Canada, Thanksgiving Day is the second Monday of October. * Black Friday is the same as the US. * However Canada observes both DDMM and MMDD formats. Defer to later, falling back to US. Reviewed By: blandinw Differential Revision: D6058909 fbshipit-source-id: 3d4e05e
1 parent fb1dcaa commit 1ab5f44

File tree

16 files changed

+2580
-76
lines changed

16 files changed

+2580
-76
lines changed

Duckling/Locale.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ instance TextShow Lang where
6969
-- | ISO 3166-1 alpha-2 Country code (includes regions and territories).
7070
-- See https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
7171
data Region
72-
= CN
72+
= CA
73+
| CN
7374
| GB
7475
| HK
7576
| MO
@@ -100,6 +101,6 @@ makeLocale lang (Just region)
100101

101102
allLocales :: HashMap Lang (HashSet Region)
102103
allLocales = HashMap.fromList
103-
[ (EN, HashSet.fromList [GB, US])
104+
[ (EN, HashSet.fromList [CA, GB, US])
104105
, (ZH, HashSet.fromList [CN, HK, MO, TW])
105106
]

Duckling/Ranking/Classifiers/EN_CA.hs

Lines changed: 2349 additions & 0 deletions
Large diffs are not rendered by default.

Duckling/Rules/EN.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import qualified Duckling.Ordinal.EN.Rules as Ordinal
2929
import qualified Duckling.Quantity.EN.Rules as Quantity
3030
import qualified Duckling.Temperature.EN.Rules as Temperature
3131
import qualified Duckling.Time.EN.Rules as Time
32+
import qualified Duckling.Time.EN.CA.Rules as TimeCA
3233
import qualified Duckling.Time.EN.GB.Rules as TimeGB
3334
import qualified Duckling.Time.EN.US.Rules as TimeUS
3435
import qualified Duckling.TimeGrain.EN.Rules as TimeGrain
@@ -38,10 +39,12 @@ defaultRules :: Some Dimension -> [Rule]
3839
defaultRules dim@(This Time) =
3940
[ TimeUS.ruleMMDD
4041
, TimeUS.ruleMMDDYYYY
42+
, TimeUS.ruleThanksgiving
4143
] ++ langRules dim
4244
defaultRules dim = langRules dim
4345

4446
localeRules :: Region -> Some Dimension -> [Rule]
47+
localeRules CA (This Time) = TimeCA.rules
4548
localeRules GB (This Time) = TimeGB.rules
4649
localeRules US (This Time) = TimeUS.rules
4750
localeRules _ _ = []

Duckling/Time/EN/CA/Corpus.hs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
-- Copyright (c) 2016-present, Facebook, Inc.
2+
-- All rights reserved.
3+
--
4+
-- This source code is licensed under the BSD-style license found in the
5+
-- LICENSE file in the root directory of this source tree. An additional grant
6+
-- of patent rights can be found in the PATENTS file in the same directory.
7+
8+
{-# LANGUAGE OverloadedStrings #-}
9+
10+
module Duckling.Time.EN.CA.Corpus
11+
( allExamples
12+
) where
13+
14+
import Data.String
15+
import Prelude
16+
17+
import Duckling.Testing.Types hiding (examples)
18+
import Duckling.Time.Corpus
19+
import Duckling.Time.Types hiding (Month)
20+
import Duckling.TimeGrain.Types hiding (add)
21+
22+
allExamples :: [Example]
23+
allExamples = concat
24+
[ examples (datetime (2013, 2, 15, 0, 0, 0) Day)
25+
[ "2/15"
26+
, "on 2/15"
27+
, "2 / 15"
28+
, "2-15"
29+
, "2 - 15"
30+
]
31+
, examples (datetime (1974, 10, 31, 0, 0, 0) Day)
32+
[ "10/31/1974"
33+
, "10/31/74"
34+
, "10-31-74"
35+
]
36+
, examples (datetime (2013, 4, 25, 16, 0, 0) Minute)
37+
[ "4/25 at 4:00pm"
38+
]
39+
, examples (datetime (2013, 10, 14, 0, 0, 0) Day)
40+
[ "thanksgiving day"
41+
, "thanksgiving"
42+
, "thanksgiving 2013"
43+
, "this thanksgiving"
44+
, "next thanksgiving day"
45+
]
46+
, examples (datetime (2014, 10, 13, 0, 0, 0) Day)
47+
[ "thanksgiving of next year"
48+
, "thanksgiving 2014"
49+
]
50+
, examples (datetime (2012, 10, 8, 0, 0, 0) Day)
51+
[ "last thanksgiving"
52+
, "thanksgiving day 2012"
53+
]
54+
, examples (datetime (2016, 10, 10, 0, 0, 0) Day)
55+
[ "thanksgiving 2016"
56+
]
57+
, examples (datetime (2017, 10, 9, 0, 0, 0) Day)
58+
[ "thanksgiving 2017"
59+
]
60+
]

Duckling/Time/EN/CA/Rules.hs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
-- Copyright (c) 2016-present, Facebook, Inc.
2+
-- All rights reserved.
3+
--
4+
-- This source code is licensed under the BSD-style license found in the
5+
-- LICENSE file in the root directory of this source tree. An additional grant
6+
-- of patent rights can be found in the PATENTS file in the same directory.
7+
8+
9+
{-# LANGUAGE GADTs #-}
10+
{-# LANGUAGE NoRebindableSyntax #-}
11+
{-# LANGUAGE OverloadedStrings #-}
12+
13+
module Duckling.Time.EN.CA.Rules
14+
( rules
15+
) where
16+
17+
import Data.Maybe
18+
import Prelude
19+
20+
import Duckling.Dimensions.Types
21+
import Duckling.Numeral.Helpers (parseInt)
22+
import Duckling.Regex.Types
23+
import Duckling.Time.Helpers
24+
import Duckling.Time.Types (TimeData (..))
25+
import Duckling.Types
26+
27+
-- Although one can see both MMDD and DDMM in Canada,
28+
-- there is no direct way to implement this today. Let's fallback to MMDD (US).
29+
ruleMMDD :: Rule
30+
ruleMMDD = Rule
31+
{ name = "mm/dd"
32+
, pattern = [regex "(0?[1-9]|1[0-2])\\s?[/-]\\s?(3[01]|[12]\\d|0?[1-9])"]
33+
, prod = \tokens -> case tokens of
34+
(Token RegexMatch (GroupMatch (mm:dd:_)):_) -> do
35+
m <- parseInt mm
36+
d <- parseInt dd
37+
tt $ monthDay m d
38+
_ -> Nothing
39+
}
40+
41+
ruleMMDDYYYY :: Rule
42+
ruleMMDDYYYY = Rule
43+
{ name = "mm/dd/yyyy"
44+
, pattern =
45+
[regex "(0?[1-9]|1[0-2])[/-](3[01]|[12]\\d|0?[1-9])[-/](\\d{2,4})"]
46+
, prod = \tokens -> case tokens of
47+
(Token RegexMatch (GroupMatch (mm:dd:yy:_)):_) -> do
48+
y <- parseInt yy
49+
m <- parseInt mm
50+
d <- parseInt dd
51+
tt $ yearMonthDay y m d
52+
_ -> Nothing
53+
}
54+
55+
ruleThanksgiving :: Rule
56+
ruleThanksgiving = Rule
57+
{ name = "Thanksgiving Day"
58+
, pattern =
59+
[ regex "thanks?giving( day)?"
60+
]
61+
, prod = \_ -> tt $ nthDOWOfMonth 2 1 10 -- Second Monday of October
62+
}
63+
64+
rules :: [Rule]
65+
rules =
66+
[ ruleMMDD
67+
, ruleMMDDYYYY
68+
, ruleThanksgiving
69+
]

Duckling/Time/EN/Corpus.hs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,27 @@ defaultCorpus = (testContext, allExamples ++ custom)
4444
, examples (datetime (2013, 4, 25, 16, 0, 0) Minute)
4545
[ "4/25 at 4:00pm"
4646
]
47+
, examples (datetime (2013, 11, 28, 0, 0, 0) Day)
48+
[ "thanksgiving day"
49+
, "thanksgiving"
50+
, "thanksgiving 2013"
51+
, "this thanksgiving"
52+
, "next thanksgiving day"
53+
]
54+
, examples (datetime (2014, 11, 27, 0, 0, 0) Day)
55+
[ "thanksgiving of next year"
56+
, "thanksgiving 2014"
57+
]
58+
, examples (datetime (2012, 11, 22, 0, 0, 0) Day)
59+
[ "last thanksgiving"
60+
, "thanksgiving day 2012"
61+
]
62+
, examples (datetime (2016, 11, 24, 0, 0, 0) Day)
63+
[ "thanksgiving 2016"
64+
]
65+
, examples (datetime (2017, 11, 23, 0, 0, 0) Day)
66+
[ "thanksgiving 2017"
67+
]
4768
]
4869

4970
negativeCorpus :: NegativeCorpus
@@ -613,27 +634,6 @@ allExamples = concat
613634
, "next halloween"
614635
, "Halloween 2013"
615636
]
616-
, examples (datetime (2013, 11, 28, 0, 0, 0) Day)
617-
[ "thanksgiving day"
618-
, "thanksgiving"
619-
, "thanksgiving 2013"
620-
, "this thanksgiving"
621-
, "next thanksgiving day"
622-
]
623-
, examples (datetime (2014, 11, 27, 0, 0, 0) Day)
624-
[ "thanksgiving of next year"
625-
, "thanksgiving 2014"
626-
]
627-
, examples (datetime (2012, 11, 22, 0, 0, 0) Day)
628-
[ "last thanksgiving"
629-
, "thanksgiving day 2012"
630-
]
631-
, examples (datetime (2016, 11, 24, 0, 0, 0) Day)
632-
[ "thanksgiving 2016"
633-
]
634-
, examples (datetime (2017, 11, 23, 0, 0, 0) Day)
635-
[ "thanksgiving 2017"
636-
]
637637
, examples (datetime (2013, 11, 29, 0, 0, 0) Day)
638638
[ "black friday"
639639
, "black friday of this year"

Duckling/Time/EN/GB/Corpus.hs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,25 @@ allExamples = concat
3636
, examples (datetime (2013, 4, 25, 16, 0, 0) Minute)
3737
[ "25/4 at 4:00pm"
3838
]
39+
, examples (datetime (2013, 11, 28, 0, 0, 0) Day)
40+
[ "thanksgiving day"
41+
, "thanksgiving"
42+
, "thanksgiving 2013"
43+
, "this thanksgiving"
44+
, "next thanksgiving day"
45+
]
46+
, examples (datetime (2014, 11, 27, 0, 0, 0) Day)
47+
[ "thanksgiving of next year"
48+
, "thanksgiving 2014"
49+
]
50+
, examples (datetime (2012, 11, 22, 0, 0, 0) Day)
51+
[ "last thanksgiving"
52+
, "thanksgiving day 2012"
53+
]
54+
, examples (datetime (2016, 11, 24, 0, 0, 0) Day)
55+
[ "thanksgiving 2016"
56+
]
57+
, examples (datetime (2017, 11, 23, 0, 0, 0) Day)
58+
[ "thanksgiving 2017"
59+
]
3960
]

Duckling/Time/EN/GB/Rules.hs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,18 @@ ruleDDMMYYYY = Rule
5353
_ -> Nothing
5454
}
5555

56+
ruleThanksgiving :: Rule
57+
ruleThanksgiving = Rule
58+
{ name = "Thanksgiving Day"
59+
, pattern =
60+
[ regex "thanks?giving( day)?"
61+
]
62+
, prod = \_ -> tt $ nthDOWOfMonth 4 4 11 -- Fourth Thursday of November
63+
}
64+
5665
rules :: [Rule]
5766
rules =
5867
[ ruleDDMM
5968
, ruleDDMMYYYY
69+
, ruleThanksgiving
6070
]

Duckling/Time/EN/Rules.hs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,10 +1264,6 @@ moreUSHolidays =
12641264
, "mother'?s?'? day"
12651265
, 2, 7, 5
12661266
)
1267-
, ( "Thanksgiving Day" -- Fourth Thursday of November
1268-
, "thanks?giving( day)?"
1269-
, 4, 4, 11
1270-
)
12711267
, ( "Labor Day" -- First Monday of September
12721268
, "labor day"
12731269
, 1, 1, 9

Duckling/Time/EN/US/Corpus.hs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,25 @@ allExamples = concat
3636
, examples (datetime (2013, 4, 25, 16, 0, 0) Minute)
3737
[ "4/25 at 4:00pm"
3838
]
39+
, examples (datetime (2013, 11, 28, 0, 0, 0) Day)
40+
[ "thanksgiving day"
41+
, "thanksgiving"
42+
, "thanksgiving 2013"
43+
, "this thanksgiving"
44+
, "next thanksgiving day"
45+
]
46+
, examples (datetime (2014, 11, 27, 0, 0, 0) Day)
47+
[ "thanksgiving of next year"
48+
, "thanksgiving 2014"
49+
]
50+
, examples (datetime (2012, 11, 22, 0, 0, 0) Day)
51+
[ "last thanksgiving"
52+
, "thanksgiving day 2012"
53+
]
54+
, examples (datetime (2016, 11, 24, 0, 0, 0) Day)
55+
[ "thanksgiving 2016"
56+
]
57+
, examples (datetime (2017, 11, 23, 0, 0, 0) Day)
58+
[ "thanksgiving 2017"
59+
]
3960
]

0 commit comments

Comments
 (0)