mirror of
https://github.com/facebook/duckling.git
synced 2025-01-06 04:53:13 +03:00
Intervals for AmountOfMoney
Summary: * Supports "a" + currency (e.g. "a dollar") * Supports intervals (e.g. "10-20 dollars") * Supports open intervals (e.g. "above 3 dollars", "less than 3 dollars") * Follows `Time` format Reviewed By: blandinw Differential Revision: D5233766 fbshipit-source-id: 57cb6a8
This commit is contained in:
parent
8711df5047
commit
b943111b4f
@ -22,31 +22,36 @@ corpus = (testContext, allExamples)
|
||||
|
||||
allExamples :: [Example]
|
||||
allExamples = concat
|
||||
[ examples (AmountOfMoneyValue Dollar 10)
|
||||
[ examples (simple Dollar 1)
|
||||
[ "$1"
|
||||
, "one dollar"
|
||||
, "a dollar"
|
||||
]
|
||||
, examples (simple Dollar 10)
|
||||
[ "$10"
|
||||
, "$ 10"
|
||||
, "10$"
|
||||
, "10 dollars"
|
||||
, "ten dollars"
|
||||
]
|
||||
, examples (AmountOfMoneyValue Cent 10)
|
||||
, examples (simple Cent 10)
|
||||
[ "10 cent"
|
||||
, "ten pennies"
|
||||
, "ten cents"
|
||||
, "10 c"
|
||||
, "10¢"
|
||||
]
|
||||
, examples (AmountOfMoneyValue Dollar 1e4)
|
||||
, examples (simple Dollar 1e4)
|
||||
[ "$10K"
|
||||
, "10k$"
|
||||
, "$10,000"
|
||||
]
|
||||
, examples (AmountOfMoneyValue USD 3.14)
|
||||
, examples (simple USD 3.14)
|
||||
[ "USD3.14"
|
||||
, "3.14US$"
|
||||
, "US$ 3.14"
|
||||
]
|
||||
, examples (AmountOfMoneyValue EUR 20)
|
||||
, examples (simple EUR 20)
|
||||
[ "20\x20ac"
|
||||
, "20 euros"
|
||||
, "20 Euro"
|
||||
@ -56,22 +61,22 @@ allExamples = concat
|
||||
, "20€"
|
||||
, "20 €ur"
|
||||
]
|
||||
, examples (AmountOfMoneyValue Pound 10)
|
||||
, examples (simple Pound 10)
|
||||
[ "\x00a3\&10"
|
||||
, "ten pounds"
|
||||
]
|
||||
, examples (AmountOfMoneyValue INR 20)
|
||||
, examples (simple INR 20)
|
||||
[ "Rs. 20"
|
||||
, "Rs 20"
|
||||
, "20 Rupees"
|
||||
, "20Rs"
|
||||
, "Rs20"
|
||||
]
|
||||
, examples (AmountOfMoneyValue INR 20.43)
|
||||
, examples (simple INR 20.43)
|
||||
[ "20 Rupees 43"
|
||||
, "twenty rupees 43"
|
||||
]
|
||||
, examples (AmountOfMoneyValue Dollar 20.43)
|
||||
, examples (simple Dollar 20.43)
|
||||
[ "$20 and 43c"
|
||||
, "$20 43"
|
||||
, "20 dollar 43c"
|
||||
@ -80,37 +85,37 @@ allExamples = concat
|
||||
, "20 dollar 43"
|
||||
, "twenty dollar and 43"
|
||||
]
|
||||
, examples (AmountOfMoneyValue GBP 3.01)
|
||||
, examples (simple GBP 3.01)
|
||||
[ "GBP3.01"
|
||||
, "GBP 3.01"
|
||||
, "3 GBP 1 pence"
|
||||
]
|
||||
, examples (AmountOfMoneyValue Unnamed 42)
|
||||
, examples (simple Unnamed 42)
|
||||
[ "42 bucks"
|
||||
, "around 42 bucks"
|
||||
, "exactly 42 bucks"
|
||||
]
|
||||
, examples (AmountOfMoneyValue KWD 42)
|
||||
, examples (simple KWD 42)
|
||||
[ "42 KWD"
|
||||
, "42 kuwaiti Dinar"
|
||||
]
|
||||
, examples (AmountOfMoneyValue LBP 42)
|
||||
, examples (simple LBP 42)
|
||||
[ "42 LBP"
|
||||
, "42 Lebanese Pounds"
|
||||
]
|
||||
, examples (AmountOfMoneyValue EGP 42)
|
||||
, examples (simple EGP 42)
|
||||
[ "42 EGP"
|
||||
, "42 egyptianpound"
|
||||
]
|
||||
, examples (AmountOfMoneyValue QAR 42)
|
||||
, examples (simple QAR 42)
|
||||
[ "42 QAR"
|
||||
, "42 qatari riyals"
|
||||
]
|
||||
, examples (AmountOfMoneyValue SAR 42)
|
||||
, examples (simple SAR 42)
|
||||
[ "42 SAR"
|
||||
, "42 Saudiriyal"
|
||||
]
|
||||
, examples (AmountOfMoneyValue MYR 42)
|
||||
, examples (simple MYR 42)
|
||||
[ "42 MYR"
|
||||
, "42 RM"
|
||||
, "RM 42"
|
||||
@ -130,11 +135,31 @@ allExamples = concat
|
||||
, "42 malaysian ringgits"
|
||||
, "malaysian ringgits 42"
|
||||
]
|
||||
, examples (AmountOfMoneyValue MYR 20.43)
|
||||
, examples (simple MYR 20.43)
|
||||
[ "20 ringgit and 43c"
|
||||
, "20 ringgit and 43 sen"
|
||||
, "twenty ringgit 43 sens"
|
||||
, "20 ringgit 43"
|
||||
, "twenty ringgit and 43"
|
||||
]
|
||||
, examples (between Dollar (10, 20))
|
||||
[ "between 10 and 20 dollars"
|
||||
, "from 10 dollars to 20 dollars"
|
||||
, "around 10-20 dollars"
|
||||
, "between 10 dollars and 20 dollars"
|
||||
, "from 10 to 20 dollars"
|
||||
, "about $10-$20"
|
||||
, "10-20 dollars"
|
||||
]
|
||||
, examples (under EUR 7)
|
||||
[ "under seven euros"
|
||||
, "less than 7 EUR"
|
||||
, "lower than 7€"
|
||||
]
|
||||
, examples (above Dollar 1.42)
|
||||
[ "more than 1 dollar and forty-two cents"
|
||||
, "at least $1.42"
|
||||
, "over 1.42 dollars"
|
||||
, "above a dollar and 42 cents"
|
||||
]
|
||||
]
|
||||
|
@ -112,6 +112,18 @@ ruleBucks = Rule
|
||||
, prod = \_ -> Just . Token AmountOfMoney $ currencyOnly Unnamed
|
||||
}
|
||||
|
||||
ruleACurrency :: Rule
|
||||
ruleACurrency = Rule
|
||||
{ name = "a <currency>"
|
||||
, pattern =
|
||||
[ regex "an?"
|
||||
, financeWith TAmountOfMoney.value isNothing
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(_:Token AmountOfMoney fd:_) -> Just . Token AmountOfMoney $ fd {TAmountOfMoney.value = Just 1}
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleIntersectAndXCents :: Rule
|
||||
ruleIntersectAndXCents = Rule
|
||||
{ name = "intersect (and X cents)"
|
||||
@ -163,7 +175,9 @@ ruleIntersectXCents = Rule
|
||||
{ name = "intersect (X cents)"
|
||||
, pattern =
|
||||
[ financeWith TAmountOfMoney.value isJust
|
||||
, financeWith TAmountOfMoney.currency (== Cent)
|
||||
, 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:
|
||||
@ -177,16 +191,117 @@ rulePrecision = Rule
|
||||
{ name = "about|exactly <amount-of-money>"
|
||||
, pattern =
|
||||
[ regex "exactly|precisely|about|approx(\\.|imately)?|close to|near( to)?|around|almost"
|
||||
, financeWith TAmountOfMoney.value isJust
|
||||
, 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 "between|from"
|
||||
, dimension Numeral
|
||||
, regex "to|and"
|
||||
, 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 "between|from"
|
||||
, financeWith TAmountOfMoney.value isJust
|
||||
, regex "to|and"
|
||||
, 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 "under|(less|lower|not? more) than"
|
||||
, 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 = "over/above/at least/more than <amount-of-money>"
|
||||
, pattern =
|
||||
[ regex "over|above|at least|more than"
|
||||
, 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
|
||||
}
|
||||
|
||||
rules :: [Rule]
|
||||
rules =
|
||||
[ ruleBucks
|
||||
[ ruleACurrency
|
||||
, ruleBucks
|
||||
, ruleCent
|
||||
, ruleDinars
|
||||
, ruleDirham
|
||||
@ -194,6 +309,12 @@ rules =
|
||||
, ruleIntersectAndNumeral
|
||||
, ruleIntersectAndXCents
|
||||
, ruleIntersectXCents
|
||||
, ruleIntervalBetweenNumeral
|
||||
, ruleIntervalBetween
|
||||
, ruleIntervalMax
|
||||
, ruleIntervalMin
|
||||
, ruleIntervalNumeralDash
|
||||
, ruleIntervalDash
|
||||
, ruleOtherPounds
|
||||
, rulePounds
|
||||
, rulePrecision
|
||||
|
@ -24,42 +24,42 @@ corpus = (testContext {lang = ES}, allExamples)
|
||||
|
||||
allExamples :: [Example]
|
||||
allExamples = concat
|
||||
[ examples (AmountOfMoneyValue Dollar 10)
|
||||
[ examples (simple Dollar 10)
|
||||
[ "$10"
|
||||
, "10$"
|
||||
, "diez dollars"
|
||||
, "diez dólares"
|
||||
]
|
||||
, examples (AmountOfMoneyValue Dollar 10000)
|
||||
, examples (simple Dollar 10000)
|
||||
[ "$10.000"
|
||||
, "10K$"
|
||||
, "$10k"
|
||||
]
|
||||
, examples (AmountOfMoneyValue USD 1.23)
|
||||
, examples (simple USD 1.23)
|
||||
[ "USD1,23"
|
||||
]
|
||||
, examples (AmountOfMoneyValue EUR 20)
|
||||
, examples (simple EUR 20)
|
||||
[ "20€"
|
||||
, "20 euros"
|
||||
, "20 Euro"
|
||||
, "20 Euros"
|
||||
, "EUR 20"
|
||||
]
|
||||
, examples (AmountOfMoneyValue EUR 29.99)
|
||||
, examples (simple EUR 29.99)
|
||||
[ "EUR29,99"
|
||||
]
|
||||
, examples (AmountOfMoneyValue Pound 9)
|
||||
, examples (simple Pound 9)
|
||||
[ "£9"
|
||||
, "nueve pounds"
|
||||
, "9 libras"
|
||||
]
|
||||
, examples (AmountOfMoneyValue GBP 3.01)
|
||||
, examples (simple GBP 3.01)
|
||||
[ "GBP3,01"
|
||||
, "GBP 3,01"
|
||||
, "3 gbp 1 centavo"
|
||||
, "3 gbp y 1 centavo"
|
||||
]
|
||||
, examples (AmountOfMoneyValue PTS 15)
|
||||
, examples (simple PTS 15)
|
||||
[ "15 Pt"
|
||||
, "15pta"
|
||||
, "15Ptas"
|
||||
|
@ -24,41 +24,41 @@ corpus = (testContext {lang = FR}, allExamples)
|
||||
|
||||
allExamples :: [Example]
|
||||
allExamples = concat
|
||||
[ examples (AmountOfMoneyValue Dollar 10)
|
||||
[ examples (simple Dollar 10)
|
||||
[ "$10"
|
||||
, "10$"
|
||||
, "dix dollars"
|
||||
]
|
||||
, examples (AmountOfMoneyValue Dollar 10000)
|
||||
, examples (simple Dollar 10000)
|
||||
[ "$10.000"
|
||||
, "10K$"
|
||||
, "$10k"
|
||||
]
|
||||
, examples (AmountOfMoneyValue USD 1.23)
|
||||
, examples (simple USD 1.23)
|
||||
[ "USD1,23"
|
||||
, "1 USD et 23 centimes"
|
||||
, "1 USD 23 cents"
|
||||
]
|
||||
, examples (AmountOfMoneyValue EUR 20)
|
||||
, examples (simple EUR 20)
|
||||
[ "20€"
|
||||
, "20 euros"
|
||||
, "20 Euro"
|
||||
, "20 Euros"
|
||||
, "EUR 20"
|
||||
]
|
||||
, examples (AmountOfMoneyValue EUR 29.99)
|
||||
, examples (simple EUR 29.99)
|
||||
[ "EUR29,99"
|
||||
]
|
||||
, examples (AmountOfMoneyValue Unnamed 3)
|
||||
, examples (simple Unnamed 3)
|
||||
[ "3 balles"
|
||||
, "à peu près 3 pouloutes"
|
||||
]
|
||||
, examples (AmountOfMoneyValue Pound 9)
|
||||
, examples (simple Pound 9)
|
||||
[ "exactement £9"
|
||||
, "neuf pounds"
|
||||
, "quasi neuf livres"
|
||||
]
|
||||
, examples (AmountOfMoneyValue GBP 3.01)
|
||||
, examples (simple GBP 3.01)
|
||||
[ "GBP3,01"
|
||||
, "GBP 3,01"
|
||||
]
|
||||
|
@ -24,62 +24,62 @@ corpus = (testContext {lang = GA}, allExamples)
|
||||
|
||||
allExamples :: [Example]
|
||||
allExamples = concat
|
||||
[ examples (AmountOfMoneyValue Dollar 10)
|
||||
[ examples (simple Dollar 10)
|
||||
[ "$10"
|
||||
, "10$"
|
||||
, "deich dollair"
|
||||
]
|
||||
, examples (AmountOfMoneyValue Cent 10)
|
||||
, examples (simple Cent 10)
|
||||
[ "deich ceinteanna"
|
||||
]
|
||||
, examples (AmountOfMoneyValue Dollar 10000)
|
||||
, examples (simple Dollar 10000)
|
||||
[ "$10,000"
|
||||
, "10K$"
|
||||
, "$10k"
|
||||
]
|
||||
, examples (AmountOfMoneyValue EUR 10000)
|
||||
, examples (simple EUR 10000)
|
||||
[ "€10,000"
|
||||
, "10K€"
|
||||
, "€10k"
|
||||
]
|
||||
, examples (AmountOfMoneyValue USD 1.23)
|
||||
, examples (simple USD 1.23)
|
||||
[ "USD1.23"
|
||||
]
|
||||
, examples (AmountOfMoneyValue Dollar 2.23)
|
||||
, examples (simple Dollar 2.23)
|
||||
[ "2 dhollair agus 23 ceinteanna"
|
||||
, "dhá dhollair 23 ceinteanna"
|
||||
, "2 dhollair 23"
|
||||
, "dhá dhollair agus 23"
|
||||
]
|
||||
, examples (AmountOfMoneyValue EUR 20)
|
||||
, examples (simple EUR 20)
|
||||
[ "20€"
|
||||
, "20 euros"
|
||||
, "20 Euro"
|
||||
, "20 Euros"
|
||||
, "EUR 20"
|
||||
]
|
||||
, examples (AmountOfMoneyValue EUR 29.99)
|
||||
, examples (simple EUR 29.99)
|
||||
[ "EUR29.99"
|
||||
]
|
||||
, examples (AmountOfMoneyValue INR 20)
|
||||
, examples (simple INR 20)
|
||||
[ "Rs. 20"
|
||||
, "Rs 20"
|
||||
, "20 Rúpaí"
|
||||
, "20Rs"
|
||||
, "Rs20"
|
||||
]
|
||||
, examples (AmountOfMoneyValue INR 20.43)
|
||||
, examples (simple INR 20.43)
|
||||
[ "20 Rupees 43"
|
||||
, "fiche rúpaí 43"
|
||||
]
|
||||
, examples (AmountOfMoneyValue INR 33)
|
||||
, examples (simple INR 33)
|
||||
[ "INR33"
|
||||
]
|
||||
, examples (AmountOfMoneyValue Pound 9)
|
||||
, examples (simple Pound 9)
|
||||
[ "£9"
|
||||
, "naoi bpunt"
|
||||
]
|
||||
, examples (AmountOfMoneyValue GBP 3.01)
|
||||
, examples (simple GBP 3.01)
|
||||
[ "GBP3.01"
|
||||
, "GBP 3.01"
|
||||
]
|
||||
|
@ -23,73 +23,73 @@ corpus = (testContext {lang = HR}, allExamples)
|
||||
|
||||
allExamples :: [Example]
|
||||
allExamples = concat
|
||||
[ examples (AmountOfMoneyValue Dollar 10)
|
||||
[ examples (simple Dollar 10)
|
||||
[ "$10"
|
||||
, "10$"
|
||||
, "deset dolara"
|
||||
]
|
||||
, examples (AmountOfMoneyValue Cent 10)
|
||||
, examples (simple Cent 10)
|
||||
[ "deset centa"
|
||||
]
|
||||
, examples (AmountOfMoneyValue Dollar 10000)
|
||||
, examples (simple Dollar 10000)
|
||||
[ "$10.000"
|
||||
, "10K$"
|
||||
, "$10k"
|
||||
]
|
||||
, examples (AmountOfMoneyValue USD 1.23)
|
||||
, examples (simple USD 1.23)
|
||||
[ "USD1,23"
|
||||
]
|
||||
, examples (AmountOfMoneyValue Dollar 2.23)
|
||||
, examples (simple Dollar 2.23)
|
||||
[ "2 dolara i 23 centa"
|
||||
, "dva dolara 23 centa"
|
||||
, "2 dolara 23"
|
||||
, "dva dolara i 23"
|
||||
]
|
||||
, examples (AmountOfMoneyValue HRK 2.23)
|
||||
, examples (simple HRK 2.23)
|
||||
[ "2 kune i 23 lipe"
|
||||
, "dvije kune 23 lipe"
|
||||
, "2 kune 23"
|
||||
, "dvije kune i 23"
|
||||
]
|
||||
, examples (AmountOfMoneyValue HRK 100)
|
||||
, examples (simple HRK 100)
|
||||
[ "100 kuna"
|
||||
, "sto kuna"
|
||||
]
|
||||
, examples (AmountOfMoneyValue HRK 200)
|
||||
, examples (simple HRK 200)
|
||||
[ "200 kuna"
|
||||
, "dvije stotine kuna"
|
||||
, "dvjesto kuna"
|
||||
, "dvjesta kuna"
|
||||
]
|
||||
, examples (AmountOfMoneyValue EUR 20)
|
||||
, examples (simple EUR 20)
|
||||
[ "20€"
|
||||
, "20 euros"
|
||||
, "20 Euro"
|
||||
, "20 Euros"
|
||||
, "EUR 20"
|
||||
]
|
||||
, examples (AmountOfMoneyValue EUR 29.99)
|
||||
, examples (simple EUR 29.99)
|
||||
[ "EUR29,99"
|
||||
]
|
||||
, examples (AmountOfMoneyValue INR 20)
|
||||
, examples (simple INR 20)
|
||||
[ "Rs. 20"
|
||||
, "Rs 20"
|
||||
, "20 Rupija"
|
||||
, "20Rs"
|
||||
, "Rs20"
|
||||
]
|
||||
, examples (AmountOfMoneyValue INR 20.43)
|
||||
, examples (simple INR 20.43)
|
||||
[ "20 Rupija 43"
|
||||
, "dvadeset rupija 43"
|
||||
]
|
||||
, examples (AmountOfMoneyValue INR 33)
|
||||
, examples (simple INR 33)
|
||||
[ "INR33"
|
||||
]
|
||||
, examples (AmountOfMoneyValue Pound 9)
|
||||
, examples (simple Pound 9)
|
||||
[ "£9"
|
||||
, "devet funti"
|
||||
]
|
||||
, examples (AmountOfMoneyValue GBP 3.01)
|
||||
, examples (simple GBP 3.01)
|
||||
[ "GBP3,01"
|
||||
, "GBP 3,01"
|
||||
]
|
||||
|
@ -13,14 +13,17 @@ module Duckling.AmountOfMoney.Helpers
|
||||
( currencyOnly
|
||||
, financeWith
|
||||
, withCents
|
||||
, withInterval
|
||||
, withMax
|
||||
, withMin
|
||||
, withValue
|
||||
)
|
||||
where
|
||||
|
||||
import Prelude
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.AmountOfMoney.Types (Currency (..), AmountOfMoneyData (..))
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Types hiding (Entity(..))
|
||||
|
||||
-- -----------------------------------------------------------------
|
||||
@ -36,7 +39,8 @@ financeWith f pred = Predicate $ \x ->
|
||||
-- Production
|
||||
|
||||
currencyOnly :: Currency -> AmountOfMoneyData
|
||||
currencyOnly c = AmountOfMoneyData {currency = c, value = Nothing}
|
||||
currencyOnly c = AmountOfMoneyData
|
||||
{currency = c, value = Nothing, minValue = Nothing, maxValue = Nothing}
|
||||
|
||||
withValue :: Double -> AmountOfMoneyData -> AmountOfMoneyData
|
||||
withValue x fd = fd {value = Just x}
|
||||
@ -45,4 +49,13 @@ withCents :: Double -> AmountOfMoneyData -> AmountOfMoneyData
|
||||
withCents x fd@AmountOfMoneyData {value = Just value} = fd
|
||||
{value = Just $ value + x / 100}
|
||||
withCents x AmountOfMoneyData {value = Nothing} = AmountOfMoneyData
|
||||
{value = Just x, currency = Cent}
|
||||
{value = Just x, currency = Cent, minValue = Nothing, maxValue = Nothing}
|
||||
|
||||
withInterval :: (Double, Double) -> AmountOfMoneyData -> AmountOfMoneyData
|
||||
withInterval (from, to) fd = fd {minValue = Just from, maxValue = Just to}
|
||||
|
||||
withMin :: Double -> AmountOfMoneyData -> AmountOfMoneyData
|
||||
withMin x fd = fd {minValue = Just x}
|
||||
|
||||
withMax :: Double -> AmountOfMoneyData -> AmountOfMoneyData
|
||||
withMax x fd = fd {maxValue = Just x}
|
||||
|
@ -24,24 +24,24 @@ corpus = (testContext {lang = ID}, allExamples)
|
||||
|
||||
allExamples :: [Example]
|
||||
allExamples = concat
|
||||
[ examples (AmountOfMoneyValue Dollar 10)
|
||||
[ examples (simple Dollar 10)
|
||||
[ "$10"
|
||||
, "10$"
|
||||
, "sepuluh dolar"
|
||||
]
|
||||
, examples (AmountOfMoneyValue Dollar 10000)
|
||||
, examples (simple Dollar 10000)
|
||||
[ "$10.000"
|
||||
, "10K$"
|
||||
, "$10k"
|
||||
]
|
||||
, examples (AmountOfMoneyValue USD 1.23)
|
||||
, examples (simple USD 1.23)
|
||||
[ "USD1,23"
|
||||
]
|
||||
, examples (AmountOfMoneyValue Dollar 2)
|
||||
, examples (simple Dollar 2)
|
||||
[ "2 dola"
|
||||
, "dua dolar"
|
||||
]
|
||||
, examples (AmountOfMoneyValue EUR 20)
|
||||
, examples (simple EUR 20)
|
||||
[ "20€"
|
||||
, "20 euros"
|
||||
, "20 Euro"
|
||||
@ -49,32 +49,32 @@ allExamples = concat
|
||||
, "EUR 20"
|
||||
, "dua puluh Euro"
|
||||
]
|
||||
, examples (AmountOfMoneyValue EUR 29.99)
|
||||
, examples (simple EUR 29.99)
|
||||
[ "EUR29,99"
|
||||
]
|
||||
, examples (AmountOfMoneyValue IDR 315)
|
||||
, examples (simple IDR 315)
|
||||
[ "Rp. 315,00"
|
||||
]
|
||||
, examples (AmountOfMoneyValue IDR 20)
|
||||
, examples (simple IDR 20)
|
||||
[ "Rp 20"
|
||||
, "20 Rupiah"
|
||||
, "20Rp"
|
||||
, "Rp20"
|
||||
]
|
||||
, examples (AmountOfMoneyValue IDR 33000)
|
||||
, examples (simple IDR 33000)
|
||||
[ "IDR33000"
|
||||
, "IDR 33.000"
|
||||
]
|
||||
, examples (AmountOfMoneyValue Pound 9)
|
||||
, examples (simple Pound 9)
|
||||
[ "£9"
|
||||
, "sembilan pound"
|
||||
, "sembilan pound sterling"
|
||||
]
|
||||
, examples (AmountOfMoneyValue GBP 3.01)
|
||||
, examples (simple GBP 3.01)
|
||||
[ "GBP3,01"
|
||||
, "GBP 3,01"
|
||||
]
|
||||
, examples (AmountOfMoneyValue JPY 10)
|
||||
, examples (simple JPY 10)
|
||||
[ "10 yen"
|
||||
, "10¥"
|
||||
, "10 ¥."
|
||||
|
@ -24,53 +24,53 @@ corpus = (testContext {lang = KO}, allExamples)
|
||||
|
||||
allExamples :: [Example]
|
||||
allExamples = concat
|
||||
[ examples (AmountOfMoneyValue Dollar 10)
|
||||
[ examples (simple Dollar 10)
|
||||
[ "십달러"
|
||||
, "십불"
|
||||
]
|
||||
, examples (AmountOfMoneyValue Cent 10)
|
||||
, examples (simple Cent 10)
|
||||
[ "십센트"
|
||||
]
|
||||
, examples (AmountOfMoneyValue Dollar 10000)
|
||||
, examples (simple Dollar 10000)
|
||||
[ "만달러"
|
||||
, "만불"
|
||||
]
|
||||
, examples (AmountOfMoneyValue Dollar 1.23)
|
||||
, examples (simple Dollar 1.23)
|
||||
[ "일점이삼달러"
|
||||
, "일쩜이삼달러"
|
||||
, "일점이삼불"
|
||||
, "일쩜이삼불"
|
||||
]
|
||||
, examples (AmountOfMoneyValue Dollar 2.23)
|
||||
, examples (simple Dollar 2.23)
|
||||
[ "이달러이십삼센트"
|
||||
, "이불이십삼센트"
|
||||
]
|
||||
, examples (AmountOfMoneyValue EUR 20)
|
||||
, examples (simple EUR 20)
|
||||
[ "이십유로"
|
||||
, "EUR 20"
|
||||
]
|
||||
, examples (AmountOfMoneyValue EUR 29.99)
|
||||
, examples (simple EUR 29.99)
|
||||
[ "이십구점구구유로"
|
||||
, "EUR29.99"
|
||||
]
|
||||
, examples (AmountOfMoneyValue Pound 9)
|
||||
, examples (simple Pound 9)
|
||||
[ "구파운드"
|
||||
]
|
||||
, examples (AmountOfMoneyValue KRW 27350000)
|
||||
, examples (simple KRW 27350000)
|
||||
[ "이천칠백삼십오만원"
|
||||
, "27,350,000원"
|
||||
, "27350000원"
|
||||
]
|
||||
, examples (AmountOfMoneyValue KRW 27000)
|
||||
, examples (simple KRW 27000)
|
||||
[ "이만칠천원"
|
||||
, "27,000원"
|
||||
, "27000원"
|
||||
]
|
||||
, examples (AmountOfMoneyValue KRW 100)
|
||||
, examples (simple KRW 100)
|
||||
[ "백원"
|
||||
, "100원"
|
||||
]
|
||||
, examples (AmountOfMoneyValue KRW 10)
|
||||
, examples (simple KRW 10)
|
||||
[ "십원"
|
||||
, "10원"
|
||||
, "10₩"
|
||||
|
@ -24,45 +24,45 @@ corpus = (testContext {lang = NB}, allExamples)
|
||||
|
||||
allExamples :: [Example]
|
||||
allExamples = concat
|
||||
[ examples (AmountOfMoneyValue Dollar 10)
|
||||
[ examples (simple Dollar 10)
|
||||
[ "$10"
|
||||
, "10$"
|
||||
, "ti dollar"
|
||||
]
|
||||
, examples (AmountOfMoneyValue Cent 10)
|
||||
, examples (simple Cent 10)
|
||||
[ "ti øre"
|
||||
]
|
||||
, examples (AmountOfMoneyValue Dollar 10000)
|
||||
, examples (simple Dollar 10000)
|
||||
[ "$10.000"
|
||||
, "10K$"
|
||||
, "$10k"
|
||||
]
|
||||
, examples (AmountOfMoneyValue USD 1.23)
|
||||
, examples (simple USD 1.23)
|
||||
[ "USD1,23"
|
||||
]
|
||||
, examples (AmountOfMoneyValue NOK 10)
|
||||
, examples (simple NOK 10)
|
||||
[ "10kroner"
|
||||
, "10kr"
|
||||
, "ti kroner"
|
||||
, "10 NOK"
|
||||
]
|
||||
, examples (AmountOfMoneyValue NOK 2.23)
|
||||
, examples (simple NOK 2.23)
|
||||
[ "2 kroner og 23 øre"
|
||||
, "to kroner 23 øre"
|
||||
, "to kroner og 23 øre"
|
||||
, "to kr 23"
|
||||
]
|
||||
, examples (AmountOfMoneyValue EUR 20)
|
||||
, examples (simple EUR 20)
|
||||
[ "20€"
|
||||
, "20 euro"
|
||||
, "20 Euro"
|
||||
, "20 Euros"
|
||||
, "EUR 20"
|
||||
]
|
||||
, examples (AmountOfMoneyValue EUR 29.99)
|
||||
, examples (simple EUR 29.99)
|
||||
[ "EUR29,99"
|
||||
]
|
||||
, examples (AmountOfMoneyValue INR 20)
|
||||
, examples (simple INR 20)
|
||||
[ "Rs. 20"
|
||||
, "Rs 20"
|
||||
, "20 Rupees"
|
||||
@ -70,16 +70,16 @@ allExamples = concat
|
||||
, "Rs20"
|
||||
, "INR20"
|
||||
]
|
||||
, examples (AmountOfMoneyValue INR 20.43)
|
||||
, examples (simple INR 20.43)
|
||||
[ "20 Rupees 43"
|
||||
, "tjue rupees 43"
|
||||
, "tjue rupees 43¢"
|
||||
]
|
||||
, examples (AmountOfMoneyValue Pound 9)
|
||||
, examples (simple Pound 9)
|
||||
[ "£9"
|
||||
, "ni pund"
|
||||
]
|
||||
, examples (AmountOfMoneyValue GBP 3.01)
|
||||
, examples (simple GBP 3.01)
|
||||
[ "GBP3,01"
|
||||
, "GBP 3,01"
|
||||
]
|
||||
|
@ -24,49 +24,49 @@ corpus = (testContext {lang = PT}, allExamples)
|
||||
|
||||
allExamples :: [Example]
|
||||
allExamples = concat
|
||||
[ examples (AmountOfMoneyValue Dollar 10)
|
||||
[ examples (simple Dollar 10)
|
||||
[ "$10"
|
||||
, "10$"
|
||||
, "dez dolares"
|
||||
]
|
||||
, examples (AmountOfMoneyValue Dollar 10000)
|
||||
, examples (simple Dollar 10000)
|
||||
[ "$10.000"
|
||||
, "10K$"
|
||||
, "$10k"
|
||||
]
|
||||
, examples (AmountOfMoneyValue USD 1.23)
|
||||
, examples (simple USD 1.23)
|
||||
[ "USD1,23"
|
||||
]
|
||||
, examples (AmountOfMoneyValue EUR 20)
|
||||
, examples (simple EUR 20)
|
||||
[ "20€"
|
||||
, "20 euros"
|
||||
, "20 Euro"
|
||||
, "20 Euros"
|
||||
, "EUR 20"
|
||||
]
|
||||
, examples (AmountOfMoneyValue EUR 29.99)
|
||||
, examples (simple EUR 29.99)
|
||||
[ "EUR29,99"
|
||||
]
|
||||
, examples (AmountOfMoneyValue Pound 9)
|
||||
, examples (simple Pound 9)
|
||||
[ "£9"
|
||||
, "nove libras"
|
||||
]
|
||||
, examples (AmountOfMoneyValue GBP 3.01)
|
||||
, examples (simple GBP 3.01)
|
||||
[ "GBP3,01"
|
||||
, "GBP 3,01"
|
||||
]
|
||||
, examples (AmountOfMoneyValue PTS 15)
|
||||
, examples (simple PTS 15)
|
||||
[ "15 Pt"
|
||||
, "15pta"
|
||||
, "15Ptas"
|
||||
]
|
||||
, examples (AmountOfMoneyValue BRL 15)
|
||||
, examples (simple BRL 15)
|
||||
[ "15 reais"
|
||||
, "15reais"
|
||||
, "15 Reais"
|
||||
, "BRL 15"
|
||||
]
|
||||
, examples (AmountOfMoneyValue BRL 2.0)
|
||||
, examples (simple BRL 2.0)
|
||||
[ "R$2,00"
|
||||
, "R$ 2,00"
|
||||
, "2,00 reais"
|
||||
|
@ -24,49 +24,49 @@ corpus = (testContext {lang = RO}, allExamples)
|
||||
|
||||
allExamples :: [Example]
|
||||
allExamples = concat
|
||||
[ examples (AmountOfMoneyValue RON 10)
|
||||
[ examples (simple RON 10)
|
||||
[ "10 lei"
|
||||
, "10 roni"
|
||||
, "10 RON"
|
||||
]
|
||||
, examples (AmountOfMoneyValue Cent 50)
|
||||
, examples (simple Cent 50)
|
||||
[ "50 bani"
|
||||
, "50 BANI"
|
||||
]
|
||||
, examples (AmountOfMoneyValue RON 10.5)
|
||||
, examples (simple RON 10.5)
|
||||
[ "10,5 lei"
|
||||
, "10,5 ron"
|
||||
, "10 lei si 50 bani"
|
||||
]
|
||||
, examples (AmountOfMoneyValue Dollar 10)
|
||||
, examples (simple Dollar 10)
|
||||
[ "$10"
|
||||
, "10$"
|
||||
, "zece dolari"
|
||||
, "10 dolari"
|
||||
]
|
||||
, examples (AmountOfMoneyValue Cent 10)
|
||||
, examples (simple Cent 10)
|
||||
[ "zece centi"
|
||||
, "zece cenți"
|
||||
]
|
||||
, examples (AmountOfMoneyValue Dollar 10000)
|
||||
, examples (simple Dollar 10000)
|
||||
[ "$10.000"
|
||||
, "$10000"
|
||||
]
|
||||
, examples (AmountOfMoneyValue USD 1.23)
|
||||
, examples (simple USD 1.23)
|
||||
[ "USD1,23"
|
||||
]
|
||||
, examples (AmountOfMoneyValue Dollar 1)
|
||||
, examples (simple Dollar 1)
|
||||
[ "1 dolar"
|
||||
, "un dolar"
|
||||
, "$1"
|
||||
]
|
||||
, examples (AmountOfMoneyValue Cent 2)
|
||||
, examples (simple Cent 2)
|
||||
[ "2 centi"
|
||||
]
|
||||
, examples (AmountOfMoneyValue Cent 23)
|
||||
, examples (simple Cent 23)
|
||||
[ "23 centi"
|
||||
]
|
||||
, examples (AmountOfMoneyValue Dollar 2.23)
|
||||
, examples (simple Dollar 2.23)
|
||||
[ "2 dolari si 23 centi"
|
||||
, "2 dolari și 23 cenți"
|
||||
, "doi dolari si douăzeci si trei centi"
|
||||
@ -75,45 +75,45 @@ allExamples = concat
|
||||
, "doi dolari si 23"
|
||||
, "doi dolari și 23"
|
||||
]
|
||||
, examples (AmountOfMoneyValue EUR 20)
|
||||
, examples (simple EUR 20)
|
||||
[ "20€"
|
||||
, "20 euro"
|
||||
, "20 Euro"
|
||||
, "EUR 20"
|
||||
]
|
||||
, examples (AmountOfMoneyValue EUR 29.99)
|
||||
, examples (simple EUR 29.99)
|
||||
[ "EUR29,99"
|
||||
]
|
||||
, examples (AmountOfMoneyValue Pound 9)
|
||||
, examples (simple Pound 9)
|
||||
[ "£9"
|
||||
, "noua lir"
|
||||
, "nouă lire"
|
||||
]
|
||||
, examples (AmountOfMoneyValue GBP 3.01)
|
||||
, examples (simple GBP 3.01)
|
||||
[ "GBP3,01"
|
||||
, "GBP 3,01"
|
||||
]
|
||||
, examples (AmountOfMoneyValue QAR 1)
|
||||
, examples (simple QAR 1)
|
||||
[ "un rial qatarian"
|
||||
, "1 rial qataria"
|
||||
]
|
||||
, examples (AmountOfMoneyValue EGP 10)
|
||||
, examples (simple EGP 10)
|
||||
[ "zece lira egiptiana"
|
||||
]
|
||||
, examples (AmountOfMoneyValue LBP 1)
|
||||
, examples (simple LBP 1)
|
||||
[ "una liră libaneză"
|
||||
]
|
||||
, examples (AmountOfMoneyValue INR 42)
|
||||
, examples (simple INR 42)
|
||||
[ "42 rupii"
|
||||
, "Rs. 42"
|
||||
]
|
||||
, examples (AmountOfMoneyValue KWD 1)
|
||||
, examples (simple KWD 1)
|
||||
[ "un dinar kuweitian"
|
||||
]
|
||||
, examples (AmountOfMoneyValue AED 2)
|
||||
, examples (simple AED 2)
|
||||
[ "2 dirhami"
|
||||
]
|
||||
, examples (AmountOfMoneyValue SAR 1)
|
||||
, examples (simple SAR 1)
|
||||
[ "1 rial saudit"
|
||||
, "un rial saudi"
|
||||
]
|
||||
|
@ -24,67 +24,67 @@ corpus = (testContext {lang = SV}, allExamples)
|
||||
|
||||
allExamples :: [Example]
|
||||
allExamples = concat
|
||||
[ examples (AmountOfMoneyValue Dollar 10)
|
||||
[ examples (simple Dollar 10)
|
||||
[ "$10"
|
||||
, "10$"
|
||||
, "tio dollar"
|
||||
]
|
||||
, examples (AmountOfMoneyValue Cent 10)
|
||||
, examples (simple Cent 10)
|
||||
[ "tio öre"
|
||||
]
|
||||
, examples (AmountOfMoneyValue Dollar 10000)
|
||||
, examples (simple Dollar 10000)
|
||||
[ "$10.000"
|
||||
, "10K$"
|
||||
, "$10k"
|
||||
]
|
||||
, examples (AmountOfMoneyValue USD 1.23)
|
||||
, examples (simple USD 1.23)
|
||||
[ "USD1,23"
|
||||
]
|
||||
, examples (AmountOfMoneyValue SEK 10)
|
||||
, examples (simple SEK 10)
|
||||
[ "10kronor"
|
||||
, "10kr"
|
||||
, "10 kr"
|
||||
, "tio kronor"
|
||||
, "10 SEK"
|
||||
]
|
||||
, examples (AmountOfMoneyValue SEK 2.23)
|
||||
, examples (simple SEK 2.23)
|
||||
[ "2 kronor och 23 öre"
|
||||
, "två kronor 23 öre"
|
||||
, "två kronor och 23 öre"
|
||||
]
|
||||
, examples (AmountOfMoneyValue EUR 20)
|
||||
, examples (simple EUR 20)
|
||||
[ "20€"
|
||||
, "20 euro"
|
||||
, "20 Euro"
|
||||
, "20 Euros"
|
||||
, "EUR 20"
|
||||
]
|
||||
, examples (AmountOfMoneyValue EUR 29.99)
|
||||
, examples (simple EUR 29.99)
|
||||
[ "EUR29,99"
|
||||
]
|
||||
, examples (AmountOfMoneyValue INR 20)
|
||||
, examples (simple INR 20)
|
||||
[ "Rs. 20"
|
||||
, "Rs 20"
|
||||
, "20 Rupees"
|
||||
, "20Rs"
|
||||
, "Rs20"
|
||||
]
|
||||
, examples (AmountOfMoneyValue INR 20.43)
|
||||
, examples (simple INR 20.43)
|
||||
[ "20 Rupees 43"
|
||||
, "tjugo rupees 43"
|
||||
]
|
||||
, examples (AmountOfMoneyValue INR 33)
|
||||
, examples (simple INR 33)
|
||||
[ "INR33"
|
||||
]
|
||||
, examples (AmountOfMoneyValue Pound 9)
|
||||
, examples (simple Pound 9)
|
||||
[ "£9"
|
||||
, "nio pund"
|
||||
]
|
||||
, examples (AmountOfMoneyValue GBP 3.01)
|
||||
, examples (simple GBP 3.01)
|
||||
[ "GBP3,01"
|
||||
, "GBP 3,01"
|
||||
]
|
||||
, examples (AmountOfMoneyValue NOK 10)
|
||||
, examples (simple NOK 10)
|
||||
[ "10 norska kronor"
|
||||
, "10 nkr"
|
||||
]
|
||||
|
@ -21,6 +21,7 @@ import Data.Hashable
|
||||
import Data.Text (Text)
|
||||
import GHC.Generics
|
||||
import Prelude
|
||||
import qualified Data.HashMap.Strict as H
|
||||
|
||||
import Duckling.Resolve (Resolve(..))
|
||||
|
||||
@ -88,24 +89,79 @@ instance ToJSON Currency where
|
||||
data AmountOfMoneyData = AmountOfMoneyData
|
||||
{ value :: Maybe Double
|
||||
, currency :: Currency
|
||||
, minValue :: Maybe Double
|
||||
, maxValue :: Maybe Double
|
||||
}
|
||||
deriving (Eq, Generic, Hashable, Show, Ord, NFData)
|
||||
|
||||
data AmountOfMoneyValue = AmountOfMoneyValue
|
||||
instance Resolve AmountOfMoneyData where
|
||||
type ResolvedValue AmountOfMoneyData = AmountOfMoneyValue
|
||||
resolve _ AmountOfMoneyData {value = Nothing, minValue = Nothing, maxValue = Nothing} = Nothing
|
||||
resolve _ AmountOfMoneyData {value = Just value, currency} =
|
||||
Just $ simple currency value
|
||||
resolve _ AmountOfMoneyData {value = Nothing, currency = c, minValue = Just from, maxValue = Just to} =
|
||||
Just $ between c (from, to)
|
||||
resolve _ AmountOfMoneyData {value = Nothing, currency = c, minValue = Just v, maxValue = Nothing} =
|
||||
Just $ above c v
|
||||
resolve _ AmountOfMoneyData {value = Nothing, currency = c, minValue = Nothing, maxValue = Just v} =
|
||||
Just $ under c v
|
||||
|
||||
data IntervalDirection = Above | Under
|
||||
deriving (Eq, Generic, Hashable, Ord, Show, NFData)
|
||||
|
||||
data SingleValue = SingleValue
|
||||
{ vCurrency :: Currency
|
||||
, vValue :: Double
|
||||
}
|
||||
deriving (Eq, Show)
|
||||
|
||||
instance Resolve AmountOfMoneyData where
|
||||
type ResolvedValue AmountOfMoneyData = AmountOfMoneyValue
|
||||
resolve _ AmountOfMoneyData {value = Nothing} = Nothing
|
||||
resolve _ AmountOfMoneyData {value = Just value, currency} =
|
||||
Just AmountOfMoneyValue {vValue = value, vCurrency = currency}
|
||||
|
||||
instance ToJSON AmountOfMoneyValue where
|
||||
toJSON AmountOfMoneyValue {vCurrency, vValue} = object
|
||||
[ "type" .= ("value" :: Text)
|
||||
, "value" .= vValue
|
||||
instance ToJSON SingleValue where
|
||||
toJSON SingleValue {vCurrency, vValue} = object
|
||||
[ "value" .= vValue
|
||||
, "unit" .= vCurrency
|
||||
]
|
||||
|
||||
data AmountOfMoneyValue
|
||||
= SimpleValue SingleValue
|
||||
| IntervalValue (SingleValue, SingleValue)
|
||||
| OpenIntervalValue (SingleValue, IntervalDirection)
|
||||
deriving (Show, Eq)
|
||||
|
||||
instance ToJSON AmountOfMoneyValue where
|
||||
toJSON (SimpleValue value) = case toJSON value of
|
||||
Object o -> Object $ H.insert "type" (toJSON ("value" :: Text)) o
|
||||
_ -> Object H.empty
|
||||
toJSON (IntervalValue (from, to)) = object
|
||||
[ "type" .= ("interval" :: Text)
|
||||
, "from" .= toJSON from
|
||||
, "to" .= toJSON to
|
||||
]
|
||||
toJSON (OpenIntervalValue (from, Above)) = object
|
||||
[ "type" .= ("interval" :: Text)
|
||||
, "from" .= toJSON from
|
||||
]
|
||||
toJSON (OpenIntervalValue (to, Under)) = object
|
||||
[ "type" .= ("interval" :: Text)
|
||||
, "to" .= toJSON to
|
||||
]
|
||||
|
||||
-- -----------------------------------------------------------------
|
||||
-- Value helpers
|
||||
|
||||
simple :: Currency -> Double -> AmountOfMoneyValue
|
||||
simple c v = SimpleValue $ single c v
|
||||
|
||||
between :: Currency -> (Double, Double) -> AmountOfMoneyValue
|
||||
between c (from, to) = IntervalValue (single c from, single c to)
|
||||
|
||||
above :: Currency -> Double -> AmountOfMoneyValue
|
||||
above = openInterval Above
|
||||
|
||||
under :: Currency -> Double -> AmountOfMoneyValue
|
||||
under = openInterval Under
|
||||
|
||||
openInterval :: IntervalDirection -> Currency -> Double -> AmountOfMoneyValue
|
||||
openInterval direction c v = OpenIntervalValue (single c v, direction)
|
||||
|
||||
single :: Currency -> Double -> SingleValue
|
||||
single c v = SingleValue {vCurrency = c, vValue = v}
|
||||
|
@ -24,26 +24,26 @@ corpus = (testContext {lang = VI}, allExamples)
|
||||
|
||||
allExamples :: [Example]
|
||||
allExamples = concat
|
||||
[ examples (AmountOfMoneyValue Dollar 10)
|
||||
[ examples (simple Dollar 10)
|
||||
[ "$10"
|
||||
, "10$"
|
||||
, "mười đô"
|
||||
, "mười đô la"
|
||||
, "mười đô mỹ"
|
||||
]
|
||||
, examples (AmountOfMoneyValue Cent 10)
|
||||
, examples (simple Cent 10)
|
||||
[ "mười xen"
|
||||
, "mười xu"
|
||||
]
|
||||
, examples (AmountOfMoneyValue Dollar 10000)
|
||||
, examples (simple Dollar 10000)
|
||||
[ "$10,000"
|
||||
, "10K$"
|
||||
, "$10k"
|
||||
]
|
||||
, examples (AmountOfMoneyValue USD 1.23)
|
||||
, examples (simple USD 1.23)
|
||||
[ "USD1.23"
|
||||
]
|
||||
, examples (AmountOfMoneyValue Dollar 2.23)
|
||||
, examples (simple Dollar 2.23)
|
||||
[ "2 đô la và 23 xen"
|
||||
, "hai đô la và 23 xen"
|
||||
, "2 đô 23 xu"
|
||||
@ -51,52 +51,52 @@ allExamples = concat
|
||||
, "2 chấm 23 đô la"
|
||||
, "hai phẩy 23 đô"
|
||||
]
|
||||
, examples (AmountOfMoneyValue VND 10)
|
||||
, examples (simple VND 10)
|
||||
[ "mười đồng"
|
||||
]
|
||||
, examples (AmountOfMoneyValue VND 10000)
|
||||
, examples (simple VND 10000)
|
||||
[ "10,000 đồng"
|
||||
, "10K đồng"
|
||||
, "10k đồng"
|
||||
]
|
||||
, examples (AmountOfMoneyValue VND 1000)
|
||||
, examples (simple VND 1000)
|
||||
[ "1000 VNĐ"
|
||||
, "VN$1000"
|
||||
]
|
||||
, examples (AmountOfMoneyValue EUR 20)
|
||||
, examples (simple EUR 20)
|
||||
[ "20€"
|
||||
, "20 euros"
|
||||
, "20 Euro"
|
||||
, "20 Euros"
|
||||
, "EUR 20"
|
||||
]
|
||||
, examples (AmountOfMoneyValue EUR 29.99)
|
||||
, examples (simple EUR 29.99)
|
||||
[ "EUR29.99"
|
||||
]
|
||||
, examples (AmountOfMoneyValue INR 20)
|
||||
, examples (simple INR 20)
|
||||
[ "Rs. 20"
|
||||
, "Rs 20"
|
||||
, "20 Rupees"
|
||||
, "20Rs"
|
||||
, "Rs20"
|
||||
]
|
||||
, examples (AmountOfMoneyValue INR 20.43)
|
||||
, examples (simple INR 20.43)
|
||||
[ "20 Rupees 43"
|
||||
, "hai mươi rupees 43"
|
||||
, "hai mươi rupees 43 xen"
|
||||
]
|
||||
, examples (AmountOfMoneyValue INR 33)
|
||||
, examples (simple INR 33)
|
||||
[ "INR33"
|
||||
]
|
||||
, examples (AmountOfMoneyValue Pound 9)
|
||||
, examples (simple Pound 9)
|
||||
[ "£9"
|
||||
, "chín pounds"
|
||||
]
|
||||
, examples (AmountOfMoneyValue GBP 3.01)
|
||||
, examples (simple GBP 3.01)
|
||||
[ "GBP3.01"
|
||||
, "GBP 3.01"
|
||||
]
|
||||
, examples (AmountOfMoneyValue AED 1)
|
||||
, examples (simple AED 1)
|
||||
[ "1 AED."
|
||||
, "1 dirham"
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user