-- Copyright (c) 2016-present, Facebook, Inc.
-- All rights reserved.
--
-- This source code is licensed under the BSD-style license found in the
-- LICENSE file in the root directory of this source tree.


{-# LANGUAGE GADTs #-}
{-# LANGUAGE NoRebindableSyntax #-}

module Duckling.Dimensions
  ( allDimensions
  , explicitDimensions
  ) where

import Data.HashSet (HashSet)
import Prelude
import qualified Data.HashSet as HashSet

import Duckling.Dimensions.Types
import Duckling.Locale
import Duckling.Types
import qualified Duckling.Dimensions.Common as CommonDimensions
import qualified Duckling.Dimensions.AF as AFDimensions
import qualified Duckling.Dimensions.AR as ARDimensions
import qualified Duckling.Dimensions.BG as BGDimensions
import qualified Duckling.Dimensions.BN as BNDimensions
import qualified Duckling.Dimensions.CA as CADimensions
import qualified Duckling.Dimensions.CS as CSDimensions
import qualified Duckling.Dimensions.DA as DADimensions
import qualified Duckling.Dimensions.DE as DEDimensions
import qualified Duckling.Dimensions.EL as ELDimensions
import qualified Duckling.Dimensions.EN as ENDimensions
import qualified Duckling.Dimensions.ES as ESDimensions
import qualified Duckling.Dimensions.ET as ETDimensions
import qualified Duckling.Dimensions.FA as FADimensions
import qualified Duckling.Dimensions.FI as FIDimensions
import qualified Duckling.Dimensions.FR as FRDimensions
import qualified Duckling.Dimensions.GA as GADimensions
import qualified Duckling.Dimensions.HE as HEDimensions
import qualified Duckling.Dimensions.HI as HIDimensions
import qualified Duckling.Dimensions.HR as HRDimensions
import qualified Duckling.Dimensions.HU as HUDimensions
import qualified Duckling.Dimensions.ID as IDDimensions
import qualified Duckling.Dimensions.IS as ISDimensions
import qualified Duckling.Dimensions.IT as ITDimensions
import qualified Duckling.Dimensions.JA as JADimensions
import qualified Duckling.Dimensions.KA as KADimensions
import qualified Duckling.Dimensions.KM as KMDimensions
import qualified Duckling.Dimensions.KN as KNDimensions
import qualified Duckling.Dimensions.KO as KODimensions
import qualified Duckling.Dimensions.LO as LODimensions
import qualified Duckling.Dimensions.ML as MLDimensions
import qualified Duckling.Dimensions.MN as MNDimensions
import qualified Duckling.Dimensions.MY as MYDimensions
import qualified Duckling.Dimensions.NB as NBDimensions
import qualified Duckling.Dimensions.NE as NEDimensions
import qualified Duckling.Dimensions.NL as NLDimensions
import qualified Duckling.Dimensions.PL as PLDimensions
import qualified Duckling.Dimensions.PT as PTDimensions
import qualified Duckling.Dimensions.RO as RODimensions
import qualified Duckling.Dimensions.RU as RUDimensions
import qualified Duckling.Dimensions.SK as SKDimensions
import qualified Duckling.Dimensions.SV as SVDimensions
import qualified Duckling.Dimensions.SW as SWDimensions
import qualified Duckling.Dimensions.TA as TADimensions
import qualified Duckling.Dimensions.TE as TEDimensions
import qualified Duckling.Dimensions.TH as THDimensions
import qualified Duckling.Dimensions.TR as TRDimensions
import qualified Duckling.Dimensions.UK as UKDimensions
import qualified Duckling.Dimensions.VI as VIDimensions
import qualified Duckling.Dimensions.ZH as ZHDimensions


allDimensions :: Lang -> [Seal Dimension]
allDimensions :: Lang -> [Seal Dimension]
allDimensions Lang
lang = [Seal Dimension]
CommonDimensions.allDimensions [Seal Dimension] -> [Seal Dimension] -> [Seal Dimension]
forall a. [a] -> [a] -> [a]
++ Lang -> [Seal Dimension]
langDimensions Lang
lang

-- | Augments `targets` with all dependent dimensions.
explicitDimensions :: HashSet (Seal Dimension) -> HashSet (Seal Dimension)
explicitDimensions :: HashSet (Seal Dimension) -> HashSet (Seal Dimension)
explicitDimensions HashSet (Seal Dimension)
targets = HashSet (Seal Dimension)
-> HashSet (Seal Dimension) -> HashSet (Seal Dimension)
forall a. (Eq a, Hashable a) => HashSet a -> HashSet a -> HashSet a
HashSet.union HashSet (Seal Dimension)
targets HashSet (Seal Dimension)
deps
  where
    deps :: HashSet (Seal Dimension)
deps = [HashSet (Seal Dimension)] -> HashSet (Seal Dimension)
forall a. (Eq a, Hashable a) => [HashSet a] -> HashSet a
HashSet.unions ([HashSet (Seal Dimension)] -> HashSet (Seal Dimension))
-> ([Seal Dimension] -> [HashSet (Seal Dimension)])
-> [Seal Dimension]
-> HashSet (Seal Dimension)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Seal Dimension -> HashSet (Seal Dimension))
-> [Seal Dimension] -> [HashSet (Seal Dimension)]
forall a b. (a -> b) -> [a] -> [b]
map Seal Dimension -> HashSet (Seal Dimension)
dependents ([Seal Dimension] -> HashSet (Seal Dimension))
-> [Seal Dimension] -> HashSet (Seal Dimension)
forall a b. (a -> b) -> a -> b
$ HashSet (Seal Dimension) -> [Seal Dimension]
forall a. HashSet a -> [a]
HashSet.toList HashSet (Seal Dimension)
targets

-- | Ordinal depends on Numeral for JA, KO, and ZH.
dependents :: Seal Dimension -> HashSet (Seal Dimension)
dependents :: Seal Dimension -> HashSet (Seal Dimension)
dependents (Seal Dimension a
CreditCardNumber) = HashSet (Seal Dimension)
forall a. HashSet a
HashSet.empty
dependents (Seal Dimension a
Distance) = Seal Dimension -> HashSet (Seal Dimension)
forall a. Hashable a => a -> HashSet a
HashSet.singleton (Dimension NumeralData -> Seal Dimension
forall (s :: * -> *) a. s a -> Seal s
Seal Dimension NumeralData
Numeral)
dependents (Seal Dimension a
Duration) = [Seal Dimension] -> HashSet (Seal Dimension)
forall a. (Eq a, Hashable a) => [a] -> HashSet a
HashSet.fromList [Dimension NumeralData -> Seal Dimension
forall (s :: * -> *) a. s a -> Seal s
Seal Dimension NumeralData
Numeral, Dimension Grain -> Seal Dimension
forall (s :: * -> *) a. s a -> Seal s
Seal Dimension Grain
TimeGrain]
dependents (Seal Dimension a
Numeral) = HashSet (Seal Dimension)
forall a. HashSet a
HashSet.empty
dependents (Seal Dimension a
Email) = HashSet (Seal Dimension)
forall a. HashSet a
HashSet.empty
dependents (Seal Dimension a
AmountOfMoney) = Seal Dimension -> HashSet (Seal Dimension)
forall a. Hashable a => a -> HashSet a
HashSet.singleton (Dimension NumeralData -> Seal Dimension
forall (s :: * -> *) a. s a -> Seal s
Seal Dimension NumeralData
Numeral)
dependents (Seal Dimension a
Ordinal) = Seal Dimension -> HashSet (Seal Dimension)
forall a. Hashable a => a -> HashSet a
HashSet.singleton (Dimension NumeralData -> Seal Dimension
forall (s :: * -> *) a. s a -> Seal s
Seal Dimension NumeralData
Numeral)
dependents (Seal Dimension a
PhoneNumber) = HashSet (Seal Dimension)
forall a. HashSet a
HashSet.empty
dependents (Seal Dimension a
Quantity) = Seal Dimension -> HashSet (Seal Dimension)
forall a. Hashable a => a -> HashSet a
HashSet.singleton (Dimension NumeralData -> Seal Dimension
forall (s :: * -> *) a. s a -> Seal s
Seal Dimension NumeralData
Numeral)
dependents (Seal Dimension a
RegexMatch) = HashSet (Seal Dimension)
forall a. HashSet a
HashSet.empty
dependents (Seal Dimension a
Temperature) = Seal Dimension -> HashSet (Seal Dimension)
forall a. Hashable a => a -> HashSet a
HashSet.singleton (Dimension NumeralData -> Seal Dimension
forall (s :: * -> *) a. s a -> Seal s
Seal Dimension NumeralData
Numeral)
dependents (Seal Dimension a
Time) =
  [Seal Dimension] -> HashSet (Seal Dimension)
forall a. (Eq a, Hashable a) => [a] -> HashSet a
HashSet.fromList [Dimension NumeralData -> Seal Dimension
forall (s :: * -> *) a. s a -> Seal s
Seal Dimension NumeralData
Numeral, Dimension DurationData -> Seal Dimension
forall (s :: * -> *) a. s a -> Seal s
Seal Dimension DurationData
Duration, Dimension OrdinalData -> Seal Dimension
forall (s :: * -> *) a. s a -> Seal s
Seal Dimension OrdinalData
Ordinal, Dimension Grain -> Seal Dimension
forall (s :: * -> *) a. s a -> Seal s
Seal Dimension Grain
TimeGrain]
dependents (Seal Dimension a
TimeGrain) = HashSet (Seal Dimension)
forall a. HashSet a
HashSet.empty
dependents (Seal Dimension a
Url) = HashSet (Seal Dimension)
forall a. HashSet a
HashSet.empty
dependents (Seal Dimension a
Volume) = Seal Dimension -> HashSet (Seal Dimension)
forall a. Hashable a => a -> HashSet a
HashSet.singleton (Dimension NumeralData -> Seal Dimension
forall (s :: * -> *) a. s a -> Seal s
Seal Dimension NumeralData
Numeral)
dependents (Seal (CustomDimension a
dim)) = a -> HashSet (Seal Dimension)
forall a. CustomDimension a => a -> HashSet (Seal Dimension)
dimDependents a
dim

langDimensions :: Lang -> [Seal Dimension]
langDimensions :: Lang -> [Seal Dimension]
langDimensions Lang
AF = [Seal Dimension]
AFDimensions.allDimensions
langDimensions Lang
AR = [Seal Dimension]
ARDimensions.allDimensions
langDimensions Lang
BG = [Seal Dimension]
BGDimensions.allDimensions
langDimensions Lang
BN = [Seal Dimension]
BNDimensions.allDimensions
langDimensions Lang
CA = [Seal Dimension]
CADimensions.allDimensions
langDimensions Lang
CS = [Seal Dimension]
CSDimensions.allDimensions
langDimensions Lang
DA = [Seal Dimension]
DADimensions.allDimensions
langDimensions Lang
DE = [Seal Dimension]
DEDimensions.allDimensions
langDimensions Lang
EL = [Seal Dimension]
ELDimensions.allDimensions
langDimensions Lang
EN = [Seal Dimension]
ENDimensions.allDimensions
langDimensions Lang
ES = [Seal Dimension]
ESDimensions.allDimensions
langDimensions Lang
ET = [Seal Dimension]
ETDimensions.allDimensions
langDimensions Lang
FA = [Seal Dimension]
FADimensions.allDimensions
langDimensions Lang
FI = [Seal Dimension]
FIDimensions.allDimensions
langDimensions Lang
FR = [Seal Dimension]
FRDimensions.allDimensions
langDimensions Lang
GA = [Seal Dimension]
GADimensions.allDimensions
langDimensions Lang
HE = [Seal Dimension]
HEDimensions.allDimensions
langDimensions Lang
HI = [Seal Dimension]
HIDimensions.allDimensions
langDimensions Lang
HR = [Seal Dimension]
HRDimensions.allDimensions
langDimensions Lang
HU = [Seal Dimension]
HUDimensions.allDimensions
langDimensions Lang
ID = [Seal Dimension]
IDDimensions.allDimensions
langDimensions Lang
IS = [Seal Dimension]
ISDimensions.allDimensions
langDimensions Lang
IT = [Seal Dimension]
ITDimensions.allDimensions
langDimensions Lang
JA = [Seal Dimension]
JADimensions.allDimensions
langDimensions Lang
KA = [Seal Dimension]
KADimensions.allDimensions
langDimensions Lang
KM = [Seal Dimension]
KMDimensions.allDimensions
langDimensions Lang
KN = [Seal Dimension]
KNDimensions.allDimensions
langDimensions Lang
KO = [Seal Dimension]
KODimensions.allDimensions
langDimensions Lang
LO = [Seal Dimension]
LODimensions.allDimensions
langDimensions Lang
ML = [Seal Dimension]
MLDimensions.allDimensions
langDimensions Lang
MN = [Seal Dimension]
MNDimensions.allDimensions
langDimensions Lang
MY = [Seal Dimension]
MYDimensions.allDimensions
langDimensions Lang
NB = [Seal Dimension]
NBDimensions.allDimensions
langDimensions Lang
NE = [Seal Dimension]
NEDimensions.allDimensions
langDimensions Lang
NL = [Seal Dimension]
NLDimensions.allDimensions
langDimensions Lang
PL = [Seal Dimension]
PLDimensions.allDimensions
langDimensions Lang
PT = [Seal Dimension]
PTDimensions.allDimensions
langDimensions Lang
RO = [Seal Dimension]
RODimensions.allDimensions
langDimensions Lang
RU = [Seal Dimension]
RUDimensions.allDimensions
langDimensions Lang
SK = [Seal Dimension]
SKDimensions.allDimensions
langDimensions Lang
SV = [Seal Dimension]
SVDimensions.allDimensions
langDimensions Lang
SW = [Seal Dimension]
SWDimensions.allDimensions
langDimensions Lang
TA = [Seal Dimension]
TADimensions.allDimensions
langDimensions Lang
TE = [Seal Dimension]
TEDimensions.allDimensions
langDimensions Lang
TH = [Seal Dimension]
THDimensions.allDimensions
langDimensions Lang
TR = [Seal Dimension]
TRDimensions.allDimensions
langDimensions Lang
UK = [Seal Dimension]
UKDimensions.allDimensions
langDimensions Lang
VI = [Seal Dimension]
VIDimensions.allDimensions
langDimensions Lang
ZH = [Seal Dimension]
ZHDimensions.allDimensions