AmountOfMoney/EN: added support for subunits of dollars

Summary: Added support for recognizing nickels, dimes and quarters, as well as numbers of coins.

Reviewed By: patapizza

Differential Revision: D9317706

fbshipit-source-id: 3fb3d63546c9cfe13c094703ddb583c6ac46585b
This commit is contained in:
Daniel Sainati 2018-08-16 15:33:50 -07:00 committed by Facebook Github Bot
parent f8c967c28d
commit 3910c68262
26 changed files with 538 additions and 13 deletions

View File

@ -27,6 +27,26 @@ allExamples = concat
]
, examples (simple AUD 10000)
[ "10 grand"
, "two hundred thousand nickels"
]
, examples (simple AUD 1)
[ "four quarters"
, "ten dimes"
, "twenty nickels"
]
, examples (simple AUD 0.1)
[ "dime"
, "a dime"
, "two nickels"
]
, examples (simple AUD 0.25)
[ "quarter"
, "a quarter"
, "five nickels"
]
, examples (simple AUD 0.05)
[ "nickel"
, "a nickel"
]
]

View File

@ -13,17 +13,22 @@ module Duckling.AmountOfMoney.EN.AU.Rules
( rules
) where
import Data.HashMap.Strict (HashMap)
import Data.String
import Data.Text (Text)
import Prelude
import Duckling.AmountOfMoney.Helpers
import Duckling.AmountOfMoney.Types (Currency(..))
import Duckling.Numeral.Helpers (isPositive)
import Duckling.Regex.Types
import Duckling.Types
import qualified Data.HashMap.Strict as HashMap
import qualified Data.Text as Text
import qualified Duckling.AmountOfMoney.Helpers as Helpers
import qualified Duckling.Numeral.Types as TNumeral
ruleAGrand :: Rule
ruleAGrand = Rule
{ name = "a grand"
@ -46,8 +51,22 @@ ruleGrand = Rule
_ -> Nothing
}
ruleDollarCoin :: Rule
ruleDollarCoin = Rule
{ name = "dollar coin"
, pattern =
[ regex "(nickel|dime|quarter)s?"
]
, prod = \tokens -> case tokens of
(Token RegexMatch (GroupMatch (match:_)):_) -> do
c <- HashMap.lookup (Text.toLower match) Helpers.dollarCoins
Just . Token AmountOfMoney . withValue c $ currencyOnly AUD
_ -> Nothing
}
rules :: [Rule]
rules =
[ ruleAGrand
, ruleGrand
, ruleDollarCoin
]

View File

@ -27,6 +27,26 @@ allExamples = concat
]
, examples (simple Dollar 10000)
[ "10 grand"
, "two hundred thousand nickels"
]
, examples (simple Dollar 1)
[ "four quarters"
, "ten dimes"
, "twenty nickels"
]
, examples (simple Dollar 0.1)
[ "dime"
, "a dime"
, "two nickels"
]
, examples (simple Dollar 0.25)
[ "quarter"
, "a quarter"
, "five nickels"
]
, examples (simple Dollar 0.05)
[ "nickel"
, "a nickel"
]
]

View File

@ -13,17 +13,22 @@ module Duckling.AmountOfMoney.EN.BZ.Rules
( rules
) where
import Data.HashMap.Strict (HashMap)
import Data.String
import Data.Text (Text)
import Prelude
import Duckling.AmountOfMoney.Helpers
import Duckling.AmountOfMoney.Types (Currency(..))
import Duckling.Numeral.Helpers (isPositive)
import Duckling.Regex.Types
import Duckling.Types
import qualified Data.HashMap.Strict as HashMap
import qualified Data.Text as Text
import qualified Duckling.AmountOfMoney.Helpers as Helpers
import qualified Duckling.Numeral.Types as TNumeral
ruleAGrand :: Rule
ruleAGrand = Rule
{ name = "a grand"
@ -48,8 +53,22 @@ ruleGrand = Rule
_ -> Nothing
}
ruleDollarCoin :: Rule
ruleDollarCoin = Rule
{ name = "dollar coin"
, pattern =
[ regex "(nickel|dime|quarter)s?"
]
, prod = \tokens -> case tokens of
(Token RegexMatch (GroupMatch (match:_)):_) -> do
c <- HashMap.lookup (Text.toLower match) Helpers.dollarCoins
Just . Token AmountOfMoney . withValue c $ currencyOnly Dollar
_ -> Nothing
}
rules :: [Rule]
rules =
[ ruleAGrand
, ruleGrand
, ruleDollarCoin
]

View File

@ -27,6 +27,26 @@ allExamples = concat
]
, examples (simple CAD 10000)
[ "10 grand"
, "two hundred thousand nickels"
]
, examples (simple CAD 1)
[ "four quarters"
, "ten dimes"
, "twenty nickels"
]
, examples (simple CAD 0.1)
[ "dime"
, "a dime"
, "two nickels"
]
, examples (simple CAD 0.25)
[ "quarter"
, "a quarter"
, "five nickels"
]
, examples (simple CAD 0.05)
[ "nickel"
, "a nickel"
]
]

View File

@ -13,17 +13,22 @@ module Duckling.AmountOfMoney.EN.CA.Rules
( rules
) where
import Data.HashMap.Strict (HashMap)
import Data.String
import Data.Text (Text)
import Prelude
import Duckling.AmountOfMoney.Helpers
import Duckling.AmountOfMoney.Types (Currency(..))
import Duckling.Numeral.Helpers (isPositive)
import Duckling.Regex.Types
import Duckling.Types
import qualified Data.HashMap.Strict as HashMap
import qualified Data.Text as Text
import qualified Duckling.AmountOfMoney.Helpers as Helpers
import qualified Duckling.Numeral.Types as TNumeral
ruleAGrand :: Rule
ruleAGrand = Rule
{ name = "a grand"
@ -46,8 +51,22 @@ ruleGrand = Rule
_ -> Nothing
}
ruleDollarCoin :: Rule
ruleDollarCoin = Rule
{ name = "dollar coin"
, pattern =
[ regex "(nickel|dime|quarter)s?"
]
, prod = \tokens -> case tokens of
(Token RegexMatch (GroupMatch (match:_)):_) -> do
c <- HashMap.lookup (Text.toLower match) Helpers.dollarCoins
Just . Token AmountOfMoney . withValue c $ currencyOnly CAD
_ -> Nothing
}
rules :: [Rule]
rules =
[ ruleAGrand
, ruleGrand
, ruleDollarCoin
]

View File

@ -28,6 +28,25 @@ allExamples = concat
, examples (simple GBP 10000)
[ "10 grand"
]
, examples (simple Dollar 1)
[ "four quarters"
, "ten dimes"
, "twenty nickels"
]
, examples (simple Dollar 0.1)
[ "dime"
, "a dime"
, "two nickels"
]
, examples (simple Dollar 0.25)
[ "quarter"
, "a quarter"
, "five nickels"
]
, examples (simple Dollar 0.05)
[ "nickel"
, "a nickel"
]
]
negativeExamples :: [Text]

View File

@ -13,17 +13,22 @@ module Duckling.AmountOfMoney.EN.GB.Rules
( rules
) where
import Data.HashMap.Strict (HashMap)
import Data.String
import Data.Text (Text)
import Prelude
import Duckling.AmountOfMoney.Helpers
import Duckling.AmountOfMoney.Types (Currency(..))
import Duckling.Numeral.Helpers (isPositive)
import Duckling.Regex.Types
import Duckling.Types
import qualified Data.HashMap.Strict as HashMap
import qualified Data.Text as Text
import qualified Duckling.AmountOfMoney.Helpers as Helpers
import qualified Duckling.Numeral.Types as TNumeral
ruleAGrand :: Rule
ruleAGrand = Rule
{ name = "a grand"
@ -46,8 +51,22 @@ ruleGrand = Rule
_ -> Nothing
}
ruleDollarCoin :: Rule
ruleDollarCoin = Rule
{ name = "dollar coin"
, pattern =
[ regex "(nickel|dime|quarter)s?"
]
, prod = \tokens -> case tokens of
(Token RegexMatch (GroupMatch (match:_)):_) -> do
c <- HashMap.lookup (Text.toLower match) Helpers.dollarCoins
Just . Token AmountOfMoney . withValue c $ currencyOnly Dollar
_ -> Nothing
}
rules :: [Rule]
rules =
[ ruleAGrand
, ruleGrand
, ruleDollarCoin
]

View File

@ -27,6 +27,26 @@ allExamples = concat
]
, examples (simple Dollar 10000)
[ "10 grand"
, "two hundred thousand nickels"
]
, examples (simple Dollar 1)
[ "four quarters"
, "ten dimes"
, "twenty nickels"
]
, examples (simple Dollar 0.1)
[ "dime"
, "a dime"
, "two nickels"
]
, examples (simple Dollar 0.25)
[ "quarter"
, "a quarter"
, "five nickels"
]
, examples (simple Dollar 0.05)
[ "nickel"
, "a nickel"
]
]

View File

@ -13,14 +13,20 @@ module Duckling.AmountOfMoney.EN.IE.Rules
( rules
) where
import Data.HashMap.Strict (HashMap)
import Data.String
import Data.Text (Text)
import Prelude
import Duckling.AmountOfMoney.Helpers
import Duckling.AmountOfMoney.Types (Currency(..))
import Duckling.Numeral.Helpers (isPositive)
import Duckling.Regex.Types
import Duckling.Types
import qualified Data.HashMap.Strict as HashMap
import qualified Data.Text as Text
import qualified Duckling.AmountOfMoney.Helpers as Helpers
import qualified Duckling.Numeral.Types as TNumeral
@ -48,8 +54,22 @@ ruleGrand = Rule
_ -> Nothing
}
ruleDollarCoin :: Rule
ruleDollarCoin = Rule
{ name = "dollar coin"
, pattern =
[ regex "(nickel|dime|quarter)s?"
]
, prod = \tokens -> case tokens of
(Token RegexMatch (GroupMatch (match:_)):_) -> do
c <- HashMap.lookup (Text.toLower match) Helpers.dollarCoins
Just . Token AmountOfMoney . withValue c $ currencyOnly Dollar
_ -> Nothing
}
rules :: [Rule]
rules =
[ ruleAGrand
, ruleGrand
, ruleDollarCoin
]

View File

@ -27,6 +27,26 @@ allExamples = concat
]
, examples (simple Dollar 10000)
[ "10 grand"
, "two hundred thousand nickels"
]
, examples (simple Dollar 1)
[ "four quarters"
, "ten dimes"
, "twenty nickels"
]
, examples (simple Dollar 0.1)
[ "dime"
, "a dime"
, "two nickels"
]
, examples (simple Dollar 0.25)
[ "quarter"
, "a quarter"
, "five nickels"
]
, examples (simple Dollar 0.05)
[ "nickel"
, "a nickel"
]
]

View File

@ -13,17 +13,22 @@ module Duckling.AmountOfMoney.EN.IN.Rules
( rules
) where
import Data.HashMap.Strict (HashMap)
import Data.String
import Data.Text (Text)
import Prelude
import Duckling.AmountOfMoney.Helpers
import Duckling.AmountOfMoney.Types (Currency(..))
import Duckling.Numeral.Helpers (isPositive)
import Duckling.Regex.Types
import Duckling.Types
import qualified Data.HashMap.Strict as HashMap
import qualified Data.Text as Text
import qualified Duckling.AmountOfMoney.Helpers as Helpers
import qualified Duckling.Numeral.Types as TNumeral
ruleAGrand :: Rule
ruleAGrand = Rule
{ name = "a grand"
@ -46,8 +51,22 @@ ruleGrand = Rule
_ -> Nothing
}
ruleDollarCoin :: Rule
ruleDollarCoin = Rule
{ name = "dollar coin"
, pattern =
[ regex "(nickel|dime|quarter)s?"
]
, prod = \tokens -> case tokens of
(Token RegexMatch (GroupMatch (match:_)):_) -> do
c <- HashMap.lookup (Text.toLower match) Helpers.dollarCoins
Just . Token AmountOfMoney . withValue c $ currencyOnly Dollar
_ -> Nothing
}
rules :: [Rule]
rules =
[ ruleAGrand
, ruleGrand
, ruleDollarCoin
]

View File

@ -27,9 +27,28 @@ allExamples = concat
]
, examples (simple JMD 10000)
[ "10 grand"
, "two hundred thousand nickels"
]
, examples (simple JMD 1)
[ "four quarters"
, "ten dimes"
, "twenty nickels"
]
, examples (simple JMD 0.1)
[ "dime"
, "a dime"
, "two nickels"
]
, examples (simple JMD 0.25)
[ "quarter"
, "a quarter"
, "five nickels"
]
, examples (simple JMD 0.05)
[ "nickel"
, "a nickel"
]
]
negativeExamples :: [Text]
negativeExamples =
[ "grand"

View File

@ -13,17 +13,22 @@ module Duckling.AmountOfMoney.EN.JM.Rules
( rules
) where
import Data.HashMap.Strict (HashMap)
import Data.String
import Data.Text (Text)
import Prelude
import Duckling.AmountOfMoney.Helpers
import Duckling.AmountOfMoney.Types (Currency(..))
import Duckling.Numeral.Helpers (isPositive)
import Duckling.Regex.Types
import Duckling.Types
import qualified Data.HashMap.Strict as HashMap
import qualified Data.Text as Text
import qualified Duckling.AmountOfMoney.Helpers as Helpers
import qualified Duckling.Numeral.Types as TNumeral
ruleAGrand :: Rule
ruleAGrand = Rule
{ name = "a grand"
@ -48,8 +53,22 @@ ruleGrand = Rule
_ -> Nothing
}
ruleDollarCoin :: Rule
ruleDollarCoin = Rule
{ name = "dollar coin"
, pattern =
[ regex "(nickel|dime|quarter)s?"
]
, prod = \tokens -> case tokens of
(Token RegexMatch (GroupMatch (match:_)):_) -> do
c <- HashMap.lookup (Text.toLower match) Helpers.dollarCoins
Just . Token AmountOfMoney . withValue c $ currencyOnly JMD
_ -> Nothing
}
rules :: [Rule]
rules =
[ ruleAGrand
, ruleGrand
, ruleDollarCoin
]

View File

@ -27,6 +27,26 @@ allExamples = concat
]
, examples (simple NZD 10000)
[ "10 grand"
, "two hundred thousand nickels"
]
, examples (simple NZD 1)
[ "four quarters"
, "ten dimes"
, "twenty nickels"
]
, examples (simple NZD 0.1)
[ "dime"
, "a dime"
, "two nickels"
]
, examples (simple NZD 0.25)
[ "quarter"
, "a quarter"
, "five nickels"
]
, examples (simple NZD 0.05)
[ "nickel"
, "a nickel"
]
]

View File

@ -13,17 +13,22 @@ module Duckling.AmountOfMoney.EN.NZ.Rules
( rules
) where
import Data.HashMap.Strict (HashMap)
import Data.String
import Data.Text (Text)
import Prelude
import Duckling.AmountOfMoney.Helpers
import Duckling.AmountOfMoney.Types (Currency(..))
import Duckling.Numeral.Helpers (isPositive)
import Duckling.Regex.Types
import Duckling.Types
import qualified Data.HashMap.Strict as HashMap
import qualified Data.Text as Text
import qualified Duckling.AmountOfMoney.Helpers as Helpers
import qualified Duckling.Numeral.Types as TNumeral
ruleAGrand :: Rule
ruleAGrand = Rule
{ name = "a grand"
@ -48,8 +53,22 @@ ruleGrand = Rule
_ -> Nothing
}
ruleDollarCoin :: Rule
ruleDollarCoin = Rule
{ name = "dollar coin"
, pattern =
[ regex "(nickel|dime|quarter)s?"
]
, prod = \tokens -> case tokens of
(Token RegexMatch (GroupMatch (match:_)):_) -> do
c <- HashMap.lookup (Text.toLower match) Helpers.dollarCoins
Just . Token AmountOfMoney . withValue c $ currencyOnly NZD
_ -> Nothing
}
rules :: [Rule]
rules =
[ ruleAGrand
, ruleGrand
, ruleDollarCoin
]

View File

@ -27,6 +27,26 @@ allExamples = concat
]
, examples (simple Dollar 10000)
[ "10 grand"
, "two hundred thousand nickels"
]
, examples (simple Dollar 1)
[ "four quarters"
, "ten dimes"
, "twenty nickels"
]
, examples (simple Dollar 0.1)
[ "dime"
, "a dime"
, "two nickels"
]
, examples (simple Dollar 0.25)
[ "quarter"
, "a quarter"
, "five nickels"
]
, examples (simple Dollar 0.05)
[ "nickel"
, "a nickel"
]
]

View File

@ -13,17 +13,22 @@ module Duckling.AmountOfMoney.EN.PH.Rules
( rules
) where
import Data.HashMap.Strict (HashMap)
import Data.String
import Data.Text (Text)
import Prelude
import Duckling.AmountOfMoney.Helpers
import Duckling.AmountOfMoney.Types (Currency(..))
import Duckling.Numeral.Helpers (isPositive)
import Duckling.Regex.Types
import Duckling.Types
import qualified Data.HashMap.Strict as HashMap
import qualified Data.Text as Text
import qualified Duckling.AmountOfMoney.Helpers as Helpers
import qualified Duckling.Numeral.Types as TNumeral
ruleAGrand :: Rule
ruleAGrand = Rule
{ name = "a grand"
@ -48,8 +53,22 @@ ruleGrand = Rule
_ -> Nothing
}
ruleDollarCoin :: Rule
ruleDollarCoin = Rule
{ name = "dollar coin"
, pattern =
[ regex "(nickel|dime|quarter)s?"
]
, prod = \tokens -> case tokens of
(Token RegexMatch (GroupMatch (match:_)):_) -> do
c <- HashMap.lookup (Text.toLower match) dollarCoins
Just . Token AmountOfMoney . withValue c $ Helpers.currencyOnly Dollar
_ -> Nothing
}
rules :: [Rule]
rules =
[ ruleAGrand
, ruleGrand
, ruleDollarCoin
]

View File

@ -143,6 +143,35 @@ ruleACurrency = Rule
_ -> Nothing
}
ruleADollarCoin :: Rule
ruleADollarCoin = Rule
{ name = "a <dollar coin>"
, pattern =
[ regex "an?"
, Predicate isDollarCoin
]
, prod = \tokens -> case tokens of
(_:
Token AmountOfMoney fd:
_) -> Just . Token AmountOfMoney $ fd
_ -> Nothing
}
ruleNumDollarCoins :: Rule
ruleNumDollarCoins = Rule
{ name = "X <dollar coins>"
, pattern =
[ Predicate isNatural
, Predicate isDollarCoin
]
, prod = \tokens -> case tokens of
(Token Numeral NumeralData{TNumeral.value = c}:
Token AmountOfMoney AmountOfMoneyData{TAmountOfMoney.value = Just d,
TAmountOfMoney.currency = cur}:
_) -> Just . Token AmountOfMoney $ withValue (c * d) $ currencyOnly cur
_ -> Nothing
}
ruleIntersectAndXCents :: Rule
ruleIntersectAndXCents = Rule
{ name = "intersect (and X cents)"
@ -329,6 +358,8 @@ rules =
, ruleACurrency
, ruleBucks
, ruleCent
, ruleADollarCoin
, ruleNumDollarCoins
, ruleDinars
, ruleDirham
, ruleIntersect

View File

@ -27,6 +27,26 @@ allExamples = concat
]
, examples (simple TTD 10000)
[ "10 grand"
, "two hundred thousand nickels"
]
, examples (simple TTD 1)
[ "four quarters"
, "ten dimes"
, "twenty nickels"
]
, examples (simple TTD 0.1)
[ "dime"
, "a dime"
, "two nickels"
]
, examples (simple TTD 0.25)
[ "quarter"
, "a quarter"
, "five nickels"
]
, examples (simple TTD 0.05)
[ "nickel"
, "a nickel"
]
]

View File

@ -13,17 +13,22 @@ module Duckling.AmountOfMoney.EN.TT.Rules
( rules
) where
import Data.HashMap.Strict (HashMap)
import Data.String
import Data.Text (Text)
import Prelude
import Duckling.AmountOfMoney.Helpers
import Duckling.AmountOfMoney.Types (Currency(..))
import Duckling.Numeral.Helpers (isPositive)
import Duckling.Regex.Types
import Duckling.Types
import qualified Data.HashMap.Strict as HashMap
import qualified Data.Text as Text
import qualified Duckling.AmountOfMoney.Helpers as Helpers
import qualified Duckling.Numeral.Types as TNumeral
ruleAGrand :: Rule
ruleAGrand = Rule
{ name = "a grand"
@ -48,8 +53,22 @@ ruleGrand = Rule
_ -> Nothing
}
ruleDollarCoin :: Rule
ruleDollarCoin = Rule
{ name = "dollar coin"
, pattern =
[ regex "(nickel|dime|quarter)s?"
]
, prod = \tokens -> case tokens of
(Token RegexMatch (GroupMatch (match:_)):_) -> do
c <- HashMap.lookup (Text.toLower match) Helpers.dollarCoins
Just . Token AmountOfMoney . withValue c $ currencyOnly TTD
_ -> Nothing
}
rules :: [Rule]
rules =
[ ruleAGrand
, ruleGrand
, ruleDollarCoin
]

View File

@ -27,6 +27,26 @@ allExamples = concat
]
, examples (simple USD 10000)
[ "10 grand"
, "two hundred thousand nickels"
]
, examples (simple USD 1)
[ "four quarters"
, "ten dimes"
, "twenty nickels"
]
, examples (simple USD 0.1)
[ "dime"
, "a dime"
, "two nickels"
]
, examples (simple USD 0.25)
[ "quarter"
, "a quarter"
, "five nickels"
]
, examples (simple USD 0.05)
[ "nickel"
, "a nickel"
]
]

View File

@ -13,17 +13,22 @@ module Duckling.AmountOfMoney.EN.US.Rules
( rules
) where
import Data.HashMap.Strict (HashMap)
import Data.String
import Data.Text (Text)
import Prelude
import Duckling.AmountOfMoney.Helpers
import Duckling.AmountOfMoney.Types (Currency(..))
import Duckling.Numeral.Helpers (isPositive)
import Duckling.Regex.Types
import Duckling.Types
import qualified Data.HashMap.Strict as HashMap
import qualified Data.Text as Text
import qualified Duckling.AmountOfMoney.Helpers as Helpers
import qualified Duckling.Numeral.Types as TNumeral
ruleAGrand :: Rule
ruleAGrand = Rule
{ name = "a grand"
@ -46,8 +51,22 @@ ruleGrand = Rule
_ -> Nothing
}
ruleDollarCoin :: Rule
ruleDollarCoin = Rule
{ name = "dollar coin"
, pattern =
[ regex "(nickel|dime|quarter)s?"
]
, prod = \tokens -> case tokens of
(Token RegexMatch (GroupMatch (match:_)):_) -> do
c <- HashMap.lookup (Text.toLower match) Helpers.dollarCoins
Just . Token AmountOfMoney . withValue c $ currencyOnly USD
_ -> Nothing
}
rules :: [Rule]
rules =
[ ruleAGrand
, ruleGrand
, ruleDollarCoin
]

View File

@ -27,6 +27,26 @@ allExamples = concat
]
, examples (simple Dollar 10000)
[ "10 grand"
, "two hundred thousand nickels"
]
, examples (simple Dollar 1)
[ "four quarters"
, "ten dimes"
, "twenty nickels"
]
, examples (simple Dollar 0.1)
[ "dime"
, "a dime"
, "two nickels"
]
, examples (simple Dollar 0.25)
[ "quarter"
, "a quarter"
, "five nickels"
]
, examples (simple Dollar 0.05)
[ "nickel"
, "a nickel"
]
]

View File

@ -13,17 +13,22 @@ module Duckling.AmountOfMoney.EN.ZA.Rules
( rules
) where
import Data.HashMap.Strict (HashMap)
import Data.String
import Data.Text (Text)
import Prelude
import Duckling.AmountOfMoney.Helpers
import Duckling.AmountOfMoney.Types (Currency(..))
import Duckling.Numeral.Helpers (isPositive)
import Duckling.Regex.Types
import Duckling.Types
import qualified Data.HashMap.Strict as HashMap
import qualified Data.Text as Text
import qualified Duckling.AmountOfMoney.Helpers as Helpers
import qualified Duckling.Numeral.Types as TNumeral
ruleAGrand :: Rule
ruleAGrand = Rule
{ name = "a grand"
@ -48,8 +53,22 @@ ruleGrand = Rule
_ -> Nothing
}
ruleDollarCoin :: Rule
ruleDollarCoin = Rule
{ name = "dollar coin"
, pattern =
[ regex "(nickel|dime|quarter)s?"
]
, prod = \tokens -> case tokens of
(Token RegexMatch (GroupMatch (match:_)):_) -> do
c <- HashMap.lookup (Text.toLower match) Helpers.dollarCoins
Just . Token AmountOfMoney . withValue c $ currencyOnly Dollar
_ -> Nothing
}
rules :: [Rule]
rules =
[ ruleAGrand
, ruleGrand
, ruleDollarCoin
]

View File

@ -7,13 +7,14 @@
{-# LANGUAGE GADTs #-}
{-# LANGUAGE NamedFieldPuns #-}
module Duckling.AmountOfMoney.Helpers
( currencyOnly
, isSimpleAmountOfMoney
, isCent
, isCents
, isDollarCoin
, isCurrencyOnly
, isDime
, isMoneyWithValue
@ -23,10 +24,14 @@ module Duckling.AmountOfMoney.Helpers
, withMax
, withMin
, withValue
, dollarCoins
)
where
import Data.HashMap.Strict (HashMap)
import Data.Maybe (isJust)
import Data.String
import Data.Text (Text)
import Prelude
import Duckling.AmountOfMoney.Types (Currency (..), AmountOfMoneyData (..))
@ -34,6 +39,22 @@ import Duckling.Numeral.Types (getIntValue, isInteger)
import Duckling.Dimensions.Types
import Duckling.Types hiding (Entity(..))
import qualified Data.HashMap.Strict as HashMap
import qualified Data.Text as Text
-- -----------------------------------------------------------------
-- Dollar coin Types
dollarCoins :: HashMap Text Double
dollarCoins = HashMap.fromList
[ ("nickel", 0.05)
, ("nickels", 0.05)
, ("dime", 0.1)
, ("dimes", 0.1)
, ("quarter", 0.25)
, ("quarters", 0.25)
]
-- -----------------------------------------------------------------
-- Patterns
@ -56,6 +77,12 @@ isCurrencyOnly (Token AmountOfMoney AmountOfMoneyData
{value = Nothing, minValue = Nothing, maxValue = Nothing}) = True
isCurrencyOnly _ = False
isDollarCoin :: Predicate
isDollarCoin (Token AmountOfMoney AmountOfMoneyData{value = Just d, currency}) =
elem d [0.05, 0.1, 0.25] && elem currency [Dollar, AUD, CAD, JMD,
NZD, SGD, TTD, USD]
isDollarCoin _ = False
isSimpleAmountOfMoney :: Predicate
isSimpleAmountOfMoney (Token AmountOfMoney AmountOfMoneyData
{value = Just _, minValue = Nothing, maxValue = Nothing}) = True