-- 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 LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}

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"
  , pattern =
    [ regex "a grand"
    ]
  , prod = \_ -> Just . Token AmountOfMoney . withValue 1000 $ currencyOnly CAD
  }

ruleGrand :: Rule
ruleGrand = Rule
  { name = "<amount> grand"
  , pattern =
    [ Predicate isPositive
    , regex "grand"
    ]
  , prod = \case
      (Token Numeral TNumeral.NumeralData{TNumeral.value = v}:_)
        -> Just . Token AmountOfMoney . withValue (1000 * v) $ currencyOnly CAD
      _ -> 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
  ]


-- 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 OverloadedStrings #-}

module Duckling.AmountOfMoney.EN.GB.Corpus
  ( allExamples
  , negativeExamples
  ) where

import Data.String
import Data.Text (Text)
import Prelude

import Duckling.AmountOfMoney.Types
import Duckling.Testing.Types

allExamples :: [Example]
allExamples = concat
  [ examples (simple GBP 1000)
             [ "a grand"
             , "1 grand"
             ]
  , 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]
negativeExamples =
  [ "grand"
  ]


-- 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 LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}

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"
  , pattern =
    [ regex "a grand"
    ]
  , prod = \_ -> Just . Token AmountOfMoney . withValue 1000 $ currencyOnly GBP
  }

ruleGrand :: Rule
ruleGrand = Rule
  { name = "<amount> grand"
  , pattern =
    [ Predicate isPositive
    , regex "grand"
    ]
  , prod = \case
      (Token Numeral TNumeral.NumeralData{TNumeral.value = v}:_)
        -> Just . Token AmountOfMoney . withValue (1000 * v) $ currencyOnly GBP
      _ -> 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
  ]


-- 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 OverloadedStrings #-}

module Duckling.AmountOfMoney.EN.IE.Corpus
  ( allExamples
  , negativeExamples
  ) where

import Data.String
import Data.Text (Text)
import Prelude

import Duckling.AmountOfMoney.Types
import Duckling.Testing.Types

allExamples :: [Example]
allExamples = concat
  [ examples (simple Dollar 1000)
             [ "a grand"
             , "1 grand"
             ]
  , 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"
             ]
  ]

negativeExamples :: [Text]
negativeExamples =
  [ "grand"
  ]


-- 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 LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}

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

ruleAGrand :: Rule
ruleAGrand = Rule
  { name = "a grand"
  , pattern =
    [ regex "a grand"
    ]
  , prod = \_ -> Just . Token AmountOfMoney . withValue 1000
                 $ currencyOnly Dollar
  }

ruleGrand :: Rule
ruleGrand = Rule
  { name = "<amount> grand"
  , pattern =
    [ Predicate isPositive
    , regex "grand"
    ]
  , prod = \case
      (Token Numeral TNumeral.NumeralData{TNumeral.value = v}:_)
        -> Just . Token AmountOfMoney . withValue (1000 * v)
           $ currencyOnly Dollar
      _ -> 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
  ]


-- 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 OverloadedStrings #-}

module Duckling.AmountOfMoney.EN.IN.Corpus
  ( allExamples
  , negativeExamples
  ) where

import Data.String
import Data.Text (Text)
import Prelude

import Duckling.AmountOfMoney.Types
import Duckling.Testing.Types

allExamples :: [Example]
allExamples = concat
  [ examples (simple Dollar 1000)
             [ "a grand"
             , "1 grand"
             ]
  , 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"
             ]
  ]

negativeExamples :: [Text]
negativeExamples =
  [ "grand"
  ]


-- 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 LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}

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"
  , pattern =
    [ regex "a grand"
    ]
  , prod = \_ -> Just . Token AmountOfMoney . withValue 1000 $ currencyOnly Dollar
  }

ruleGrand :: Rule
ruleGrand = Rule
  { name = "<amount> grand"
  , pattern =
    [ Predicate isPositive
    , regex "grand"
    ]
  , prod = \case
      (Token Numeral TNumeral.NumeralData{TNumeral.value = v}:_)
        -> Just . Token AmountOfMoney . withValue (1000 * v) $ currencyOnly Dollar
      _ -> 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
  ]


-- 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 OverloadedStrings #-}

module Duckling.AmountOfMoney.EN.JM.Corpus
  ( allExamples
  , negativeExamples
  ) where

import Data.String
import Data.Text (Text)
import Prelude

import Duckling.AmountOfMoney.Types
import Duckling.Testing.Types

allExamples :: [Example]
allExamples = concat
  [ examples (simple JMD 1000)
             [ "a grand"
             , "1 grand"
             ]
  , 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"
  ]


-- 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 LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}

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"
  , pattern =
    [ regex "a grand"
    ]
  , prod = \_ -> Just . Token AmountOfMoney . withValue 1000
                 $ currencyOnly JMD
  }

ruleGrand :: Rule
ruleGrand = Rule
  { name = "<amount> grand"
  , pattern =
    [ Predicate isPositive
    , regex "grand"
    ]
  , prod = \case
      (Token Numeral TNumeral.NumeralData{TNumeral.value = v}:_)
        -> Just . Token AmountOfMoney . withValue (1000 * v)
           $ currencyOnly JMD
      _ -> 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
  ]


-- 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 OverloadedStrings #-}

module Duckling.AmountOfMoney.EN.NZ.Corpus
  ( allExamples
  , negativeExamples
  ) where

import Data.String
import Data.Text (Text)
import Prelude

import Duckling.AmountOfMoney.Types
import Duckling.Testing.Types

allExamples :: [Example]
allExamples = concat
  [ examples (simple NZD 1000)
             [ "a grand"
             , "1 grand"
             ]
  , 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"
             ]
  ]

negativeExamples :: [Text]
negativeExamples =
  [ "grand"
  ]


-- 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 LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}

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"
  , pattern =
    [ regex "a grand"
    ]
  , prod = \_ -> Just . Token AmountOfMoney . withValue 1000
                 $ currencyOnly NZD
  }

ruleGrand :: Rule
ruleGrand = Rule
  { name = "<amount> grand"
  , pattern =
    [ Predicate isPositive
    , regex "grand"
    ]
  , prod = \case
      (Token Numeral TNumeral.NumeralData{TNumeral.value = v}:_)
        -> Just . Token AmountOfMoney . withValue (1000 * v)
           $ currencyOnly NZD
      _ -> 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
  ]


-- 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 OverloadedStrings #-}

module Duckling.AmountOfMoney.EN.PH.Corpus
  ( allExamples
  , negativeExamples
  ) where

import Data.String
import Data.Text (Text)
import Prelude

import Duckling.AmountOfMoney.Types
import Duckling.Testing.Types

allExamples :: [Example]
allExamples = concat
  [ examples (simple Dollar 1000)
             [ "a grand"
             , "1 grand"
             ]
  , 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"
             ]
  ]

negativeExamples :: [Text]
negativeExamples =
  [ "grand"
  ]


-- 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 LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}

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"
  , pattern =
    [ regex "a grand"
    ]
  , prod = \_ -> Just . Token AmountOfMoney . withValue 1000
                 $ currencyOnly Dollar
  }

ruleGrand :: Rule
ruleGrand = Rule
  { name = "<amount> grand"
  , pattern =
    [ Predicate isPositive
    , regex "grand"
    ]
  , prod = \case
      (Token Numeral TNumeral.NumeralData{TNumeral.value = v}:_)
        -> Just . Token AmountOfMoney . withValue (1000 * v)
           $ currencyOnly Dollar
      _ -> 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
  ]


-- 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 OverloadedStrings #-}

module Duckling.AmountOfMoney.EN.TT.Corpus
  ( allExamples
  , negativeExamples
  ) where

import Data.String
import Data.Text (Text)
import Prelude

import Duckling.AmountOfMoney.Types
import Duckling.Testing.Types

allExamples :: [Example]
allExamples = concat
  [ examples (simple TTD 1000)
             [ "a grand"
             , "1 grand"
             ]
  , 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"
             ]
  ]

negativeExamples :: [Text]
negativeExamples =
  [ "grand"
  ]


-- 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 LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}

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"
  , pattern =
    [ regex "a grand"
    ]
  , prod = \_ -> Just . Token AmountOfMoney . withValue 1000
                 $ currencyOnly TTD
  }

ruleGrand :: Rule
ruleGrand = Rule
  { name = "<amount> grand"
  , pattern =
    [ Predicate isPositive
    , regex "grand"
    ]
  , prod = \case
      (Token Numeral TNumeral.NumeralData{TNumeral.value = v}:_)
        -> Just . Token AmountOfMoney . withValue (1000 * v)
           $ currencyOnly TTD
      _ -> 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
  ]


-- 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 OverloadedStrings #-}

module Duckling.AmountOfMoney.EN.US.Corpus
  ( allExamples
  , negativeExamples
  ) where

import Data.String
import Data.Text (Text)
import Prelude

import Duckling.AmountOfMoney.Types
import Duckling.Testing.Types

allExamples :: [Example]
allExamples = concat
  [ examples (simple USD 1000)
             [ "a grand"
             , "1 grand"
             ]
  , 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"
             ]
  ]

negativeExamples :: [Text]
negativeExamples =
  [ "grand"
  ]


-- 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 LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}

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"
  , pattern =
    [ regex "a grand"
    ]
  , prod = \_ -> Just . Token AmountOfMoney . withValue 1000 $ currencyOnly USD
  }

ruleGrand :: Rule
ruleGrand = Rule
  { name = "<amount> grand"
  , pattern =
    [ Predicate isPositive
    , regex "grand"
    ]
  , prod = \case
      (Token Numeral TNumeral.NumeralData{TNumeral.value = v}:_)
        -> Just . Token AmountOfMoney . withValue (1000 * v) $ currencyOnly USD
      _ -> 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
  ]


-- 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 OverloadedStrings #-}

module Duckling.AmountOfMoney.EN.ZA.Corpus
  ( allExamples
  , negativeExamples
  ) where

import Data.String
import Data.Text (Text)
import Prelude

import Duckling.AmountOfMoney.Types
import Duckling.Testing.Types

allExamples :: [Example]
allExamples = concat
  [ examples (simple Dollar 1000)
             [ "a grand"
             , "1 grand"
             ]
  , 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"
             ]
  ]

negativeExamples :: [Text]
negativeExamples =
  [ "grand"
  ]


-- 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 LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}

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"
  , pattern =
    [ regex "a grand"
    ]
  , prod = \_ -> Just . Token AmountOfMoney . withValue 1000
                 $ currencyOnly Dollar
  }

ruleGrand :: Rule
ruleGrand = Rule
  { name = "<amount> grand"
  , pattern =
    [ Predicate isPositive
    , regex "grand"
    ]
  , prod = \case
      (Token Numeral TNumeral.NumeralData{TNumeral.value = v}:_)
        -> Just . Token AmountOfMoney . withValue (1000 * v)
           $ currencyOnly Dollar
      _ -> 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
  ]


-- 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 OverloadedStrings #-}

module Duckling.AmountOfMoney.ES.Corpus
  ( corpus
  ) where

import Data.String
import Prelude

import Duckling.AmountOfMoney.Types
import Duckling.Locale
import Duckling.Resolve
import Duckling.Testing.Types

corpus :: Corpus
corpus = (testContext {locale = makeLocale ES Nothing}, testOptions, allExamples)

allExamples :: [Example]
allExamples = concat
  [ examples (simple Dollar 10)
             [ "$10"
             , "10$"
             , "diez dollars"
             , "diez dÃ³lares"
             ]
  , examples (simple Dollar 10000)
             [ "$10.000"
             , "10K$"
             , "$10k"
             ]
  , examples (simple USD 1.23)
             [ "USD1,23"
             ]
  , examples (simple EUR 20)
             [ "20â‚¬"
             , "20 euros"
             , "20 Euro"
             , "20 Euros"
             , "EUR 20"
             ]
  , examples (simple EUR 29.99)
             [ "EUR29,99"
             ]
  , examples (simple Pound 9)
             [ "Â£9"
             , "nueve pounds"
             , "9 libras"
             ]
  , examples (simple GBP 3.01)
             [ "GBP3,01"
             , "GBP 3,01"
             , "3 gbp 1 centavo"
             , "3 gbp y 1 centavo"
             ]
  , examples (simple PTS 15)
             [ "15 Pt"
             , "15pta"
             , "15Ptas"
             ]
  , examples (between Dollar (10, 20))
             [ "entre 10 y 20 dÃ³lares"
             , "de $10 y $20"
             , "$10 - 20 dÃ³lares"
             , "10 - 20 $"
             ]
  , examples (under Dollar 10)
             [ "menos de 10 dÃ³lares"
             , "no mÃ¡s de $10"
             ]
  , examples (above Dollar 10)
             [ "no menos de 10 dÃ³lares"
             , "mÃ¡s de $10"
             ]
  ]


-- 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 LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}

module Duckling.AmountOfMoney.ES.Rules
  ( rules
  ) where

import Data.Maybe
import Data.String
import Prelude

import Duckling.AmountOfMoney.Helpers
import Duckling.AmountOfMoney.Types (Currency(..), AmountOfMoneyData (..))
import Duckling.Dimensions.Types
import Duckling.Numeral.Helpers (isNatural, isPositive)
import Duckling.Numeral.Types (NumeralData (..))
import Duckling.Types
import qualified Duckling.AmountOfMoney.Types as TAmountOfMoney
import qualified Duckling.Numeral.Types as TNumeral

ruleUnitAmount :: Rule
ruleUnitAmount = Rule
  { name = "<unit> <amount>"
  , pattern =
    [ Predicate isCurrencyOnly
    , Predicate isPositive
    ]
  , prod = \case
      (Token AmountOfMoney AmountOfMoneyData{TAmountOfMoney.currency = c}:
       Token Numeral NumeralData{TNumeral.value = v}:
       _) -> Just . Token AmountOfMoney . withValue v $ currencyOnly c
      _ -> Nothing
  }

ruleDollar :: Rule
ruleDollar = Rule
  { name = "dollar"
  , pattern =
    [ regex "d(Ã³|o)lar(es)?"
    ]
  , prod = \_ -> Just . Token AmountOfMoney $ currencyOnly Dollar
  }

ruleCent :: Rule
ruleCent = Rule
  { name = "cent"
  , pattern =
    [ regex "centavos?"
    ]
  , prod = \_ -> Just . Token AmountOfMoney $ currencyOnly Cent
  }

rulePounds :: Rule
rulePounds = Rule
  { name = "Â£"
  , pattern =
    [ regex "(pound|libra)s?"
    ]
  , prod = \_ -> Just . Token AmountOfMoney $ currencyOnly Pound
  }

ruleIntersectAndNumeral :: Rule
ruleIntersectAndNumeral = Rule
  { name = "intersect (and number)"
  , pattern =
    [ Predicate isWithoutCents
    , regex "y"
    , Predicate isNatural
    ]
  , prod = \tokens -> case tokens of
      (Token AmountOfMoney fd:
       _:
       Token Numeral NumeralData{TNumeral.value = c}:
       _) -> Just . Token AmountOfMoney $ withCents c fd
      _ -> Nothing
  }

ruleIntersectXCents :: Rule
ruleIntersectXCents = Rule
  { name = "intersect (X cents)"
  , pattern =
    [ Predicate isWithoutCents
    , Predicate isCents
    ]
  , prod = \tokens -> case tokens of
      (Token AmountOfMoney fd:
       Token AmountOfMoney AmountOfMoneyData{TAmountOfMoney.value = Just c}:
       _) -> Just . Token AmountOfMoney $ withCents c fd
      _ -> Nothing
  }

ruleIntersectAndXCents :: Rule
ruleIntersectAndXCents = Rule
  { name = "intersect (and X cents)"
  , pattern =
    [ Predicate isWithoutCents
    , regex "y"
    , Predicate isCents
    ]
  , prod = \tokens -> case tokens of
      (Token AmountOfMoney fd:
       _:
       Token AmountOfMoney AmountOfMoneyData{TAmountOfMoney.value = Just c}:
       _) -> Just . Token AmountOfMoney $ withCents c fd
      _ -> Nothing
  }

ruleIntersect :: Rule
ruleIntersect = Rule
  { name = "intersect"
  , pattern =
    [ Predicate isWithoutCents
    , Predicate isNatural
    ]
  , prod = \tokens -> case tokens of
      (Token AmountOfMoney fd:
       Token Numeral NumeralData{TNumeral.value = c}:
       _) -> Just . Token AmountOfMoney $ withCents c fd
      _ -> Nothing
  }

ruleIntervalBetweenNumeral :: Rule
ruleIntervalBetweenNumeral = Rule
  { name = "between|from <numeral> to|and <amount-of-money>"
  , pattern =
    [ regex "de|entre"
    , Predicate isPositive
    , regex "a|y"
    , Predicate isSimpleAmountOfMoney
    ]
  , prod = \case
      (_:
       Token Numeral NumeralData{TNumeral.value = from}:
       _:
       Token AmountOfMoney AmountOfMoneyData{TAmountOfMoney.value = Just to,
                                             TAmountOfMoney.currency = c}:
       _) | from < to ->
        Just $ Token AmountOfMoney $ withInterval (from, to) $ currencyOnly c
      _ -> Nothing
  }

ruleIntervalBetween :: Rule
ruleIntervalBetween = Rule
  { name = "between|from <amount-of-money> to|and <amount-of-money>"
  , pattern =
    [ regex "de|entre"
    , Predicate isSimpleAmountOfMoney
    , regex "a|y"
    , Predicate isSimpleAmountOfMoney
    ]
  , prod = \case
      (_:
       Token AmountOfMoney AmountOfMoneyData{TAmountOfMoney.value = Just from,
                                             TAmountOfMoney.currency = c1}:
       _:
       Token AmountOfMoney AmountOfMoneyData{TAmountOfMoney.value = Just to,
                                             TAmountOfMoney.currency = c2}:
       _) | from < to && c1 == c2 ->
        Just $ Token AmountOfMoney $ withInterval (from, to) $ currencyOnly c1
      _ -> Nothing
  }

ruleIntervalNumeralDash :: Rule
ruleIntervalNumeralDash = Rule
  { name = "<numeral> - <amount-of-money>"
  , pattern =
    [ Predicate isNatural
    , regex "-"
    , Predicate isSimpleAmountOfMoney
    ]
  , prod = \case
      (Token Numeral NumeralData{TNumeral.value = from}:
       _:
       Token AmountOfMoney AmountOfMoneyData{TAmountOfMoney.value = Just to,
                                             TAmountOfMoney.currency = c}:
       _) | from < to->
         Just $ Token AmountOfMoney $ withInterval (from, to) $ currencyOnly c
      _ -> Nothing
  }

ruleIntervalDash :: Rule
ruleIntervalDash = Rule
  { name = "<amount-of-money> - <amount-of-money>"
  , pattern =
    [ Predicate isSimpleAmountOfMoney
    , regex "-"
    , Predicate isSimpleAmountOfMoney
    ]
  , prod = \case
      (Token AmountOfMoney AmountOfMoneyData{TAmountOfMoney.value = Just from,
                                             TAmountOfMoney.currency = c1}:
       _:
       Token AmountOfMoney AmountOfMoneyData{TAmountOfMoney.value = Just to,
                                             TAmountOfMoney.currency = c2}:
       _) | from < to && c1 == c2 ->
        Just $ Token AmountOfMoney $ withInterval (from, to) $ currencyOnly c1
      _ -> Nothing
  }

ruleIntervalMax :: Rule
ruleIntervalMax = Rule
  { name = "less/no more than <amount-of-money>"
  , pattern =
    [ regex "menos de|no mÃ¡s de"
    , Predicate isSimpleAmountOfMoney
    ]
  , prod = \case
      (_:
       Token AmountOfMoney AmountOfMoneyData{TAmountOfMoney.value = Just to,
                                             TAmountOfMoney.currency = c}:
       _) -> Just $ Token AmountOfMoney $ withMax to $ currencyOnly c
      _ -> Nothing
  }

ruleIntervalMin :: Rule
ruleIntervalMin = Rule
  { name = "no less/more than <amount-of-money>"
  , pattern =
    [ regex "mÃ¡s de|no menos de"
    , Predicate isSimpleAmountOfMoney
    ]
  , prod = \case
      (_:
       Token AmountOfMoney AmountOfMoneyData{TAmountOfMoney.value = Just to,
                                             TAmountOfMoney.currency = c}:
       _) -> Just $ Token AmountOfMoney $ withMin to $ currencyOnly c
      _ -> Nothing
  }

rules :: [Rule]
rules =
  [ ruleUnitAmount
  , ruleCent
  , ruleDollar
  , ruleIntersect
  , ruleIntersectAndNumeral
  , ruleIntersectAndXCents
  , ruleIntersectXCents
  , rulePounds
  , ruleIntervalBetweenNumeral
  , ruleIntervalBetween
  , ruleIntervalNumeralDash
  , ruleIntervalDash
  , ruleIntervalMax
  , ruleIntervalMin
  ]


-- 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 OverloadedStrings #-}

module Duckling.AmountOfMoney.FR.Corpus
  ( corpus
  ) where

import Data.String
import Prelude

import Duckling.AmountOfMoney.Types
import Duckling.Locale
import Duckling.Resolve
import Duckling.Testing.Types

corpus :: Corpus
corpus = (testContext {locale = makeLocale FR Nothing}, testOptions, allExamples)

allExamples :: [Example]
allExamples = concat
  [ examples (simple Dollar 10)
             [ "$10"
             , "10$"
             , "dix dollars"
             ]
  , examples (simple Dollar 10000)
             [ "$10.000"
             , "10K$"
             , "$10k"
             , "10 000 dollars"
             , "10 000,00 $"
             ]
  , examples (simple USD 1.23)
             [ "USD1,23"
             , "1 USD et 23 centimes"
             , "1 USD 23 cents"
             ]
  , examples (simple EUR 20)
             [ "20â‚¬"
             , "20 euros"
             , "20 Euro"
             , "20 Euros"
             , "EUR 20"
             ]
  , examples (simple EUR 29.99)
             [ "EUR29,99"
             ]
  , examples (simple Unnamed 3)
             [ "3 balles"
             , "Ã  peu prÃ¨s 3 pouloutes"
             ]
  , examples (simple Pound 9)
             [ "exactement Â£9"
             , "neuf pounds"
             , "quasi neuf livres"
             ]
  , examples (simple GBP 3.01)
             [ "GBP3,01"
             , "GBP 3,01"
             ]
  , examples (simple ILS 10)
             [ "dix shekels"
             ]
  , examples (simple Rial 10)
             [ "dix rials"
             ]
  , examples (simple Riyal 10)
             [ "dix riyals"
             ]
  , examples (between EUR (10, 20))
             [ "entre 10 et 20 euro"
             , "entre 10 euro et 20 euro"
             , "10 - 20 euro"
             , "10 euro - 20 euro"
             ]
  , examples (above EUR 10)
             [ "au moins 10 euro"
             , "plus que 10 euros"
             , "plus de 10 euros"
             ]
  , examples (under Dollar 10)
             [ "en-dessous de 10 dollars"
             , "moins de 10 dollars"
             , "pas plus de 10 dollars"
             ]
  ]


-- 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 LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}

module Duckling.AmountOfMoney.FR.Rules
  ( rules
  ) where

import Data.Maybe
import Data.String
import Prelude

import Duckling.AmountOfMoney.Helpers
import Duckling.AmountOfMoney.Types (Currency (..), AmountOfMoneyData (..))
import Duckling.Dimensions.Types
import Duckling.Numeral.Helpers (isNatural, isPositive)
import Duckling.Numeral.Types (NumeralData (..))
import Duckling.Types
import qualified Duckling.AmountOfMoney.Types as TAmountOfMoney
import qualified Duckling.Numeral.Types as TNumeral

ruleUnitAmount :: Rule
ruleUnitAmount = Rule
  { name = "<unit> <amount>"
  , pattern =
    [ Predicate isCurrencyOnly
    , Predicate isPositive
    ]
  , prod = \case
      (Token AmountOfMoney AmountOfMoneyData{TAmountOfMoney.currency = c}:
       Token Numeral NumeralData{TNumeral.value = v}:
       _) -> Just . Token AmountOfMoney . withValue v $ currencyOnly c
      _ -> Nothing
  }

ruleIntersectAndNumeral :: Rule
ruleIntersectAndNumeral = Rule
  { name = "intersect (and number)"
  , pattern =
    [ Predicate isWithoutCents
    , regex "et"
    , Predicate isNatural
    ]
  , prod = \tokens -> case tokens of
      (Token AmountOfMoney fd:
       _:
       Token Numeral NumeralData{TNumeral.value = c}:
       _) -> Just . Token AmountOfMoney $ withCents c fd
      _ -> Nothing
  }

rulePrecision :: Rule
rulePrecision = Rule
  { name = "precision"
  , pattern =
    [ regex "exactement|quasi|plus ou moins|environ|autour de|(a|Ã ) peu pr(e|Ã¨)s"
    , Predicate isMoneyWithValue
    ]
  , prod = \tokens -> case tokens of
      (_:token:_) -> Just token
      _ -> Nothing
  }

ruleCent :: Rule
ruleCent = Rule
  { name = "cent"
  , pattern =
    [ regex "cent(ime)?s?"
    ]
  , prod = \_ -> Just . Token AmountOfMoney $ currencyOnly Cent
  }

ruleIntersectXCents :: Rule
ruleIntersectXCents = Rule
  { name = "intersect (X cents)"
  , pattern =
    [ Predicate isWithoutCents
    , Predicate isCents
    ]
  , prod = \tokens -> case tokens of
      (Token AmountOfMoney fd:
       Token AmountOfMoney AmountOfMoneyData{TAmountOfMoney.value = Just c}:
       _) -> Just . Token AmountOfMoney $ withCents c fd
      _ -> Nothing
  }

ruleIntervalBetweenNumeral :: Rule
ruleIntervalBetweenNumeral = Rule
  { name = "between|from <numeral> to|and <amount-of-money>"
  , pattern =
    [ regex "entre"
    , Predicate isPositive
    , regex "et"
    , Predicate isSimpleAmountOfMoney
    ]
  , prod = \tokens -> case tokens of
      (_:
       Token Numeral NumeralData{TNumeral.value = from}:
       _:
       Token AmountOfMoney AmountOfMoneyData{TAmountOfMoney.value = Just to,
                  TAmountOfMoney.currency = c}:
       _) | from < to ->
        Just . Token AmountOfMoney . withInterval (from, to) $ currencyOnly c
      _ -> Nothing
  }

ruleIntervalBetween :: Rule
ruleIntervalBetween = Rule
  { name = "between|from <amount-of-money> to|and <amount-of-money>"
  , pattern =
    [ regex "entre"
    , Predicate isSimpleAmountOfMoney
    , regex "et"
    , Predicate isSimpleAmountOfMoney
    ]
  , prod = \tokens -> case tokens of
      (_:
       Token AmountOfMoney AmountOfMoneyData {
         TAmountOfMoney.value = Just from,
         TAmountOfMoney.currency = c1
       }:
       _:
       Token AmountOfMoney AmountOfMoneyData {
         TAmountOfMoney.value = Just to,
         TAmountOfMoney.currency = c2
       }:
       _) | c1 == c2, from < to ->
        Just . Token AmountOfMoney . withInterval (from, to) $ currencyOnly c1
      _ -> Nothing
  }

ruleIntervalNumeralDash :: Rule
ruleIntervalNumeralDash = Rule
  { name = "<numeral> - <amount-of-money>"
  , pattern =
    [ Predicate isNatural
    , regex "-"
    , Predicate isSimpleAmountOfMoney
    ]
  , prod = \tokens -> case tokens of
      (Token Numeral NumeralData{TNumeral.value = from}:
       _:
       Token AmountOfMoney AmountOfMoneyData{TAmountOfMoney.value = Just to,
                  TAmountOfMoney.currency = c}:
       _) | from < to ->
         Just . Token AmountOfMoney . withInterval (from, to) $ currencyOnly c
      _ -> Nothing
  }

ruleIntervalDash :: Rule
ruleIntervalDash = Rule
  { name = "<amount-of-money> - <amount-of-money>"
  , pattern =
    [ Predicate isSimpleAmountOfMoney
    , regex "-"
    , Predicate isSimpleAmountOfMoney
    ]
  , prod = \tokens -> case tokens of
      (Token AmountOfMoney AmountOfMoneyData{TAmountOfMoney.value = Just from,
                  TAmountOfMoney.currency = c1}:
       _:
       Token AmountOfMoney AmountOfMoneyData{TAmountOfMoney.value = Just to,
                  TAmountOfMoney.currency = c2}:
       _) | from < to && c1 == c2 ->
        Just . Token AmountOfMoney . withInterval (from, to) $ currencyOnly c1
      _ -> Nothing
  }

ruleIntervalMax :: Rule
ruleIntervalMax = Rule
  { name = "under/less/lower/no more than <amount-of-money>"
  , pattern =
    [ regex "(moins|pas plus|en-dessous) de"
    , Predicate isSimpleAmountOfMoney
    ]
  , prod = \tokens -> case tokens of
      (_:
       Token AmountOfMoney AmountOfMoneyData{TAmountOfMoney.value = Just to,
                  TAmountOfMoney.currency = c}:
       _) -> Just . Token AmountOfMoney . withMax to $ currencyOnly c
      _ -> Nothing
  }

ruleIntervalMin :: Rule
ruleIntervalMin = Rule
  { name = "over/above/at least/more than <amount-of-money>"
  , pattern =
    [ regex "plus (que|de)|au moins"
    , Predicate isSimpleAmountOfMoney
    ]
  , prod = \tokens -> case tokens of
      (_:
       Token AmountOfMoney AmountOfMoneyData{TAmountOfMoney.value = Just to,
                  TAmountOfMoney.currency = c}:
       _) -> Just . Token AmountOfMoney . withMin to $ currencyOnly c
      _ -> Nothing
  }

rulePounds :: Rule
rulePounds = Rule
  { name = "Â£"
  , pattern =
    [ regex "(livre|pound)s?"
    ]
  , prod = \_ -> Just . Token AmountOfMoney $ currencyOnly Pound
  }

ruleIntersectAndXCents :: Rule
ruleIntersectAndXCents = Rule
  { name = "intersect (and X cents)"
  , pattern =
    [ Predicate isWithoutCents
    , regex "et"
    , Predicate isCents
    ]
  , prod = \tokens -> case tokens of
      (Token AmountOfMoney fd:
       _:
       Token AmountOfMoney AmountOfMoneyData{TAmountOfMoney.value = Just c}:
       _) -> Just . Token AmountOfMoney $ withCents c fd
      _ -> Nothing
  }

ruleIntersect :: Rule
ruleIntersect = Rule
  { name = "intersect"
  , pattern =
    [ Predicate isWithoutCents
    , Predicate isNatural
    ]
  , prod = \tokens -> case tokens of
      (Token AmountOfMoney fd:
       Token Numeral NumeralData{TNumeral.value = c}:
       _) -> Just . Token AmountOfMoney $ withCents c fd
      _ -> Nothing
  }

ruleUnnamedCurrency :: Rule
ruleUnnamedCurrency = Rule
  { name = "unnamed currencyOnly"
  , pattern =
    [ regex "(balle|pouloute)s?"
    ]
  , prod = \_ -> Just . Token AmountOfMoney $ currencyOnly Unnamed
  }

rules :: [Rule]
rules =
  [ ruleUnitAmount
  , ruleCent
  , ruleIntersect
  , ruleIntersectAndNumeral
  , ruleIntersectAndXCents
  , ruleIntersectXCents
  , ruleIntervalBetween
  , ruleIntervalBetweenNumeral
  , ruleIntervalDash
  , ruleIntervalMax
  , ruleIntervalMin
  , ruleIntervalNumeralDash
  , rulePounds
  , rulePrecision
  , ruleUnnamedCurrency
  ]


-- 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 OverloadedStrings #-}

module Duckling.AmountOfMoney.GA.Corpus
  ( corpus
  ) where

import Data.String
import Prelude

import Duckling.AmountOfMoney.Types
import Duckling.Locale
import Duckling.Resolve
import Duckling.Testing.Types

corpus :: Corpus
corpus = (testContext {locale = makeLocale GA Nothing}, testOptions, allExamples)

allExamples :: [Example]
allExamples = concat
  [ examples (simple Dollar 10)
             [ "$10"
             , "10$"
             , "deich dollair"
             ]
  , examples (simple Cent 10)
             [ "deich ceinteanna"
             ]
  , examples (simple Dollar 10000)
             [ "$10,000"
             , "10K$"
             , "$10k"
             ]
  , examples (simple EUR 10000)
             [ "â‚¬10,000"
             , "10Kâ‚¬"
             , "â‚¬10k"
             ]
  , examples (simple USD 1.23)
             [ "USD1.23"
             ]
  , examples (simple Dollar 2.23)
             [ "2 dhollair agus 23 ceinteanna"
             , "dhÃ¡ dhollair 23 ceinteanna"
             , "2 dhollair 23"
             , "dhÃ¡ dhollair agus 23"
             ]
  , examples (simple EUR 20)
             [ "20â‚¬"
             , "20 euros"
             , "20 Euro"
             , "20 Euros"
             , "EUR 20"
             ]
  , examples (simple EUR 29.99)
             [ "EUR29.99"
             ]
  , examples (simple INR 20)
             [ "Rs. 20"
             , "Rs 20"
             , "20 RÃºpaÃ"
             , "20Rs"
             , "Rs20"
             ]
  , examples (simple INR 20.43)
             [ "20 Rupees 43"
             , "fiche rÃºpaÃ 43"
             ]
  , examples (simple INR 33)
             [ "INR33"
             ]
  , examples (simple Pound 9)
             [ "Â£9"
             , "naoi bpunt"
             ]
  , examples (simple GBP 3.01)
             [ "GBP3.01"
             , "GBP 3.01"
             ]
  ]


-- 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 LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}

module Duckling.AmountOfMoney.GA.Rules
  ( rules
  ) where

import Data.Maybe
import Data.String
import Prelude

import Duckling.AmountOfMoney.Helpers
import Duckling.AmountOfMoney.Types (Currency (..), AmountOfMoneyData (..))
import Duckling.Dimensions.Types
import Duckling.Numeral.Helpers (isNatural, isPositive)
import Duckling.Numeral.Types (NumeralData (..))
import Duckling.Types
import qualified Duckling.AmountOfMoney.Types as TAmountOfMoney
import qualified Duckling.Numeral.Types as TNumeral

ruleUnitAmount :: Rule
ruleUnitAmount = Rule
  { name = "<unit> <amount>"
  , pattern =
    [ Predicate isCurrencyOnly
    , Predicate isPositive
    ]
  , prod = \case
      (Token AmountOfMoney AmountOfMoneyData{TAmountOfMoney.currency = c}:
       Token Numeral NumeralData{TNumeral.value = v}:
       _) -> Just . Token AmountOfMoney . withValue v $ currencyOnly c
      _ -> Nothing
  }

ruleDollar :: Rule
ruleDollar = Rule
  { name = "$"
  , pattern =
    [ regex "n?dh?oll?ai?rs?"
    ]
  , prod = \_ -> Just . Token AmountOfMoney $ currencyOnly Dollar
  }

ruleCent :: Rule
ruleCent = Rule
  { name = "cent"
  , pattern =
    [ regex "cents?|g?ch?eint(eanna)?"
    ]
  , prod = \_ -> Just . Token AmountOfMoney $ currencyOnly Cent
  }

ruleThartArAmountofmoney :: Rule
ruleThartArAmountofmoney = Rule
  { name = "thart ar <amount-of-money>"
  , pattern =
    [ regex "thart( ar)?|beagnach|breis (is|agus)"
    , Predicate isMoneyWithValue
    ]
  , prod = \tokens -> case tokens of
      (_:token:_) -> Just token
      _ -> Nothing
  }

ruleIntersectXCents :: Rule
ruleIntersectXCents = Rule
  { name = "intersect (X cents)"
  , pattern =
    [ Predicate isWithoutCents
    , Predicate isCents
    ]
  , prod = \tokens -> case tokens of
      (Token AmountOfMoney fd:
       Token AmountOfMoney AmountOfMoneyData{TAmountOfMoney.value = Just c}:
       _) -> Just . Token AmountOfMoney $ withCents c fd
      _ -> Nothing
  }

rulePounds :: Rule
rulePounds = Rule
  { name = "Â£"
  , pattern =
    [ regex "pounds?|b?ph?unt"
    ]
  , prod = \_ -> Just . Token AmountOfMoney $ currencyOnly Pound
  }

ruleIntersectAndXCents :: Rule
ruleIntersectAndXCents = Rule
  { name = "intersect (and X cents)"
  , pattern =
    [ Predicate isWithoutCents
    , regex "agus|is"
    , Predicate isCents
    ]
  , prod = \tokens -> case tokens of
      (Token AmountOfMoney fd:
       _:
       Token AmountOfMoney AmountOfMoneyData{TAmountOfMoney.value = Just c}:
       _) -> Just . Token AmountOfMoney $ withCents c fd
      _ -> Nothing
  }

ruleIntersect :: Rule
ruleIntersect = Rule
  { name = "intersect"
  , pattern =
    [ Predicate isWithoutCents
    , Predicate isNatural
    ]
  , prod = \tokens -> case tokens of
      (Token AmountOfMoney fd:
       Token Numeral NumeralData{TNumeral.value = c}:
       _) -> Just . Token AmountOfMoney $ withCents c fd
      _ -> Nothing
  }

ruleInr :: Rule
ruleInr = Rule
  { name = "INR"
  , pattern =
    [ regex "r(Ãº|u)pa(Ã|i)"
    ]
  , prod = \_ -> Just . Token AmountOfMoney $ currencyOnly INR
  }

ruleIntersectAgusNumeral :: Rule
ruleIntersectAgusNumeral = Rule
  { name = "intersect (agus number)"
  , pattern =
    [ Predicate isWithoutCents
    , regex "agus|is"
    , Predicate isNatural
    ]
  , prod = \tokens -> case tokens of
      (Token AmountOfMoney fd:
       _:
       Token Numeral NumeralData{TNumeral.value = c}:
       _) -> Just . Token AmountOfMoney $ withCents c fd
      _ -> Nothing
  }

ruleAmountofmoneyGlan :: Rule
ruleAmountofmoneyGlan = Rule
  { name = "<amount-of-money> glan"
  , pattern =
    [ Predicate isMoneyWithValue
    , regex "glan|baileach|(go )?d(Ã|i)reach"
    ]
  , prod = \tokens -> case tokens of
      (token:_) -> Just token
      _ -> Nothing
  }

rules :: [Rule]
rules =
  [ ruleUnitAmount
  , ruleAmountofmoneyGlan
  , ruleCent
  , ruleDollar
  , ruleInr
  , ruleIntersect
  , ruleIntersectAgusNumeral
  , ruleIntersectAndXCents
  , ruleIntersectXCents
  , rulePounds
  , ruleThartArAmountofmoney
  ]


-- 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 LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}

module Duckling.AmountOfMoney.HR.Rules
  ( rules
  ) where

import Data.Maybe
import Data.String
import Data.Text (Text)
import Prelude
import qualified Data.Text as Text

import Duckling.AmountOfMoney.Helpers
import Duckling.AmountOfMoney.Types (Currency(..), AmountOfMoneyData (..))
import Duckling.Dimensions.Types
import Duckling.Numeral.Helpers (isNatural, isPositive)
import Duckling.Numeral.Types (NumeralData (..))
import Duckling.Regex.Types
import Duckling.Types
import qualified Duckling.AmountOfMoney.Types as TAmountOfMoney
import qualified Duckling.Numeral.Types as TNumeral

ruleACurrency :: Rule
ruleACurrency = Rule
  { name = "a <currency>"
  , pattern =
    [ regex "jed(an|na|no)"
    , Predicate isCurrencyOnly
    ]
  , prod = \tokens -> case tokens of
      (_:
       Token AmountOfMoney AmountOfMoneyData{TAmountOfMoney.currency = c}:
       _) -> Just . Token AmountOfMoney $ withValue 1 $ currencyOnly c
      _ -> Nothing
  }

ruleUnitAmount :: Rule
ruleUnitAmount = Rule
  { name = "<unit> <amount>"
  , pattern =
    [ Predicate isCurrencyOnly
    , Predicate isPositive
    ]
  , prod = \case
      (Token AmountOfMoney AmountOfMoneyData{TAmountOfMoney.currency = c}:
       Token Numeral NumeralData{TNumeral.value = v}:
       _) -> Just . Token AmountOfMoney . withValue v $ currencyOnly c
      _ -> Nothing
  }

ruleIntersectAndNumber :: Rule
ruleIntersectAndNumber = Rule
  { name = "intersect (and number)"
  , pattern =
    [ Predicate isWithoutCents
    , regex "i"
    , Predicate isNatural
    ]
  , prod = \tokens -> case tokens of
      (Token AmountOfMoney fd:
       _:
       Token Numeral NumeralData{TNumeral.value = c}:
       _) -> Just . Token AmountOfMoney $ withCents c fd
      _ -> Nothing
  }

ruleSar :: Rule
ruleSar = Rule
  { name = "SAR"
  , pattern =
    [ regex "saudijskirijal|saudi rijal?"
    ]
  , prod = \_ -> Just . Token AmountOfMoney $ currencyOnly SAR
  }

ruleDollar :: Rule
ruleDollar = Rule
  { name = "$"
  , pattern =
    [ regex "dolar(a|i|e)?"
    ]
  , prod = \_ -> Just . Token AmountOfMoney $ currencyOnly Dollar
  }

ruleCent :: Rule
ruleCent = Rule
  { name = "cent"
  , pattern =
    [ regex "cent(i|a)?|penij(i|a)?|c|Â¢|lp|lip(a|e)"
    ]
  , prod = \_ -> Just . Token AmountOfMoney $ currencyOnly Cent
  }

ruleIntersectIXLipa :: Rule
ruleIntersectIXLipa = Rule
  { name = "intersect (i X lipa)"
  , pattern =
    [ Predicate isWithoutCents
    , regex "i"
    , Predicate isCents
    ]
  , prod = \tokens -> case tokens of
      (Token AmountOfMoney fd:
       _:
       Token AmountOfMoney AmountOfMoneyData{TAmountOfMoney.value = Just c}:
       _) -> Just . Token AmountOfMoney $ withCents c fd
      _ -> Nothing
  }

ruleIntersectXCents :: Rule
ruleIntersectXCents = Rule
  { name = "intersect (X cents)"
  , pattern =
    [ Predicate isWithoutCents
    , Predicate isCents
    ]
  , prod = \tokens -> case tokens of
      (Token AmountOfMoney fd:
       Token AmountOfMoney AmountOfMoneyData{TAmountOfMoney.value = Just c}:
       _) -> Just . Token AmountOfMoney $ withCents c fd
      _ -> Nothing
  }

rulePound :: Rule
rulePound = Rule
  { name = "Â£"
  , pattern =
    [ regex "funt(a|e|i)?"
    ]
  , prod = \_ -> Just . Token AmountOfMoney $ currencyOnly Pound
  }

ruleHrk :: Rule
ruleHrk = Rule
  { name = "HRK"
  , pattern =
    [ regex "kn|(hrvatsk(a|ih|e) )?kun(a|e)"
    ]
  , prod = \_ -> Just . Token AmountOfMoney $ currencyOnly HRK
  }

ruleIntersect :: Rule
ruleIntersect = Rule
  { name = "intersect"
  , pattern =
    [ Predicate isWithoutCents
    , Predicate isNatural
    ]
  , prod = \tokens -> case tokens of
      (Token AmountOfMoney fd:
       Token Numeral NumeralData{TNumeral.value = c}:
       _) -> Just . Token AmountOfMoney $ withCents c fd
      _ -> Nothing
  }

ruleOtherPounds :: Rule
ruleOtherPounds = Rule
  { name = "other pounds"
  , pattern =
    [ regex "(egipatska|libanonska) ?funta"
    ]
  , prod = \tokens -> case tokens of
      (Token RegexMatch (GroupMatch (match:_)):_) -> case Text.toLower match of
        "egipatska"  -> Just . Token AmountOfMoney $ currencyOnly EGP
        "libanonska" -> Just . Token AmountOfMoney $ currencyOnly LBP
        _            -> Nothing
      _ -> Nothing
  }

ruleInr :: Rule
ruleInr = Rule
  { name = "INR"
  , pattern =
    [ regex "rupija?"
    ]
  , prod = \_ -> Just . Token AmountOfMoney $ currencyOnly INR
  }

ruleKwd :: Rule
ruleKwd = Rule
  { name = "KWD"
  , pattern =
    [ regex "kuvajtski ?dinar"
    ]
  , prod = \_ -> Just . Token AmountOfMoney $ currencyOnly KWD
  }

ruleQar :: Rule
ruleQar = Rule
  { name = "QAR"
  , pattern =
    [ regex "katarski(i| )rijal"
    ]
  , prod = \_ -> Just . Token AmountOfMoney $ currencyOnly QAR
  }

ruleAed :: Rule
ruleAed = Rule
  { name = "AED"
  , pattern =
    [ regex "drahma?"
    ]
  , prod = \_ -> Just . Token AmountOfMoney $ currencyOnly AED
  }

rulePrecision :: Rule
rulePrecision = Rule
  { name = "about|exactly <amount-of-money>"
  , pattern =
    [ regex "oko|otprilike|u blizini|skoro|pribliÅ¾no"
    , Predicate isMoneyWithValue
    ]
  , prod = \tokens -> case tokens of
      (_:token:_) -> Just token
      _ -> Nothing
  }

ruleIntervalNumeralDash :: Rule
ruleIntervalNumeralDash = Rule
  { name = "<numeral> - <amount-of-money>"
  , pattern =
    [ Predicate isNatural
    , regex "-"
    , Predicate isSimpleAmountOfMoney
    ]
  , prod = \tokens -> case tokens of
      (Token Numeral NumeralData{TNumeral.value = from}:
       _:
       Token AmountOfMoney AmountOfMoneyData{TAmountOfMoney.value = Just to,
                  TAmountOfMoney.currency = c}:
       _) | from < to->
         Just . Token AmountOfMoney . withInterval (from, to) $ currencyOnly c
      _ -> Nothing
  }

ruleIntervalDash :: Rule
ruleIntervalDash = Rule
  { name = "<amount-of-money> - <amount-of-money>"
  , pattern =
    [ Predicate isSimpleAmountOfMoney
    , regex "-"
    , Predicate isSimpleAmountOfMoney
    ]
  , prod = \tokens -> case tokens of
      (Token AmountOfMoney AmountOfMoneyData{TAmountOfMoney.value = Just from,
                  TAmountOfMoney.currency = c1}:
       _:
       Token AmountOfMoney AmountOfMoneyData{TAmountOfMoney.value = Just to,
                  TAmountOfMoney.currency = c2}:
       _) | from < to && c1 == c2 ->
        Just . Token AmountOfMoney . withInterval (from, to) $ currencyOnly c1
      _ -> Nothing
  }

ruleIntervalBetweenNumeral1 :: Rule
ruleIntervalBetweenNumeral1 = Rule
  { name = "between|from <numeral> to|and <amount-of-money>"
  , pattern =
    [ regex "od|otprilike|pribliÅ¾no"
    , Predicate isPositive
    , regex "do"
    , Predicate isSimpleAmountOfMoney
    ]
  , prod = \tokens -> case tokens of
      (_:
       Token Numeral NumeralData{TNumeral.value = from}:
       _:
       Token AmountOfMoney AmountOfMoneyData{TAmountOfMoney.value = Just to,
                  TAmountOfMoney.currency = c}:
       _) | from < to ->
        Just . Token AmountOfMoney . withInterval (from, to) $ currencyOnly c
      _ -> Nothing
  }

ruleIntervalBetweenNumeral2 :: Rule
ruleIntervalBetweenNumeral2 = Rule
  { name = "between|from <numeral> to|and <amount-of-money>"
  , pattern =
    [ regex "izmedju"
    , Predicate isPositive
    , regex "i"
    , Predicate isSimpleAmountOfMoney
    ]
  , prod = \tokens -> case tokens of
      (_:
       Token Numeral NumeralData{TNumeral.value = from}:
       _:
       Token AmountOfMoney AmountOfMoneyData{TAmountOfMoney.value = Just to,
                  TAmountOfMoney.currency = c}:
       _) | from < to ->
        Just . Token AmountOfMoney . withInterval (from, to) $ currencyOnly c
      _ -> Nothing
  }

ruleIntervalBetween1 :: Rule
ruleIntervalBetween1 = Rule
  { name = "between|from <amount-of-money> to|and <amount-of-money>"
  , pattern =
    [ regex "od|otprilike"
    , Predicate isSimpleAmountOfMoney
    , regex "do"
    , Predicate isSimpleAmountOfMoney
    ]
  , prod = \tokens -> case tokens of
      (_:
       Token AmountOfMoney AmountOfMoneyData{TAmountOfMoney.value = Just from,
                  TAmountOfMoney.currency = c1}:
       _:
       Token AmountOfMoney AmountOfMoneyData{TAmountOfMoney.value = Just to,
                  TAmountOfMoney.currency = c2}:
       _) | from < to && c1 == c2 ->
        Just . Token AmountOfMoney . withInterval (from, to) $ currencyOnly c1
      _ -> Nothing
  }

ruleIntervalBetween2 :: Rule
ruleIntervalBetween2 = Rule
  { name = "between|from <amount-of-money> to|and <amount-of-money>"
  , pattern =
    [ regex "izmedju"
    , Predicate isSimpleAmountOfMoney
    , regex "i"
    , Predicate isSimpleAmountOfMoney
    ]
  , prod = \tokens -> case tokens of
      (_:
       Token AmountOfMoney AmountOfMoneyData{TAmountOfMoney.value = Just from,
                  TAmountOfMoney.currency = c1}:
       _:
       Token AmountOfMoney AmountOfMoneyData{TAmountOfMoney.value = Just to,
                  TAmountOfMoney.currency = c2}:
       _) | from < to && c1 == c2 ->
        Just . Token AmountOfMoney . withInterval (from, to) $ currencyOnly c1
      _ -> Nothing
  }

ruleIntervalMin :: Rule
ruleIntervalMin = Rule
  { name = "over/above/at least/more than <amount-of-money>"
  , pattern =
    [ regex "viÅ¡e od|najmanje|preko|iznad"
    , Predicate isSimpleAmountOfMoney
    ]
  , prod = \tokens -> case tokens of
      (_:
       Token AmountOfMoney AmountOfMoneyData{TAmountOfMoney.value = Just to,
                  TAmountOfMoney.currency = c}:
       _) -> Just . Token AmountOfMoney . withMin to $ currencyOnly c
      _ -> Nothing
  }

ruleIntervalMax :: Rule
ruleIntervalMax = Rule
  { name = "under/less/lower/no more than <amount-of-money>"
  , pattern =
    [ regex "ispod|manje od"
    , Predicate isSimpleAmountOfMoney
    ]
  , prod = \tokens -> case tokens of
      (_:
       Token AmountOfMoney AmountOfMoneyData{TAmountOfMoney.value = Just to,
                  TAmountOfMoney.currency = c}:
       _) -> Just . Token AmountOfMoney . withMax to $ currencyOnly c
      _ -> Nothing
  }

rules :: [Rule]
rules =
  [ ruleACurrency
  , ruleUnitAmount
  , ruleDollar
  , rulePound
  , ruleOtherPounds
  , ruleAed
  , ruleCent
  , ruleHrk
  , ruleInr
  , ruleIntersect
  , ruleIntersectAndNumber
  , ruleIntersectIXLipa
  , ruleIntersectXCents
  , ruleKwd
  , ruleQar
  , ruleSar
  , rulePrecision
  , ruleIntervalNumeralDash
  , ruleIntervalDash
  , ruleIntervalBetweenNumeral1
  , ruleIntervalBetweenNumeral2
  , ruleIntervalBetween1
  , ruleIntervalBetween2
  , ruleIntervalMin
  , ruleIntervalMax
  ]


-- 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 OverloadedStrings #-}

module Duckling.AmountOfMoney.ID.Corpus
  ( corpus
  ) where

import Data.String
import Prelude

import Duckling.AmountOfMoney.Types
import Duckling.Locale
import Duckling.Resolve
import Duckling.Testing.Types

corpus :: Corpus
corpus = (testContext {locale = makeLocale ID Nothing}, testOptions, allExamples)

allExamples :: [Example]
allExamples = concat
  [ examples (simple Dollar 10)
             [ "$10"
             , "10$"
             , "sepuluh dolar"
             ]
  , examples (simple Dollar 10000)
             [ "$10.000"
             , "10K$"
             , "$10k"
             ]
  , examples (simple USD 1.23)
             [ "USD1,23"
             ]
  , examples (simple Dollar 2)
             [ "2 dolar"
             , "dua dolar"
             ]
  , examples (simple EUR 20)
             [ "20â‚¬"
             , "20 euros"
             , "20 Euro"
             , "20 Euros"
             , "EUR 20"
             , "dua puluh Euro"
             ]
  , examples (simple EUR 29.99)
             [ "EUR29,99"
             ]
  , examples (simple IDR 315)
             [ "Rp. 315,00"
             ]
  , examples (simple IDR 20)
             [ "Rp 20"
             , "20 Rupiah"
             , "20Rp"
             , "Rp20"
             ]
  , examples (simple IDR 33000)
             [ "IDR33000"
             , "IDR 33.000"
             ]
  , examples (simple Pound 9)
             [ "Â£9"
             , "sembilan pound"
             , "sembilan pound sterling"
             ]
  , examples (simple GBP 3.01)
             [ "GBP3,01"
             , "GBP 3,01"
             ]
  , examples (simple JPY 10)
             [ "10 yen"
             , "10Â¥"
             , "10 Â¥."
             ]
  , examples (between Dollar(10, 20))
             [ "antara 10 sampai 20 dolar"
             , "dari 10 dolar sampai 20 dolar"
             , "sekitar 10 sampai 20 dolar"
             , "antara 10 hingga 20 dolar"
             , "sekitar 10 dolar hingga 20 dolar"
             , "kira-kira 10-20 dolar"
             , "10-20 dolar"
             ]
  , examples (between IDR(1000, 10000))
             [ "antara Rp1000 sampai Rp10000"
             , "dari 1000 Rupiah hingga 10000 Rupiah"
             , "sekitar 1000 sampai 10000 Rupiah"
             , "1000-10000 Rupiah"
             , "kira-kira Rp1000 sampai Rp10000"
             , "dari Rp1.000 sampai Rp10.000"
             , "antara 1.000 hingga 10.000 Rupiah"
             , "kira-kira 1.000-10.000 Rupiah"
             , "sekitar 1.000 hingga 10.000 Rupiah"
             ]
  , examples (under EUR 7)
             [ "kurang dari 7 euro"
             , "di bawah EUR 7"
             , "tidak sampai 7 euro"
             , "lebih murah dari EUR 7"
             ]
  , examples (under IDR 500)
             [ "kurang dari 500 Rupiah"
             , "tidak sampai Rp500"
             , "di bawah Rp 500"
             , "lebih murah dari 500 rupiah"
             ]
  , examples (above USD 1.42)
             [ "di atas USD1,42"
             , "lebih dari USD1,42"
             , "melebihi USD1,42"
             , "melewati USD1,42"
             ]
  , examples (above IDR 33000)
             [ "di atas 33.000 Rupiah"
             , "lebih dari Rp33000"
             , "melebihi Rp33.000"
             , "melewati 33000 rupiah"
             ]
  ]


-- 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 LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}

module Duckling.AmountOfMoney.ID.Rules
  ( rules
  ) where

import Data.Maybe
import Data.String
import Prelude

import Duckling.AmountOfMoney.Helpers
import Duckling.AmountOfMoney.Types (Currency(..), AmountOfMoneyData(..))
import Duckling.Dimensions.Types
import Duckling.Numeral.Helpers (isNatural, isPositive)
import Duckling.Numeral.Types (NumeralData (..))
import Duckling.Types
import qualified Duckling.AmountOfMoney.Types as TAmountOfMoney
import qualified Duckling.Numeral.Types as TNumeral

ruleUnitAmount :: Rule
ruleUnitAmount = Rule
  { name = "<unit> <amount>"
  , pattern =
    [ Predicate isCurrencyOnly
    , Predicate isPositive
    ]
  , prod = \case
      (Token AmountOfMoney AmountOfMoneyData{TAmountOfMoney.currency = c}:
       Token Numeral NumeralData{TNumeral.value = v}:
       _) -> Just . Token AmountOfMoney . withValue v $ currencyOnly c
      _ -> Nothing
  }

ruleDollar :: Rule
ruleDollar = Rule
  { name = "$"
  , pattern =
    [ regex "dolar?"
    ]
  , prod = \_ -> Just . Token AmountOfMoney $ currencyOnly Dollar
  }

ruleIdr :: Rule
ruleIdr = Rule
  { name = "IDR"
  , pattern =
    [ regex "rp\\.?|rupiah"
    ]
  , prod = \_ -> Just . Token AmountOfMoney $ currencyOnly IDR
  }

rulePounds :: Rule
rulePounds = Rule
  { name = "Â£"
  , pattern =
    [ regex "pound( sterling)?"
    ]
  , prod = \_ -> Just . Token AmountOfMoney $ currencyOnly Pound
  }

ruleIntersect :: Rule
ruleIntersect = Rule
  { name = "intersect"
  , pattern =
    [ Predicate isWithoutCents
    , Predicate isNatural
    ]
  , prod = \tokens -> case tokens of
      (Token AmountOfMoney fd:
       Token Numeral NumeralData{TNumeral.value = c}:
       _) -> Just . Token AmountOfMoney $ withCents c fd
      _ -> Nothing
  }

ruleJpy :: Rule
ruleJpy = Rule
  { name = "JPY"
  , pattern =
    [ regex "Â¥\\."
    ]
  , prod = \_ -> Just . Token AmountOfMoney $ currencyOnly JPY
  }

rulePrecision :: Rule
rulePrecision = Rule
  { name = "about|exactly <amount-of-money>"
  , pattern =
    [ regex "tepatnya|kira-kira|sekitar|hampir"
    , Predicate isMoneyWithValue
    ]
  , prod = \case
      (_:token:_) -> Just token
      _ -> Nothing
  }

ruleIntervalBetweenNumeral :: Rule
ruleIntervalBetweenNumeral = Rule
  { name = "between|from <numeral> to|and <amount-of-money>"
  , pattern =
    [ regex "sekitar|dari|antara"
    , Predicate isPositive
    , regex "sampai|hingga"
    , Predicate isSimpleAmountOfMoney
    ]
  , prod = \case
      (_:
       Token Numeral NumeralData{TNumeral.value = from}:
       _:
       Token AmountOfMoney AmountOfMoneyData{TAmountOfMoney.value = Just to,
                  TAmountOfMoney.currency = c}:
       _) | from < to ->
        Just . Token AmountOfMoney . withInterval (from, to) $ currencyOnly c
      _ -> Nothing
  }

ruleIntervalBetween :: Rule
ruleIntervalBetween = Rule
  { name = "between|from <amount-of-money> to|and <amount-of-money>"
  , pattern =
    [ regex "sekitar|dari|antara|kira-kira"
    , Predicate isSimpleAmountOfMoney
    , regex "sampai|hingga"
    , Predicate isSimpleAmountOfMoney
    ]
  , prod = \case
      (_:
       Token AmountOfMoney AmountOfMoneyData{TAmountOfMoney.value = Just from,
                  TAmountOfMoney.currency = c1}:
       _:
       Token AmountOfMoney AmountOfMoneyData{TAmountOfMoney.value = Just to,
                  TAmountOfMoney.currency = c2}:
       _) | from < to && c1 == c2 ->
        Just . Token AmountOfMoney . withInterval (from, to) $ currencyOnly c1
      _ -> Nothing
  }

ruleIntervalNumeralDash :: Rule
ruleIntervalNumeralDash = Rule
  { name = "<numeral> - <amount-of-money>"
  , pattern =
    [ Predicate isNatural
    , regex "\\-"
    , Predicate isSimpleAmountOfMoney
    ]
  , prod = \case
      (Token Numeral NumeralData{TNumeral.value = from}:
       _:
       Token AmountOfMoney AmountOfMoneyData{TAmountOfMoney.value = Just to,
                  TAmountOfMoney.currency = c}:
       _) | from < to ->
         Just . Token AmountOfMoney . withInterval (from, to) $ currencyOnly c
      _ -> Nothing
  }

ruleIntervalDash :: Rule
ruleIntervalDash = Rule
  { name = "<amount-of-money> - <amount-of-money>"
  , pattern =
    [ Predicate isSimpleAmountOfMoney
    , regex "\\-"
    , Predicate isSimpleAmountOfMoney
    ]
  , prod = \case
      (Token AmountOfMoney AmountOfMoneyData{TAmountOfMoney.value = Just from,
                  TAmountOfMoney.currency = c1}:
       _:
       Token AmountOfMoney AmountOfMoneyData{TAmountOfMoney.value = Just to,
                  TAmountOfMoney.currency = c2}:
       _) | from < to && c1 == c2 ->
        Just . Token AmountOfMoney . withInterval (from, to) $ currencyOnly c1
      _ -> Nothing
  }

ruleIntervalMax :: Rule
ruleIntervalMax = Rule
  { name = "under/less/lower/no more than <amount-of-money>"
  , pattern =
    [ regex "(kurang|lebih murah) dari|tidak sampai|di bawah"
    , Predicate isSimpleAmountOfMoney
    ]
  , prod = \case
      (_:
       Token AmountOfMoney AmountOfMoneyData{TAmountOfMoney.value = Just to,
                  TAmountOfMoney.currency = c}:
       _) -> Just . Token AmountOfMoney . withMax to $ currencyOnly c
      _ -> Nothing
  }

ruleIntervalMin :: Rule
ruleIntervalMin = Rule
  { name = "over/above/at least/more than <amount-of-money>"
  , pattern =
    [ regex "di atas|lebih dari|melebihi|melewati"
    , Predicate isSimpleAmountOfMoney
    ]
  , prod = \case
      (_:
       Token AmountOfMoney AmountOfMoneyData{TAmountOfMoney.value = Just to,
                  TAmountOfMoney.currency = c}:
       _) -> Just . Token AmountOfMoney . withMin to $ currencyOnly c
      _ -> Nothing
  }

rules :: [Rule]
rules =
  [ ruleUnitAmount
  , ruleDollar
  , ruleIdr
  , ruleIntersect
  , ruleJpy
  , rulePounds
  , rulePrecision
  , ruleIntervalBetweenNumeral
  , ruleIntervalBetween
  , ruleIntervalMax
  , ruleIntervalMin
  , ruleIntervalNumeralDash
  , ruleIntervalDash
  ]


-- 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 OverloadedStrings #-}

module Duckling.AmountOfMoney.IT.Corpus
  ( corpus
  ) where

import Data.String
import Prelude

import Duckling.AmountOfMoney.Types
import Duckling.Locale
import Duckling.Resolve
import Duckling.Testing.Types

corpus :: Corpus
corpus = (testContext {locale = makeLocale IT Nothing}, testOptions, allExamples)

allExamples :: [Example]
allExamples = concat
  [ examples (simple Dollar 10)
             [ "$10"
             , "10$"
             , "dieci dollari"
             ]
  , examples (simple Dollar 10000)
             [ "$10.000"
             , "10K$"
             , "$10k"
             , "10 000 dollari"
             , "10 000,00 $"
             ]
  , examples (simple USD 1.23)
             [ "USD1,23"
             , "1 USD e 23 centesimi"
             , "1 USD 23 centesimi"
             ]
  , examples (simple EUR 20)
             [ "20â‚¬"
             , "20 euro"
             , "20 Euro"
             , "20 Euro"
             , "EUR 20"
             ]
  , examples (simple EUR 29.99)
             [ "EUR29,99"
             ]
  , examples (simple Pound 9)
             [ "nove sterline"
             , "quasi nove sterline"
             ]
  , examples (simple GBP 3.01)
             [ "GBP3,01"
             , "GBP 3,01"
             ]
  , examples (between EUR (10, 20))
             [ "tra 10 e 20 euro"
             , "tra 10 euro e 20 euro"
             , "10 - 20 euro"
             , "10 euro - 20 euro"
             ]
  , examples (above EUR 10)
             [ "almeno 10 euro"
             , "piÃ¹ di 10 euro"
             , "piÃ¹ di 10 euro"
             ]
  , examples (under Dollar 10)
             [ "meno di 10 dollari"
             , "non piÃ¹ di 10 dollari"
             ]
  ]


-- 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 LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}

module Duckling.AmountOfMoney.IT.Rules
  ( rules
  ) where

import Data.Maybe
import Data.String
import Prelude
import qualified Data.Text as Text

import Duckling.AmountOfMoney.Helpers
import Duckling.AmountOfMoney.Types (Currency (..), AmountOfMoneyData (..))
import Duckling.Dimensions.Types
import Duckling.Numeral.Helpers (isNatural, isPositive)
import Duckling.Numeral.Types (NumeralData (..))
import Duckling.Regex.Types (GroupMatch (..))
import Duckling.Types
import qualified Duckling.AmountOfMoney.Types as TAmountOfMoney
import qualified Duckling.Numeral.Types as TNumeral

ruleUnitAmount :: Rule
ruleUnitAmount = Rule
  { name = "<unit> <amount>"
  , pattern =
    [ Predicate isCurrencyOnly
    , Predicate isPositive
    ]
  , prod = \case
      (Token AmountOfMoney AmountOfMoneyData{TAmountOfMoney.currency = c}:
       Token Numeral NumeralData{TNumeral.value = v}:
       _) -> Just . Token AmountOfMoney . withValue v $ currencyOnly c
      _ -> Nothing
  }

ruleIntersectAndNumeral :: Rule
ruleIntersectAndNumeral = Rule
  { name = "intersect (and number)"
  , pattern =
    [ Predicate isWithoutCents
    , regex "e"
    , Predicate isNatural
    ]
  , prod = \tokens -> case tokens of
      (Token AmountOfMoney fd:
       _:
       Token Numeral NumeralData{TNumeral.value = c}:
       _) -> Just . Token AmountOfMoney $ withCents c fd
      _ -> Nothing
  }

rulePrecision :: Rule
rulePrecision = Rule
  { name = "precision"
  , pattern =
    [ regex "esattamente|quasi|piÃ¹ o meno|circa"
    , Predicate isMoneyWithValue
    ]
  , prod = \tokens -> case tokens of
      (_:token:_) -> Just token
      _ -> Nothing
  }

ruleCent :: Rule
ruleCent = Rule
  { name = "cent"
  , pattern =
    [ regex "cent(esim)i?o?"
    ]
  , prod = \_ -> Just . Token AmountOfMoney $ currencyOnly Cent
  }

ruleIntersectXCents :: Rule
ruleIntersectXCents = Rule
  { name = "intersect (X cents)"
  , pattern =
    [ Predicate isWithoutCents
    , Predicate isCents
    ]
  , prod = \tokens -> case tokens of
      (Token AmountOfMoney fd:
       Token AmountOfMoney AmountOfMoneyData{TAmountOfMoney.value = Just c}:
       _) -> Just . Token AmountOfMoney $ withCents c fd
      _ -> Nothing
  }

ruleIntervalBetweenNumeral :: Rule
ruleIntervalBetweenNumeral = Rule
  { name = "between|from <numeral> to|and <amount-of-money>"
  , pattern =
    [ regex "tra"
    , Predicate isPositive
    , regex "e"
    , Predicate isSimpleAmountOfMoney
    ]
  , prod = \tokens -> case tokens of
      (_:
       Token Numeral NumeralData{TNumeral.value = from}:
       _:
       Token AmountOfMoney AmountOfMoneyData{TAmountOfMoney.value = Just to,
                  TAmountOfMoney.currency = c}:
       _) | from < to ->
        Just . Token AmountOfMoney . withInterval (from, to) $ currencyOnly c
      _ -> Nothing
  }

ruleIntervalBetween :: Rule
ruleIntervalBetween = Rule
  { name = "between|from <amount-of-money> to|and <amount-of-money>"
  , pattern =
    [ regex "tra"
    , Predicate isSimpleAmountOfMoney
    , regex "e"
    , Predicate isSimpleAmountOfMoney
    ]
  , prod = \tokens -> case tokens of
      (_:
       Token AmountOfMoney AmountOfMoneyData {
         TAmountOfMoney.value = Just from,
         TAmountOfMoney.currency = c1
       }:
       _:
       Token AmountOfMoney AmountOfMoneyData {
         TAmountOfMoney.value = Just to,
         TAmountOfMoney.currency = c2
       }:
       _) | c1 == c2, from < to ->
        Just . Token AmountOfMoney . withInterval (from, to) $ currencyOnly c1
      _ -> Nothing
  }

ruleIntervalNumeralDash :: Rule
ruleIntervalNumeralDash = Rule
  { name = "<numeral> - <amount-of-money>"
  , pattern =
    [ Predicate isNatural
    , regex "-"
    , Predicate isSimpleAmountOfMoney
    ]
  , prod = \tokens -> case tokens of
      (Token Numeral NumeralData{TNumeral.value = from}:
       _:
       Token AmountOfMoney AmountOfMoneyData{TAmountOfMoney.value = Just to,
                  TAmountOfMoney.currency = c}:
       _) | from < to ->
         Just . Token AmountOfMoney . withInterval (from, to) $ currencyOnly c
      _ -> Nothing
  }

ruleIntervalDash :: Rule
ruleIntervalDash = Rule
  { name = "<amount-of-money> - <amount-of-money>"
  , pattern =
    [ Predicate isSimpleAmountOfMoney
    , regex "-"
    , Predicate isSimpleAmountOfMoney
    ]
  , prod = \tokens -> case tokens of
      (Token AmountOfMoney AmountOfMoneyData{TAmountOfMoney.value = Just from,
                  TAmountOfMoney.currency = c1}:
       _:
       Token AmountOfMoney AmountOfMoneyData{TAmountOfMoney.value = Just to,
                  TAmountOfMoney.currency = c2}:
       _) | from < to && c1 == c2 ->
        Just . Token AmountOfMoney . withInterval (from, to) $ currencyOnly c1
      _ -> Nothing
  }

ruleIntervalMax :: Rule
ruleIntervalMax = Rule
  { name = "under/less/lower/no more than <amount-of-money>"
  , pattern =
    [ regex "(meno|non piÃ¹) di"
    , Predicate isSimpleAmountOfMoney
    ]
  , prod = \tokens -> case tokens of
      (_:
       Token AmountOfMoney AmountOfMoneyData{TAmountOfMoney.value = Just to,
                  TAmountOfMoney.currency = c}:
       _) -> Just . Token AmountOfMoney . withMax to $ currencyOnly c
      _ -> Nothing
  }

ruleIntervalMin :: Rule
ruleIntervalMin = Rule
  { name = "over/above/at least/more than <amount-of-money>"
  , pattern =
    [ regex "piÃ¹ di|almeno"
    , Predicate isSimpleAmountOfMoney
    ]
  , prod = \tokens -> case tokens of
      (_:
       Token AmountOfMoney AmountOfMoneyData{TAmountOfMoney.value = Just to,
                  TAmountOfMoney.currency = c}:
       _) -> Just . Token AmountOfMoney . withMin to $ currencyOnly c
      _ -> Nothing
  }

ruleCurrencies :: Rule
ruleCurrencies = Rule
  { name = "Â£, $"
  , pattern =
    [ regex "(dollari|sterline)"
    ]
  , prod = \case
      (Token RegexMatch (GroupMatch (match:_)):_) -> case Text.toLower match of
        "dollari"  -> Just . Token AmountOfMoney $ currencyOnly Dollar
        "sterline" -> Just . Token AmountOfMoney $ currencyOnly Pound
        _          -> Nothing
      _ -> Nothing
  }

ruleIntersectAndXCents :: Rule
ruleIntersectAndXCents = Rule
  { name = "intersect (and X cents)"
  , pattern =
    [ Predicate isWithoutCents
    , regex "e"
    , Predicate isCents
    ]
  , prod = \tokens -> case tokens of
      (Token AmountOfMoney fd:
       _:
       Token AmountOfMoney AmountOfMoneyData{TAmountOfMoney.value = Just c}:
       _) -> Just . Token AmountOfMoney $ withCents c fd
      _ -> Nothing
  }

ruleIntersect :: Rule
ruleIntersect = Rule
  { name = "intersect"
  , pattern =
    [ Predicate isWithoutCents
    , Predicate isNatural
    ]
  , prod = \tokens -> case tokens of
      (Token AmountOfMoney fd:
       Token Numeral NumeralData{TNumeral.value = c}:
       _) -> Just . Token AmountOfMoney $ withCents c fd
      _ -> Nothing
  }

rules :: [Rule]
rules =
  [ ruleUnitAmount
  , ruleCent
  , ruleIntersect
  , ruleIntersectAndNumeral
  , ruleIntersectAndXCents
  , ruleIntersectXCents
  , ruleIntervalBetween
  , ruleIntervalBetweenNumeral
  , ruleIntervalDash
  , ruleIntervalMax
  , ruleIntervalMin
  , ruleIntervalNumeralDash
  , ruleCurrencies
  , rulePrecision
  ]