Summary: Initialise AmountOfMoney for CA (Catalan) language

Reviewed By: stroxler

Differential Revision: D28296090

Pulled By: chessai

fbshipit-source-id: f02305a762ee3cbf357bbb0a65eef614d3d828c9
This commit is contained in:
leandro.guisandez@pgconocimiento.com 2021-05-12 11:26:09 -07:00 committed by Facebook GitHub Bot
parent 3e28d42a29
commit 213d1f12a5
7 changed files with 377 additions and 2 deletions

View File

@ -5,6 +5,9 @@
### Core
### Rulesets
* CA (Catalan)
* AmountOfMoney: **new!**
* EN (English)
* Time: Allow latent match for \<part-of-day\> \<latent-time-of-day\>
* Time: Avoid parsing phrases like 'two five' as times

View File

@ -0,0 +1,90 @@
-- 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.CA.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 CA Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat
[ examples (simple Dollar 10)
[ "$10"
, "10$"
, "deu dolars"
, "deu dòlars"
]
, 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"
, "vint euros"
]
, examples (simple EUR 29.99)
[ "EUR29,99"
, "29,99 euros"
, "29,99 €"
, "29,99€"
]
, examples (simple Pound 9)
[ "£9"
, "nou lliures"
, "9 lliures"
]
,examples (simple Pound 1)
[ "£1"
, "una lliura"
, "1 lliura"
]
, examples (simple GBP 3.01)
[ "GBP3,01"
, "GBP 3,01"
, "3 gbp 1 cèntims"
, "3 gbp i 1 cèntims"
]
, examples (simple PTS 15)
[ "15 Pt"
, "15pta"
, "15Ptas"
]
, examples (between Dollar (10, 20))
[ "entre 10 i 20 dòlars"
, "des de $10 fins a $20"
, "10$ - 20 dolars"
, "10 - 20 $"
]
, examples (under Dollar 10)
[ "menys de 10 dolars"
, "no més de 10$"
]
, examples (above Dollar 10)
[ "no menys de 10 dòlars"
, "més de 10$"
]
]

View File

@ -0,0 +1,254 @@
-- 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.CA.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(s)?"
]
, prod = \_ -> Just $ Token AmountOfMoney $ currencyOnly Dollar
}
ruleCent :: Rule
ruleCent = Rule
{ name = "cent"
, pattern =
[ regex "c(e|è)ntims?"
]
, prod = \_ -> Just $ Token AmountOfMoney $ currencyOnly Cent
}
rulePounds :: Rule
rulePounds = Rule
{ name = "£"
, pattern =
[ regex "(lliure|lliura)s?"
]
, prod = \_ -> Just $ Token AmountOfMoney $ currencyOnly Pound
}
ruleIntersectAndNumeral :: Rule
ruleIntersectAndNumeral = Rule
{ name = "intersect (and number)"
, pattern =
[ Predicate isWithoutCents
, regex "i"
, Predicate isNatural
]
, prod = \case
(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 = \case
(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 "i"
, Predicate isCents
]
, prod = \case
(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 = \case
(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 "des de|des d'|entre"
, Predicate isPositive
, regex "fins a|i"
, 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 "des de|des d'|entre"
, Predicate isSimpleAmountOfMoney
, regex "fins a|i"
, 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 "menys de|no m(e|é)s de|no m(e|é)s d'|menys d'"
, 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(e|é)s de|no menys de|m(e|é)s d'|no menys d'"
, 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
]

View File

@ -13,5 +13,7 @@ import Duckling.Dimensions.Types
allDimensions :: [Seal Dimension]
allDimensions =
[ Seal Numeral
[ Seal AmountOfMoney
, Seal Numeral
, Seal Ordinal
]

View File

@ -17,6 +17,7 @@ module Duckling.Rules.CA
import Duckling.Dimensions.Types
import Duckling.Locale
import qualified Duckling.AmountOfMoney.CA.Rules as AmountOfMoney
import qualified Duckling.Numeral.CA.Rules as Numeral
import qualified Duckling.Ordinal.CA.Rules as Ordinal
import Duckling.Types
@ -29,7 +30,7 @@ localeRules region (Seal (CustomDimension dim)) = dimLocaleRules region dim
localeRules _ _ = []
langRules :: Seal Dimension -> [Rule]
langRules (Seal AmountOfMoney) = []
langRules (Seal AmountOfMoney) = AmountOfMoney.rules
langRules (Seal CreditCardNumber) = []
langRules (Seal Distance) = []
langRules (Seal Duration) = []

View File

@ -225,6 +225,8 @@ library
, Duckling.AmountOfMoney.AR.Rules
, Duckling.AmountOfMoney.BG.Corpus
, Duckling.AmountOfMoney.BG.Rules
, Duckling.AmountOfMoney.CA.Corpus
, Duckling.AmountOfMoney.CA.Rules
, Duckling.AmountOfMoney.EN.AU.Corpus
, Duckling.AmountOfMoney.EN.AU.Rules
, Duckling.AmountOfMoney.EN.BZ.Corpus
@ -909,6 +911,7 @@ test-suite duckling-test
, Duckling.AmountOfMoney.AR.Tests
, Duckling.AmountOfMoney.EN.Tests
, Duckling.AmountOfMoney.BG.Tests
, Duckling.AmountOfMoney.CA.Tests
, Duckling.AmountOfMoney.ES.Tests
, Duckling.AmountOfMoney.FR.Tests
, Duckling.AmountOfMoney.GA.Tests

View File

@ -0,0 +1,22 @@
-- 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.
module Duckling.AmountOfMoney.CA.Tests
( tests ) where
import Data.String
import Prelude
import Test.Tasty
import Duckling.AmountOfMoney.CA.Corpus
import Duckling.Dimensions.Types
import Duckling.Testing.Asserts
tests :: TestTree
tests = testGroup "CA Tests"
[ makeCorpusTest [Seal AmountOfMoney] corpus
]