mirror of
https://github.com/facebook/duckling.git
synced 2024-11-30 23:33:33 +03:00
Added Amount of Money Dimension to Arabic language
Summary: Closes https://github.com/facebook/duckling/pull/134 Reviewed By: JonCoens Differential Revision: D6649920 Pulled By: patapizza fbshipit-source-id: 9c647c84f5ae4f3dc26cb0c7aa74abb097ea001a
This commit is contained in:
parent
fc574a448e
commit
89822776c6
126
Duckling/AmountOfMoney/AR/Corpus.hs
Normal file
126
Duckling/AmountOfMoney/AR/Corpus.hs
Normal file
@ -0,0 +1,126 @@
|
||||
-- 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. An additional grant
|
||||
-- of patent rights can be found in the PATENTS file in the same directory.
|
||||
|
||||
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Duckling.AmountOfMoney.AR.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 AR Nothing}, allExamples)
|
||||
|
||||
allExamples :: [Example]
|
||||
allExamples = concat
|
||||
[ examples (simple Dollar 1)
|
||||
[ "$1"
|
||||
, "1 دولار"
|
||||
]
|
||||
, examples (simple Dollar 10)
|
||||
[ "$10"
|
||||
, "$ 10"
|
||||
, "10 $"
|
||||
, "10$"
|
||||
, "10$"
|
||||
, "10 دولار"
|
||||
, "عشرة دولارات"
|
||||
]
|
||||
, examples (simple Cent 10)
|
||||
[ "10 سنتات"
|
||||
, "10 سنت"
|
||||
, "10 سينت"
|
||||
, "10 سينتات"
|
||||
, "10 c"
|
||||
, "10¢"
|
||||
]
|
||||
, examples (simple Dollar 1e4)
|
||||
[ "10000 دولار"
|
||||
, "$10,000"
|
||||
, "10000$"
|
||||
]
|
||||
, examples (simple EUR 20)
|
||||
[ "20 يورو"
|
||||
, "20 اورو"
|
||||
, "20 أورو"
|
||||
, "20€"
|
||||
, "20 €"
|
||||
]
|
||||
, examples (simple Pound 10)
|
||||
[ "10 جنيه"
|
||||
, "10 جنيهات"
|
||||
]
|
||||
, examples (simple Dollar 20.43)
|
||||
[ "20$ و 43c"
|
||||
, "$20 43"
|
||||
, "20$ 43c"
|
||||
, "20 دولار و43 سنت"
|
||||
, "20.43 $"
|
||||
]
|
||||
, examples (simple GBP 3)
|
||||
[ "3 جنيهات استرلينية"
|
||||
, "3 جنيه استرليني"
|
||||
]
|
||||
, examples (simple KWD 42)
|
||||
[ "42 KWD"
|
||||
, "42 دينار كويتي"
|
||||
]
|
||||
, examples (simple LBP 42)
|
||||
[ "42 LBP"
|
||||
, "42 ليرة لبنانية"
|
||||
, "42 ليرات لبنانية"
|
||||
]
|
||||
, examples (simple EGP 42)
|
||||
[ "42 EGP"
|
||||
, "42 جنيه مصري"
|
||||
, "42 جنيهات مصريه"
|
||||
]
|
||||
, examples (simple QAR 42)
|
||||
[ "42 QAR"
|
||||
, "42 ريال قطري"
|
||||
, "42 ريالات قطرية"
|
||||
]
|
||||
, examples (simple SAR 42)
|
||||
[ "42 SAR"
|
||||
, "42 ريال سعودي"
|
||||
]
|
||||
, examples (between Dollar (10, 20))
|
||||
[ "من 10 الى 20 دولار"
|
||||
, "بحدود 10-20 دولار"
|
||||
, "ما بين عشرة وعشرون دولار"
|
||||
, "من عشرة لعشرين دولار"
|
||||
, "حوالي 10$-20$"
|
||||
, "10-20 $"
|
||||
, "10-20 دولار"
|
||||
]
|
||||
, examples (under EUR 7)
|
||||
[ "تحت سبعة اورو"
|
||||
, "اقل من سبعة يورو"
|
||||
, "اقل من 7 يورو"
|
||||
]
|
||||
, examples (above Dollar 3.42)
|
||||
[ "اكثر من ثلاثة دولار و42 سينت"
|
||||
, "3.42$ على الاقل"
|
||||
]
|
||||
, examples (simple JOD 5)
|
||||
[ "5 دينار اردني"
|
||||
, "5 دنانير أردنية"
|
||||
]
|
||||
, examples (simple ILS 5)
|
||||
[ "5 شيقل"
|
||||
, "5 شواقل"
|
||||
, "خمسة شيكل"
|
||||
]
|
||||
]
|
403
Duckling/AmountOfMoney/AR/Rules.hs
Normal file
403
Duckling/AmountOfMoney/AR/Rules.hs
Normal file
@ -0,0 +1,403 @@
|
||||
-- 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. An additional grant
|
||||
-- of patent rights can be found in the PATENTS file in the same directory.
|
||||
|
||||
|
||||
{-# LANGUAGE GADTs #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Duckling.AmountOfMoney.AR.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.Types (NumeralData (..))
|
||||
import Duckling.Regex.Types
|
||||
import Duckling.Types
|
||||
import qualified Duckling.AmountOfMoney.Types as TAmountOfMoney
|
||||
import qualified Duckling.Numeral.Types as TNumeral
|
||||
|
||||
rulePounds :: Rule
|
||||
rulePounds = Rule
|
||||
{ name = "£"
|
||||
, pattern =
|
||||
[ regex "جنيه(ات)?"
|
||||
]
|
||||
, prod = \_ -> Just . Token AmountOfMoney $ currencyOnly Pound
|
||||
}
|
||||
|
||||
ruleDinars :: Rule
|
||||
ruleDinars = Rule
|
||||
{ name = "dinars"
|
||||
, pattern =
|
||||
[ regex "دينار|دنانير"
|
||||
]
|
||||
, prod = \_ -> Just . Token AmountOfMoney $ currencyOnly Dinar
|
||||
}
|
||||
|
||||
ruleDirhams :: Rule
|
||||
ruleDirhams = Rule
|
||||
{ name = "Dirhams"
|
||||
, pattern =
|
||||
[ regex "درا?هم"
|
||||
]
|
||||
, prod = \_ -> Just . Token AmountOfMoney $ currencyOnly Dirham
|
||||
}
|
||||
|
||||
ruleRiyals :: Rule
|
||||
ruleRiyals = Rule
|
||||
{ name = "Riyals"
|
||||
, pattern =
|
||||
[ regex "ريال(ات)?"
|
||||
]
|
||||
, prod = \_ -> Just . Token AmountOfMoney $ currencyOnly Riyal
|
||||
}
|
||||
|
||||
ruleDollars :: Rule
|
||||
ruleDollars = Rule
|
||||
{ name = "Dollars"
|
||||
, pattern =
|
||||
[ regex "دولار(ات)?"
|
||||
]
|
||||
, prod = \_ -> Just . Token AmountOfMoney $ currencyOnly Dollar
|
||||
}
|
||||
|
||||
ruleShekel :: Rule
|
||||
ruleShekel = Rule
|
||||
{ name = "Shekel"
|
||||
, pattern =
|
||||
[ regex "شي[كق]ل|شوا[كق]ل"
|
||||
]
|
||||
, prod = \_ -> Just . Token AmountOfMoney $ currencyOnly ILS
|
||||
}
|
||||
|
||||
ruleEuro :: Rule
|
||||
ruleEuro = Rule
|
||||
{ name = "Euro"
|
||||
, pattern =
|
||||
[ regex "[أاي]ورو"
|
||||
]
|
||||
, prod = \_ -> Just . Token AmountOfMoney $ currencyOnly EUR
|
||||
}
|
||||
|
||||
ruleOtherPounds :: Rule
|
||||
ruleOtherPounds = Rule
|
||||
{ name = "other pounds"
|
||||
, pattern =
|
||||
[ regex "جنيه(ات)? (مصر|استرلين)ي?[ةه]?"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token RegexMatch (GroupMatch (_:match:_)):
|
||||
_) -> case Text.toLower match of
|
||||
"مصر" -> Just . Token AmountOfMoney $ currencyOnly EGP
|
||||
"استرلين" -> Just . Token AmountOfMoney $ currencyOnly GBP
|
||||
_ -> Nothing
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleOtherDinars :: Rule
|
||||
ruleOtherDinars = Rule
|
||||
{ name = "dinars"
|
||||
, pattern =
|
||||
[ regex "(دينار|دنانير) ([أا]ردن|كويت|عراق)ي?[ةه]?"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token RegexMatch (GroupMatch (_:match:_)):
|
||||
_) -> case Text.toLower match of
|
||||
"كويت" -> Just . Token AmountOfMoney $ currencyOnly KWD
|
||||
"اردن" -> Just . Token AmountOfMoney $ currencyOnly JOD
|
||||
"أردن" -> Just . Token AmountOfMoney $ currencyOnly JOD
|
||||
"عراق" -> Just . Token AmountOfMoney $ currencyOnly IQD
|
||||
_ -> Nothing
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleOtherDirhams :: Rule
|
||||
ruleOtherDirhams = Rule
|
||||
{ name = "dirham"
|
||||
, pattern =
|
||||
[ regex "(درهم|دراهم) (اردن|أردن|مغرب)ي?[ةه]?"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token RegexMatch (GroupMatch (_:match:_)):
|
||||
_) -> case Text.toLower match of
|
||||
"إمارات" -> Just . Token AmountOfMoney $ currencyOnly AED
|
||||
"امارات" -> Just . Token AmountOfMoney $ currencyOnly AED
|
||||
"مغرب" -> Just . Token AmountOfMoney $ currencyOnly MAD
|
||||
_ -> Nothing
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleOtherRiyals :: Rule
|
||||
ruleOtherRiyals = Rule
|
||||
{ name = "riyals"
|
||||
, pattern =
|
||||
[ regex "(ريال|ريالات) (سعود|قطر)ي?[ةه]?"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token RegexMatch (GroupMatch (_:match:_)):
|
||||
_) -> case Text.toLower match of
|
||||
"قطر" -> Just . Token AmountOfMoney $ currencyOnly QAR
|
||||
"سعود" -> Just . Token AmountOfMoney $ currencyOnly SAR
|
||||
_ -> Nothing
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleCent :: Rule
|
||||
ruleCent = Rule
|
||||
{ name = "cent"
|
||||
, pattern =
|
||||
[ regex "سي?نت(ات)?"
|
||||
]
|
||||
, prod = \_ -> Just . Token AmountOfMoney $ currencyOnly Cent
|
||||
}
|
||||
|
||||
ruleLBP :: Rule
|
||||
ruleLBP = Rule
|
||||
{ name = "LBP"
|
||||
, pattern =
|
||||
[ regex "لير([ةه]|ات) لبناني[ةه]?"
|
||||
]
|
||||
, prod = \_ -> Just . Token AmountOfMoney $ currencyOnly LBP
|
||||
}
|
||||
|
||||
ruleIntersectAndXCents :: Rule
|
||||
ruleIntersectAndXCents = Rule
|
||||
{ name = "intersect (and X cents)"
|
||||
, pattern =
|
||||
[ financeWith TAmountOfMoney.value isJust
|
||||
, regex "و"
|
||||
, financeWith TAmountOfMoney.currency (== Cent)
|
||||
]
|
||||
, 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 =
|
||||
[ financeWith TAmountOfMoney.value isJust
|
||||
, dimension Numeral
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token AmountOfMoney fd:
|
||||
Token Numeral NumeralData {TNumeral.value = c}:
|
||||
_) -> Just . Token AmountOfMoney $ withCents c fd
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleIntersectAndNumeral :: Rule
|
||||
ruleIntersectAndNumeral = Rule
|
||||
{ name = "intersect (and number)"
|
||||
, pattern =
|
||||
[ financeWith TAmountOfMoney.value isJust
|
||||
, regex "و"
|
||||
, dimension Numeral
|
||||
]
|
||||
, 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 =
|
||||
[ financeWith TAmountOfMoney.value isJust
|
||||
, financeWith id $ \x -> case TAmountOfMoney.value x of
|
||||
Just v | v > 0 -> TAmountOfMoney.currency x == Cent
|
||||
_ -> False
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token AmountOfMoney fd:
|
||||
Token AmountOfMoney AmountOfMoneyData {TAmountOfMoney.value = Just c}:
|
||||
_) -> Just . Token AmountOfMoney $ withCents c fd
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
rulePrecision :: Rule
|
||||
rulePrecision = Rule
|
||||
{ name = "about|exactly <amount-of-money>"
|
||||
, pattern =
|
||||
[ regex "حوال[ي|ى]|تقريبا|بحدود"
|
||||
, dimension AmountOfMoney
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(_:token:_) -> Just token
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleIntervalBetweenNumeral :: Rule
|
||||
ruleIntervalBetweenNumeral = Rule
|
||||
{ name = "between|from <numeral> to|and <amount-of-money>"
|
||||
, pattern =
|
||||
[ regex "(من|(ما )?بين)( ال)?"
|
||||
, dimension Numeral
|
||||
, regex "(الى|حتى|و|ل)( ا?ل)?"
|
||||
, financeWith TAmountOfMoney.value isJust
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(_:
|
||||
Token Numeral NumeralData {TNumeral.value = from}:
|
||||
_:
|
||||
Token AmountOfMoney AmountOfMoneyData {TAmountOfMoney.value = Just to, TAmountOfMoney.currency = c}:
|
||||
_) ->
|
||||
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 "(من|(ما )?بين)( ال)?"
|
||||
, financeWith TAmountOfMoney.value isJust
|
||||
, regex "(الى|حتى|و|ل)( ا?ل)?"
|
||||
, financeWith TAmountOfMoney.value isJust
|
||||
]
|
||||
, 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 ->
|
||||
Just . Token AmountOfMoney . withInterval (from, to) $ currencyOnly c1
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleIntervalNumeralDash :: Rule
|
||||
ruleIntervalNumeralDash = Rule
|
||||
{ name = "<numeral> - <amount-of-money>"
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, regex "-"
|
||||
, financeWith TAmountOfMoney.value isJust
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral NumeralData {TNumeral.value = from}:
|
||||
_:
|
||||
Token AmountOfMoney AmountOfMoneyData {TAmountOfMoney.value = Just to, TAmountOfMoney.currency = c}:
|
||||
_) ->
|
||||
Just . Token AmountOfMoney . withInterval (from, to) $ currencyOnly c
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleIntervalDash :: Rule
|
||||
ruleIntervalDash = Rule
|
||||
{ name = "<amount-of-money> - <amount-of-money>"
|
||||
, pattern =
|
||||
[ financeWith TAmountOfMoney.value isJust
|
||||
, regex "-"
|
||||
, financeWith TAmountOfMoney.value isJust
|
||||
]
|
||||
, 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 ->
|
||||
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 "(حتى|[أا]قل من|تحت|(ما )?دون)|على ال[أا]كثر"
|
||||
, financeWith TAmountOfMoney.value isJust
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(_:
|
||||
Token AmountOfMoney AmountOfMoneyData {TAmountOfMoney.value = Just to, TAmountOfMoney.currency = c}:
|
||||
_) -> Just . Token AmountOfMoney . withMax to $ currencyOnly c
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleIntervalAtMost :: Rule
|
||||
ruleIntervalAtMost = Rule
|
||||
{ name = "under/less/lower/no more than <amount-of-money>"
|
||||
, pattern =
|
||||
[ regex "على ال[أا]كثر"
|
||||
, financeWith TAmountOfMoney.value isJust
|
||||
]
|
||||
, 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 = "at least/over/above/more than <amount-of-money>"
|
||||
, pattern =
|
||||
[ regex "فوق||[أا]كثر من|على ال[اأ]قل"
|
||||
, financeWith TAmountOfMoney.value isJust
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(_:
|
||||
Token AmountOfMoney AmountOfMoneyData {TAmountOfMoney.value = Just to, TAmountOfMoney.currency = c}:
|
||||
_) -> Just . Token AmountOfMoney . withMin to $ currencyOnly c
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleIntervalAtLeast :: Rule
|
||||
ruleIntervalAtLeast = Rule
|
||||
{ name = "<amount-of-money> at least"
|
||||
, pattern =
|
||||
[ financeWith TAmountOfMoney.value isJust
|
||||
, regex "على ال[اأ]قل"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token AmountOfMoney AmountOfMoneyData {TAmountOfMoney.value = Just to, TAmountOfMoney.currency = c}:
|
||||
_) -> Just . Token AmountOfMoney . withMin to $ currencyOnly c
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
rules :: [Rule]
|
||||
rules =
|
||||
[ ruleCent
|
||||
, rulePounds
|
||||
, ruleDinars
|
||||
, ruleDirhams
|
||||
, ruleRiyals
|
||||
, ruleDollars
|
||||
, ruleShekel
|
||||
, ruleEuro
|
||||
, ruleOtherPounds
|
||||
, ruleOtherDinars
|
||||
, ruleOtherDirhams
|
||||
, ruleOtherRiyals
|
||||
, ruleLBP
|
||||
, ruleIntersect
|
||||
, ruleIntersectAndNumeral
|
||||
, ruleIntersectAndXCents
|
||||
, ruleIntersectXCents
|
||||
, ruleIntervalBetweenNumeral
|
||||
, ruleIntervalBetween
|
||||
, ruleIntervalMax
|
||||
, ruleIntervalAtMost
|
||||
, ruleIntervalMin
|
||||
, ruleIntervalAtLeast
|
||||
, ruleIntervalNumeralDash
|
||||
, ruleIntervalDash
|
||||
, rulePrecision
|
||||
]
|
@ -146,6 +146,21 @@ allExamples = concat
|
||||
, "20 ringgit 43"
|
||||
, "twenty ringgit and 43"
|
||||
]
|
||||
, examples (simple Dinar 10)
|
||||
[ "10 dinars"
|
||||
]
|
||||
, examples (simple ILS 10)
|
||||
[ "ten shekels"
|
||||
, "10 ILS"
|
||||
]
|
||||
, examples (simple Riyal 10)
|
||||
[ "ten riyals"
|
||||
, "10 riyals"
|
||||
]
|
||||
, examples (simple Rial 10)
|
||||
[ "ten rials"
|
||||
, "10 rials"
|
||||
]
|
||||
, examples (between Dollar (10, 20))
|
||||
[ "between 10 and 20 dollars"
|
||||
, "from 10 dollars to 20 dollars"
|
||||
|
@ -10,21 +10,22 @@
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Duckling.AmountOfMoney.EN.Rules
|
||||
( rules ) where
|
||||
( rules
|
||||
) where
|
||||
|
||||
import Data.Maybe
|
||||
import qualified Data.Text as Text
|
||||
import Prelude
|
||||
import Data.String
|
||||
import Prelude
|
||||
import qualified Data.Text as Text
|
||||
|
||||
import Duckling.AmountOfMoney.Helpers
|
||||
import Duckling.AmountOfMoney.Types (Currency(..), AmountOfMoneyData (..))
|
||||
import qualified Duckling.AmountOfMoney.Types as TAmountOfMoney
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Numeral.Types (NumeralData (..))
|
||||
import qualified Duckling.Numeral.Types as TNumeral
|
||||
import Duckling.Regex.Types
|
||||
import Duckling.Types
|
||||
import qualified Duckling.AmountOfMoney.Types as TAmountOfMoney
|
||||
import qualified Duckling.Numeral.Types as TNumeral
|
||||
|
||||
rulePounds :: Rule
|
||||
rulePounds = Rule
|
||||
@ -72,7 +73,7 @@ ruleDinars = Rule
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token RegexMatch (GroupMatch (match:_)):_) -> case Text.toLower match of
|
||||
"kuwaiti" -> Just . Token AmountOfMoney $ currencyOnly KWD
|
||||
_ -> Nothing
|
||||
_ -> Nothing
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
@ -120,7 +121,9 @@ ruleACurrency = Rule
|
||||
, financeWith TAmountOfMoney.value isNothing
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(_:Token AmountOfMoney fd:_) -> Just . Token AmountOfMoney $ fd {TAmountOfMoney.value = Just 1}
|
||||
(_:
|
||||
Token AmountOfMoney fd:
|
||||
_) -> Just . Token AmountOfMoney $ fd {TAmountOfMoney.value = Just 1}
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
|
@ -65,4 +65,13 @@ allExamples = concat
|
||||
[ "GBP3,01"
|
||||
, "GBP 3,01"
|
||||
]
|
||||
, examples (simple ILS 10)
|
||||
[ "dix shekels"
|
||||
]
|
||||
, examples (simple Rial 10)
|
||||
[ "dix rials"
|
||||
]
|
||||
, examples (simple Riyal 10)
|
||||
[ "dix riyals"
|
||||
]
|
||||
]
|
||||
|
@ -40,6 +40,8 @@ currencies = HashMap.fromList
|
||||
, ("¢", Cent)
|
||||
, ("c", Cent)
|
||||
, ("$", Dollar)
|
||||
, ("dinar", Dinar)
|
||||
, ("dinars", Dinar)
|
||||
, ("dollar", Dollar)
|
||||
, ("dollars", Dollar)
|
||||
, ("egp", EGP)
|
||||
@ -55,17 +57,21 @@ currencies = HashMap.fromList
|
||||
, ("gbp", GBP)
|
||||
, ("hrk", HRK)
|
||||
, ("idr", IDR)
|
||||
, ("ils", ILS)
|
||||
, ("inr", INR)
|
||||
, ("iqd", IQD)
|
||||
, ("rs", INR)
|
||||
, ("rs.", INR)
|
||||
, ("rupee", INR)
|
||||
, ("rupees", INR)
|
||||
, ("jod", JOD)
|
||||
, ("¥", JPY)
|
||||
, ("jpy", JPY)
|
||||
, ("yen", JPY)
|
||||
, ("krw", KRW)
|
||||
, ("kwd", KWD)
|
||||
, ("lbp", LBP)
|
||||
, ("mad", MAD)
|
||||
, ("myr", MYR)
|
||||
, ("rm", MYR)
|
||||
, ("nok", NOK)
|
||||
@ -76,11 +82,17 @@ currencies = HashMap.fromList
|
||||
, ("pts", PTS)
|
||||
, ("qar", QAR)
|
||||
, ("₽", RUB)
|
||||
, ("rial", Rial)
|
||||
, ("rials", Rial)
|
||||
, ("riyal", Riyal)
|
||||
, ("riyals", Riyal)
|
||||
, ("ron", RON)
|
||||
, ("rub", RUB)
|
||||
, ("sar", SAR)
|
||||
, ("sek", SEK)
|
||||
, ("sgd", SGD)
|
||||
, ("shekel", ILS)
|
||||
, ("shekels", ILS)
|
||||
, ("usd", USD)
|
||||
, ("us$", USD)
|
||||
, ("vnd", VND)
|
||||
@ -90,7 +102,7 @@ ruleCurrencies :: Rule
|
||||
ruleCurrencies = Rule
|
||||
{ name = "currencies"
|
||||
, pattern =
|
||||
[ regex "(aed|aud|bgn|brl|byn|¢|c|\\$|dollars?|egp|(e|€)uro?s?|€|gbp|hrk|idr|inr|¥|jpy|krw|kwd|lbp|myr|rm|nok|£|pta?s?|qar|₽|rs\\.?|ron|rub|rupees?|sar|sek|sgb|us(d|\\$)|vnd|yen)"
|
||||
[ regex "(aed|aud|bgn|brl|byn|¢|c|\\$|dinars?|dollars?|egp|(e|€)uro?s?|€|gbp|hrk|idr|ils|inr|iqd|jod|¥|jpy|krw|kwd|lbp|mad|myr|rm|nok|£|pta?s?|qar|₽|rs\\.?|riy?als?|ron|rub|rupees?|sar|sek|sgb|shekels?|us(d|\\$)|vnd|yen)"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token RegexMatch (GroupMatch (match:_)):_) -> do
|
||||
|
@ -28,8 +28,12 @@ import Duckling.Resolve (Resolve(..))
|
||||
data Currency
|
||||
-- ambiguous
|
||||
= Cent
|
||||
| Dinar
|
||||
| Dirham
|
||||
| Dollar
|
||||
| Pound
|
||||
| Rial
|
||||
| Riyal
|
||||
| Unnamed -- e.g. bucks
|
||||
-- unambiguous
|
||||
| AED
|
||||
@ -42,11 +46,15 @@ data Currency
|
||||
| GBP
|
||||
| HRK
|
||||
| IDR
|
||||
| ILS
|
||||
| INR
|
||||
| IQD
|
||||
| JOD
|
||||
| JPY
|
||||
| KRW
|
||||
| KWD
|
||||
| LBP
|
||||
| MAD
|
||||
| MYR
|
||||
| NOK
|
||||
| PTS
|
||||
@ -64,6 +72,10 @@ instance ToJSON Currency where
|
||||
toJSON Cent = "cent"
|
||||
toJSON Dollar = "$"
|
||||
toJSON Pound = "\x00a3"
|
||||
toJSON Dinar = "dinar"
|
||||
toJSON Dirham = "dirham"
|
||||
toJSON Rial = "rial"
|
||||
toJSON Riyal = "riyal"
|
||||
toJSON Unnamed = "unknown"
|
||||
toJSON AED = "AED"
|
||||
toJSON AUD = "AUD"
|
||||
@ -75,11 +87,15 @@ instance ToJSON Currency where
|
||||
toJSON GBP = "GBP"
|
||||
toJSON HRK = "HRK"
|
||||
toJSON IDR = "IDR"
|
||||
toJSON ILS = "ILS"
|
||||
toJSON IQD = "IQD"
|
||||
toJSON INR = "INR"
|
||||
toJSON JOD = "JOD"
|
||||
toJSON JPY = "JPY"
|
||||
toJSON KRW = "KRW"
|
||||
toJSON KWD = "KWD"
|
||||
toJSON LBP = "LBP"
|
||||
toJSON MAD = "MAD"
|
||||
toJSON MYR = "MYR"
|
||||
toJSON NOK = "NOK"
|
||||
toJSON PTS = "PTS"
|
||||
|
@ -18,6 +18,7 @@ module Duckling.Rules.AR
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Locale
|
||||
import Duckling.Types
|
||||
import qualified Duckling.AmountOfMoney.AR.Rules as AmountOfMoney
|
||||
import qualified Duckling.Duration.AR.Rules as Duration
|
||||
import qualified Duckling.Numeral.AR.Rules as Numeral
|
||||
import qualified Duckling.Ordinal.AR.Rules as Ordinal
|
||||
@ -34,7 +35,7 @@ localeRules :: Region -> Some Dimension -> [Rule]
|
||||
localeRules _ _ = []
|
||||
|
||||
langRules :: Some Dimension -> [Rule]
|
||||
langRules (This AmountOfMoney) = []
|
||||
langRules (This AmountOfMoney) = AmountOfMoney.rules
|
||||
langRules (This Distance) = []
|
||||
langRules (This Duration) = Duration.rules
|
||||
langRules (This Email) = []
|
||||
|
@ -158,6 +158,8 @@ library
|
||||
, Duckling.Dimensions.ZH
|
||||
|
||||
-- AmountOfMoney
|
||||
, Duckling.AmountOfMoney.AR.Corpus
|
||||
, Duckling.AmountOfMoney.AR.Rules
|
||||
, Duckling.AmountOfMoney.EN.Corpus
|
||||
, Duckling.AmountOfMoney.EN.Rules
|
||||
, Duckling.AmountOfMoney.BG.Corpus
|
||||
@ -646,6 +648,7 @@ test-suite duckling-test
|
||||
, Duckling.Dimensions.Tests
|
||||
|
||||
-- AmountOfMoney
|
||||
, Duckling.AmountOfMoney.AR.Tests
|
||||
, Duckling.AmountOfMoney.EN.Tests
|
||||
, Duckling.AmountOfMoney.BG.Tests
|
||||
, Duckling.AmountOfMoney.ES.Tests
|
||||
|
24
tests/Duckling/AmountOfMoney/AR/Tests.hs
Normal file
24
tests/Duckling/AmountOfMoney/AR/Tests.hs
Normal file
@ -0,0 +1,24 @@
|
||||
-- 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. An additional grant
|
||||
-- of patent rights can be found in the PATENTS file in the same directory.
|
||||
|
||||
|
||||
module Duckling.AmountOfMoney.AR.Tests
|
||||
( tests
|
||||
) where
|
||||
|
||||
import Data.String
|
||||
import Prelude
|
||||
import Test.Tasty
|
||||
|
||||
import Duckling.AmountOfMoney.AR.Corpus
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Testing.Asserts
|
||||
|
||||
tests :: TestTree
|
||||
tests = testGroup "AR Tests"
|
||||
[ makeCorpusTest [This AmountOfMoney] corpus
|
||||
]
|
@ -7,7 +7,8 @@
|
||||
|
||||
|
||||
module Duckling.AmountOfMoney.EN.Tests
|
||||
( tests ) where
|
||||
( tests
|
||||
) where
|
||||
|
||||
import Data.String
|
||||
import Prelude
|
||||
|
@ -12,6 +12,7 @@ import Data.String
|
||||
import Prelude
|
||||
import Test.Tasty
|
||||
|
||||
import qualified Duckling.AmountOfMoney.AR.Tests as AR
|
||||
import qualified Duckling.AmountOfMoney.EN.Tests as EN
|
||||
import qualified Duckling.AmountOfMoney.BG.Tests as BG
|
||||
import qualified Duckling.AmountOfMoney.ES.Tests as ES
|
||||
@ -29,7 +30,8 @@ import qualified Duckling.AmountOfMoney.VI.Tests as VI
|
||||
|
||||
tests :: TestTree
|
||||
tests = testGroup "AmountOfMoney Tests"
|
||||
[ EN.tests
|
||||
[ AR.tests
|
||||
, EN.tests
|
||||
, BG.tests
|
||||
, ES.tests
|
||||
, FR.tests
|
||||
|
Loading…
Reference in New Issue
Block a user