-
Notifications
You must be signed in to change notification settings - Fork 729
/
Types.hs
64 lines (55 loc) · 1.66 KB
/
Types.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
-- 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.Types
( Seal(..)
, Dimension(..)
, fromName
, toName
) where
import Data.Maybe
import Data.Text (Text)
import Prelude
import qualified Data.HashMap.Strict as HashMap
import qualified Data.Text as Text
import Duckling.Types
toName :: Dimension a -> Text
toName RegexMatch = "regex"
toName CreditCardNumber = "credit-card-number"
toName Distance = "distance"
toName Duration = "duration"
toName Email = "email"
toName AmountOfMoney = "amount-of-money"
toName Numeral = "number"
toName Ordinal = "ordinal"
toName PhoneNumber = "phone-number"
toName Quantity = "quantity"
toName Temperature = "temperature"
toName Time = "time"
toName TimeGrain = "time-grain"
toName Url = "url"
toName Volume = "volume"
toName (CustomDimension dim) = Text.pack (show dim)
fromName :: Text -> Maybe (Seal Dimension)
fromName name = HashMap.lookup name m
where
m = HashMap.fromList
[ ("amount-of-money", Seal AmountOfMoney)
, ("credit-card-number", Seal CreditCardNumber)
, ("distance", Seal Distance)
, ("duration", Seal Duration)
, ("email", Seal Email)
, ("number", Seal Numeral)
, ("ordinal", Seal Ordinal)
, ("phone-number", Seal PhoneNumber)
, ("quantity", Seal Quantity)
, ("temperature", Seal Temperature)
, ("time", Seal Time)
, ("time-grain", Seal TimeGrain)
, ("url", Seal Url)
, ("volume", Seal Volume)
]