2017-03-08 21:33:55 +03:00
|
|
|
-- Copyright (c) 2016-present, Facebook, Inc.
|
|
|
|
-- All rights reserved.
|
|
|
|
--
|
|
|
|
-- This source code is licensed under the BSD-style license found in the
|
2019-05-22 20:36:43 +03:00
|
|
|
-- LICENSE file in the root directory of this source tree.
|
2017-03-08 21:33:55 +03:00
|
|
|
|
|
|
|
|
|
|
|
{-# LANGUAGE GADTs #-}
|
2018-01-30 03:41:23 +03:00
|
|
|
|
2017-03-08 21:33:55 +03:00
|
|
|
|
|
|
|
module Duckling.Rules.EN
|
Locales support
Summary:
* Locales support for the library, following `<Lang>_<Region>` with ISO 639-1 code for `<Lang>` and ISO 3166-1 alpha-2 code for `<Region>` (#33)
* `Locale` opaque type (composite of `Lang` and `Region`) with `makeLocale` smart constructor to only allow valid `(Lang, Region)` combinations
* API: `Context`'s `lang` parameter has been replaced by `locale`, with optional `Region` and backward compatibility.
* `Rules/<Lang>.hs` exposes
- `langRules`: cross-locale rules for `<Lang>`, from `<Dimension>/<Lang>/Rules.hs`
- `localeRules`: locale-specific rules, from `<Dimension>/<Lang>/<Region>/Rules.hs`
- `defaultRules`: `langRules` + specific rules from select locales to ensure backward-compatibility
* Corpus, tests & classifiers
- 1 classifier per locale, with default classifier (`<Lang>_XX`) when no locale provided (backward-compatible)
- Default classifiers are built on existing corpus
- Locale classifiers are built on
- `<Dimension>/<Lang>/Corpus.hs` exposes a common `corpus` to all locales of `<Lang>`
- `<Dimension>/<Lang>/<Region>/Corpus.hs` exposes `allExamples`: a list of examples specific to the locale (following `<Dimension>/<Lang>/<Region>/Rules.hs`).
- Locale classifiers use the language corpus extended with the locale examples as training set.
- Locale examples need to use the same `Context` (i.e. reference time) as the language corpus.
- For backward compatibility, `<Dimension>/<Lang>/Corpus.hs` can expose also `defaultCorpus`, which is `corpus` augmented with specific examples. This is controlled by `getDefaultCorpusForLang` in `Duckling.Ranking.Generate`.
- Tests run against each classifier to make sure runtime works as expected.
* MM/DD (en_US) vs DD/MM (en_GB) example to illustrate
Reviewed By: JonCoens, blandinw
Differential Revision: D6038096
fbshipit-source-id: f29c28d
2017-10-13 18:15:32 +03:00
|
|
|
( defaultRules
|
|
|
|
, langRules
|
|
|
|
, localeRules
|
2017-03-08 21:33:55 +03:00
|
|
|
) where
|
|
|
|
|
Locales support
Summary:
* Locales support for the library, following `<Lang>_<Region>` with ISO 639-1 code for `<Lang>` and ISO 3166-1 alpha-2 code for `<Region>` (#33)
* `Locale` opaque type (composite of `Lang` and `Region`) with `makeLocale` smart constructor to only allow valid `(Lang, Region)` combinations
* API: `Context`'s `lang` parameter has been replaced by `locale`, with optional `Region` and backward compatibility.
* `Rules/<Lang>.hs` exposes
- `langRules`: cross-locale rules for `<Lang>`, from `<Dimension>/<Lang>/Rules.hs`
- `localeRules`: locale-specific rules, from `<Dimension>/<Lang>/<Region>/Rules.hs`
- `defaultRules`: `langRules` + specific rules from select locales to ensure backward-compatibility
* Corpus, tests & classifiers
- 1 classifier per locale, with default classifier (`<Lang>_XX`) when no locale provided (backward-compatible)
- Default classifiers are built on existing corpus
- Locale classifiers are built on
- `<Dimension>/<Lang>/Corpus.hs` exposes a common `corpus` to all locales of `<Lang>`
- `<Dimension>/<Lang>/<Region>/Corpus.hs` exposes `allExamples`: a list of examples specific to the locale (following `<Dimension>/<Lang>/<Region>/Rules.hs`).
- Locale classifiers use the language corpus extended with the locale examples as training set.
- Locale examples need to use the same `Context` (i.e. reference time) as the language corpus.
- For backward compatibility, `<Dimension>/<Lang>/Corpus.hs` can expose also `defaultCorpus`, which is `corpus` augmented with specific examples. This is controlled by `getDefaultCorpusForLang` in `Duckling.Ranking.Generate`.
- Tests run against each classifier to make sure runtime works as expected.
* MM/DD (en_US) vs DD/MM (en_GB) example to illustrate
Reviewed By: JonCoens, blandinw
Differential Revision: D6038096
fbshipit-source-id: f29c28d
2017-10-13 18:15:32 +03:00
|
|
|
import Prelude
|
|
|
|
|
2017-03-08 21:33:55 +03:00
|
|
|
import Duckling.Dimensions.Types
|
Locales support
Summary:
* Locales support for the library, following `<Lang>_<Region>` with ISO 639-1 code for `<Lang>` and ISO 3166-1 alpha-2 code for `<Region>` (#33)
* `Locale` opaque type (composite of `Lang` and `Region`) with `makeLocale` smart constructor to only allow valid `(Lang, Region)` combinations
* API: `Context`'s `lang` parameter has been replaced by `locale`, with optional `Region` and backward compatibility.
* `Rules/<Lang>.hs` exposes
- `langRules`: cross-locale rules for `<Lang>`, from `<Dimension>/<Lang>/Rules.hs`
- `localeRules`: locale-specific rules, from `<Dimension>/<Lang>/<Region>/Rules.hs`
- `defaultRules`: `langRules` + specific rules from select locales to ensure backward-compatibility
* Corpus, tests & classifiers
- 1 classifier per locale, with default classifier (`<Lang>_XX`) when no locale provided (backward-compatible)
- Default classifiers are built on existing corpus
- Locale classifiers are built on
- `<Dimension>/<Lang>/Corpus.hs` exposes a common `corpus` to all locales of `<Lang>`
- `<Dimension>/<Lang>/<Region>/Corpus.hs` exposes `allExamples`: a list of examples specific to the locale (following `<Dimension>/<Lang>/<Region>/Rules.hs`).
- Locale classifiers use the language corpus extended with the locale examples as training set.
- Locale examples need to use the same `Context` (i.e. reference time) as the language corpus.
- For backward compatibility, `<Dimension>/<Lang>/Corpus.hs` can expose also `defaultCorpus`, which is `corpus` augmented with specific examples. This is controlled by `getDefaultCorpusForLang` in `Duckling.Ranking.Generate`.
- Tests run against each classifier to make sure runtime works as expected.
* MM/DD (en_US) vs DD/MM (en_GB) example to illustrate
Reviewed By: JonCoens, blandinw
Differential Revision: D6038096
fbshipit-source-id: f29c28d
2017-10-13 18:15:32 +03:00
|
|
|
import Duckling.Locale
|
|
|
|
import Duckling.Types
|
2017-03-17 00:34:53 +03:00
|
|
|
import qualified Duckling.AmountOfMoney.EN.Rules as AmountOfMoney
|
Implement handling of "grand" for EN_?? locales
Summary: Add implementation of "a grand" and "<num> grand" for AU, BZ, CA, GB, IE, IN, JM, NZ, PH, TT, ZA locales. Some resolve to the local currency (AU, IN), others resolve to Dollar (NZ, PH).
Reviewed By: patapizza
Differential Revision: D7943186
fbshipit-source-id: c71ab462fa9df0ee65223ee82dc2c98457a4e13b
2018-05-18 01:37:01 +03:00
|
|
|
import qualified Duckling.AmountOfMoney.EN.AU.Rules as AmountOfMoneyAU
|
|
|
|
import qualified Duckling.AmountOfMoney.EN.BZ.Rules as AmountOfMoneyBZ
|
2018-05-10 00:22:28 +03:00
|
|
|
import qualified Duckling.AmountOfMoney.EN.CA.Rules as AmountOfMoneyCA
|
|
|
|
import qualified Duckling.AmountOfMoney.EN.GB.Rules as AmountOfMoneyGB
|
Implement handling of "grand" for EN_?? locales
Summary: Add implementation of "a grand" and "<num> grand" for AU, BZ, CA, GB, IE, IN, JM, NZ, PH, TT, ZA locales. Some resolve to the local currency (AU, IN), others resolve to Dollar (NZ, PH).
Reviewed By: patapizza
Differential Revision: D7943186
fbshipit-source-id: c71ab462fa9df0ee65223ee82dc2c98457a4e13b
2018-05-18 01:37:01 +03:00
|
|
|
import qualified Duckling.AmountOfMoney.EN.IE.Rules as AmountOfMoneyIE
|
|
|
|
import qualified Duckling.AmountOfMoney.EN.IN.Rules as AmountOfMoneyIN
|
|
|
|
import qualified Duckling.AmountOfMoney.EN.JM.Rules as AmountOfMoneyJM
|
|
|
|
import qualified Duckling.AmountOfMoney.EN.NZ.Rules as AmountOfMoneyNZ
|
|
|
|
import qualified Duckling.AmountOfMoney.EN.PH.Rules as AmountOfMoneyPH
|
|
|
|
import qualified Duckling.AmountOfMoney.EN.TT.Rules as AmountOfMoneyTT
|
2018-05-04 00:24:50 +03:00
|
|
|
import qualified Duckling.AmountOfMoney.EN.US.Rules as AmountOfMoneyUS
|
Implement handling of "grand" for EN_?? locales
Summary: Add implementation of "a grand" and "<num> grand" for AU, BZ, CA, GB, IE, IN, JM, NZ, PH, TT, ZA locales. Some resolve to the local currency (AU, IN), others resolve to Dollar (NZ, PH).
Reviewed By: patapizza
Differential Revision: D7943186
fbshipit-source-id: c71ab462fa9df0ee65223ee82dc2c98457a4e13b
2018-05-18 01:37:01 +03:00
|
|
|
import qualified Duckling.AmountOfMoney.EN.ZA.Rules as AmountOfMoneyZA
|
2017-03-08 21:33:55 +03:00
|
|
|
import qualified Duckling.Distance.EN.Rules as Distance
|
|
|
|
import qualified Duckling.Duration.EN.Rules as Duration
|
|
|
|
import qualified Duckling.Email.EN.Rules as Email
|
2017-03-16 23:42:15 +03:00
|
|
|
import qualified Duckling.Numeral.EN.Rules as Numeral
|
2017-03-08 21:33:55 +03:00
|
|
|
import qualified Duckling.Ordinal.EN.Rules as Ordinal
|
|
|
|
import qualified Duckling.Quantity.EN.Rules as Quantity
|
2021-04-09 00:27:17 +03:00
|
|
|
import qualified Duckling.Region as R
|
2017-03-08 21:33:55 +03:00
|
|
|
import qualified Duckling.Temperature.EN.Rules as Temperature
|
|
|
|
import qualified Duckling.Time.EN.Rules as Time
|
2017-10-26 18:39:53 +03:00
|
|
|
import qualified Duckling.Time.EN.AU.Rules as TimeAU
|
|
|
|
import qualified Duckling.Time.EN.BZ.Rules as TimeBZ
|
2017-10-16 19:43:53 +03:00
|
|
|
import qualified Duckling.Time.EN.CA.Rules as TimeCA
|
Locales support
Summary:
* Locales support for the library, following `<Lang>_<Region>` with ISO 639-1 code for `<Lang>` and ISO 3166-1 alpha-2 code for `<Region>` (#33)
* `Locale` opaque type (composite of `Lang` and `Region`) with `makeLocale` smart constructor to only allow valid `(Lang, Region)` combinations
* API: `Context`'s `lang` parameter has been replaced by `locale`, with optional `Region` and backward compatibility.
* `Rules/<Lang>.hs` exposes
- `langRules`: cross-locale rules for `<Lang>`, from `<Dimension>/<Lang>/Rules.hs`
- `localeRules`: locale-specific rules, from `<Dimension>/<Lang>/<Region>/Rules.hs`
- `defaultRules`: `langRules` + specific rules from select locales to ensure backward-compatibility
* Corpus, tests & classifiers
- 1 classifier per locale, with default classifier (`<Lang>_XX`) when no locale provided (backward-compatible)
- Default classifiers are built on existing corpus
- Locale classifiers are built on
- `<Dimension>/<Lang>/Corpus.hs` exposes a common `corpus` to all locales of `<Lang>`
- `<Dimension>/<Lang>/<Region>/Corpus.hs` exposes `allExamples`: a list of examples specific to the locale (following `<Dimension>/<Lang>/<Region>/Rules.hs`).
- Locale classifiers use the language corpus extended with the locale examples as training set.
- Locale examples need to use the same `Context` (i.e. reference time) as the language corpus.
- For backward compatibility, `<Dimension>/<Lang>/Corpus.hs` can expose also `defaultCorpus`, which is `corpus` augmented with specific examples. This is controlled by `getDefaultCorpusForLang` in `Duckling.Ranking.Generate`.
- Tests run against each classifier to make sure runtime works as expected.
* MM/DD (en_US) vs DD/MM (en_GB) example to illustrate
Reviewed By: JonCoens, blandinw
Differential Revision: D6038096
fbshipit-source-id: f29c28d
2017-10-13 18:15:32 +03:00
|
|
|
import qualified Duckling.Time.EN.GB.Rules as TimeGB
|
2017-10-26 18:39:53 +03:00
|
|
|
import qualified Duckling.Time.EN.IE.Rules as TimeIE
|
|
|
|
import qualified Duckling.Time.EN.IN.Rules as TimeIN
|
|
|
|
import qualified Duckling.Time.EN.JM.Rules as TimeJM
|
|
|
|
import qualified Duckling.Time.EN.NZ.Rules as TimeNZ
|
|
|
|
import qualified Duckling.Time.EN.PH.Rules as TimePH
|
|
|
|
import qualified Duckling.Time.EN.TT.Rules as TimeTT
|
Locales support
Summary:
* Locales support for the library, following `<Lang>_<Region>` with ISO 639-1 code for `<Lang>` and ISO 3166-1 alpha-2 code for `<Region>` (#33)
* `Locale` opaque type (composite of `Lang` and `Region`) with `makeLocale` smart constructor to only allow valid `(Lang, Region)` combinations
* API: `Context`'s `lang` parameter has been replaced by `locale`, with optional `Region` and backward compatibility.
* `Rules/<Lang>.hs` exposes
- `langRules`: cross-locale rules for `<Lang>`, from `<Dimension>/<Lang>/Rules.hs`
- `localeRules`: locale-specific rules, from `<Dimension>/<Lang>/<Region>/Rules.hs`
- `defaultRules`: `langRules` + specific rules from select locales to ensure backward-compatibility
* Corpus, tests & classifiers
- 1 classifier per locale, with default classifier (`<Lang>_XX`) when no locale provided (backward-compatible)
- Default classifiers are built on existing corpus
- Locale classifiers are built on
- `<Dimension>/<Lang>/Corpus.hs` exposes a common `corpus` to all locales of `<Lang>`
- `<Dimension>/<Lang>/<Region>/Corpus.hs` exposes `allExamples`: a list of examples specific to the locale (following `<Dimension>/<Lang>/<Region>/Rules.hs`).
- Locale classifiers use the language corpus extended with the locale examples as training set.
- Locale examples need to use the same `Context` (i.e. reference time) as the language corpus.
- For backward compatibility, `<Dimension>/<Lang>/Corpus.hs` can expose also `defaultCorpus`, which is `corpus` augmented with specific examples. This is controlled by `getDefaultCorpusForLang` in `Duckling.Ranking.Generate`.
- Tests run against each classifier to make sure runtime works as expected.
* MM/DD (en_US) vs DD/MM (en_GB) example to illustrate
Reviewed By: JonCoens, blandinw
Differential Revision: D6038096
fbshipit-source-id: f29c28d
2017-10-13 18:15:32 +03:00
|
|
|
import qualified Duckling.Time.EN.US.Rules as TimeUS
|
2017-10-26 18:39:53 +03:00
|
|
|
import qualified Duckling.Time.EN.ZA.Rules as TimeZA
|
2017-03-08 21:33:55 +03:00
|
|
|
import qualified Duckling.TimeGrain.EN.Rules as TimeGrain
|
|
|
|
import qualified Duckling.Volume.EN.Rules as Volume
|
|
|
|
|
2020-09-28 11:31:58 +03:00
|
|
|
defaultRules :: Seal Dimension -> [Rule]
|
|
|
|
defaultRules dim@(Seal Time) = TimeUS.rulesBackwardCompatible ++ langRules dim
|
2018-03-17 03:08:10 +03:00
|
|
|
defaultRules dim = langRules dim
|
Locales support
Summary:
* Locales support for the library, following `<Lang>_<Region>` with ISO 639-1 code for `<Lang>` and ISO 3166-1 alpha-2 code for `<Region>` (#33)
* `Locale` opaque type (composite of `Lang` and `Region`) with `makeLocale` smart constructor to only allow valid `(Lang, Region)` combinations
* API: `Context`'s `lang` parameter has been replaced by `locale`, with optional `Region` and backward compatibility.
* `Rules/<Lang>.hs` exposes
- `langRules`: cross-locale rules for `<Lang>`, from `<Dimension>/<Lang>/Rules.hs`
- `localeRules`: locale-specific rules, from `<Dimension>/<Lang>/<Region>/Rules.hs`
- `defaultRules`: `langRules` + specific rules from select locales to ensure backward-compatibility
* Corpus, tests & classifiers
- 1 classifier per locale, with default classifier (`<Lang>_XX`) when no locale provided (backward-compatible)
- Default classifiers are built on existing corpus
- Locale classifiers are built on
- `<Dimension>/<Lang>/Corpus.hs` exposes a common `corpus` to all locales of `<Lang>`
- `<Dimension>/<Lang>/<Region>/Corpus.hs` exposes `allExamples`: a list of examples specific to the locale (following `<Dimension>/<Lang>/<Region>/Rules.hs`).
- Locale classifiers use the language corpus extended with the locale examples as training set.
- Locale examples need to use the same `Context` (i.e. reference time) as the language corpus.
- For backward compatibility, `<Dimension>/<Lang>/Corpus.hs` can expose also `defaultCorpus`, which is `corpus` augmented with specific examples. This is controlled by `getDefaultCorpusForLang` in `Duckling.Ranking.Generate`.
- Tests run against each classifier to make sure runtime works as expected.
* MM/DD (en_US) vs DD/MM (en_GB) example to illustrate
Reviewed By: JonCoens, blandinw
Differential Revision: D6038096
fbshipit-source-id: f29c28d
2017-10-13 18:15:32 +03:00
|
|
|
|
2020-09-28 11:31:58 +03:00
|
|
|
localeRules :: Region -> Seal Dimension -> [Rule]
|
|
|
|
localeRules AU (Seal AmountOfMoney) = AmountOfMoneyAU.rules
|
|
|
|
localeRules BZ (Seal AmountOfMoney) = AmountOfMoneyBZ.rules
|
2021-04-09 00:27:17 +03:00
|
|
|
localeRules R.CA (Seal AmountOfMoney) = AmountOfMoneyCA.rules
|
2020-09-28 11:31:58 +03:00
|
|
|
localeRules GB (Seal AmountOfMoney) = AmountOfMoneyGB.rules
|
|
|
|
localeRules IE (Seal AmountOfMoney) = AmountOfMoneyIE.rules
|
|
|
|
localeRules IN (Seal AmountOfMoney) = AmountOfMoneyIN.rules
|
|
|
|
localeRules JM (Seal AmountOfMoney) = AmountOfMoneyJM.rules
|
|
|
|
localeRules NZ (Seal AmountOfMoney) = AmountOfMoneyNZ.rules
|
|
|
|
localeRules PH (Seal AmountOfMoney) = AmountOfMoneyPH.rules
|
|
|
|
localeRules TT (Seal AmountOfMoney) = AmountOfMoneyTT.rules
|
|
|
|
localeRules US (Seal AmountOfMoney) = AmountOfMoneyUS.rules
|
|
|
|
localeRules ZA (Seal AmountOfMoney) = AmountOfMoneyZA.rules
|
|
|
|
localeRules AU (Seal Time) = TimeAU.rules
|
|
|
|
localeRules BZ (Seal Time) = TimeBZ.rules
|
2021-04-09 00:27:17 +03:00
|
|
|
localeRules R.CA (Seal Time) = TimeCA.rules
|
2020-09-28 11:31:58 +03:00
|
|
|
localeRules GB (Seal Time) = TimeGB.rules
|
|
|
|
localeRules IE (Seal Time) = TimeIE.rules
|
|
|
|
localeRules IN (Seal Time) = TimeIN.rules
|
|
|
|
localeRules JM (Seal Time) = TimeJM.rules
|
|
|
|
localeRules NZ (Seal Time) = TimeNZ.rules
|
|
|
|
localeRules PH (Seal Time) = TimePH.rules
|
|
|
|
localeRules TT (Seal Time) = TimeTT.rules
|
|
|
|
localeRules US (Seal Time) = TimeUS.rules
|
|
|
|
localeRules ZA (Seal Time) = TimeZA.rules
|
|
|
|
localeRules region (Seal (CustomDimension dim)) = dimLocaleRules region dim
|
2018-04-20 01:21:18 +03:00
|
|
|
localeRules _ _ = []
|
Locales support
Summary:
* Locales support for the library, following `<Lang>_<Region>` with ISO 639-1 code for `<Lang>` and ISO 3166-1 alpha-2 code for `<Region>` (#33)
* `Locale` opaque type (composite of `Lang` and `Region`) with `makeLocale` smart constructor to only allow valid `(Lang, Region)` combinations
* API: `Context`'s `lang` parameter has been replaced by `locale`, with optional `Region` and backward compatibility.
* `Rules/<Lang>.hs` exposes
- `langRules`: cross-locale rules for `<Lang>`, from `<Dimension>/<Lang>/Rules.hs`
- `localeRules`: locale-specific rules, from `<Dimension>/<Lang>/<Region>/Rules.hs`
- `defaultRules`: `langRules` + specific rules from select locales to ensure backward-compatibility
* Corpus, tests & classifiers
- 1 classifier per locale, with default classifier (`<Lang>_XX`) when no locale provided (backward-compatible)
- Default classifiers are built on existing corpus
- Locale classifiers are built on
- `<Dimension>/<Lang>/Corpus.hs` exposes a common `corpus` to all locales of `<Lang>`
- `<Dimension>/<Lang>/<Region>/Corpus.hs` exposes `allExamples`: a list of examples specific to the locale (following `<Dimension>/<Lang>/<Region>/Rules.hs`).
- Locale classifiers use the language corpus extended with the locale examples as training set.
- Locale examples need to use the same `Context` (i.e. reference time) as the language corpus.
- For backward compatibility, `<Dimension>/<Lang>/Corpus.hs` can expose also `defaultCorpus`, which is `corpus` augmented with specific examples. This is controlled by `getDefaultCorpusForLang` in `Duckling.Ranking.Generate`.
- Tests run against each classifier to make sure runtime works as expected.
* MM/DD (en_US) vs DD/MM (en_GB) example to illustrate
Reviewed By: JonCoens, blandinw
Differential Revision: D6038096
fbshipit-source-id: f29c28d
2017-10-13 18:15:32 +03:00
|
|
|
|
2020-09-28 11:31:58 +03:00
|
|
|
langRules :: Seal Dimension -> [Rule]
|
|
|
|
langRules (Seal AmountOfMoney) = AmountOfMoney.rules
|
|
|
|
langRules (Seal CreditCardNumber) = []
|
|
|
|
langRules (Seal Distance) = Distance.rules
|
|
|
|
langRules (Seal Duration) = Duration.rules
|
|
|
|
langRules (Seal Email) = Email.rules
|
|
|
|
langRules (Seal Numeral) = Numeral.rules
|
|
|
|
langRules (Seal Ordinal) = Ordinal.rules
|
|
|
|
langRules (Seal PhoneNumber) = []
|
|
|
|
langRules (Seal Quantity) = Quantity.rules
|
|
|
|
langRules (Seal RegexMatch) = []
|
|
|
|
langRules (Seal Temperature) = Temperature.rules
|
|
|
|
langRules (Seal Time) = Time.rules
|
|
|
|
langRules (Seal TimeGrain) = TimeGrain.rules
|
|
|
|
langRules (Seal Url) = []
|
|
|
|
langRules (Seal Volume) = Volume.rules
|
|
|
|
langRules (Seal (CustomDimension dim)) = dimLangRules EN dim
|