Support intervals

Summary: Support intervals for Duckling AmountOfMoney KO

Reviewed By: haoxuany

Differential Revision: D13020692

fbshipit-source-id: 79e1d99acf317467c1b06b156f47a497c91062da
This commit is contained in:
Hyo Jin Kim 2018-11-14 14:11:11 -08:00 committed by Facebook Github Bot
parent 1052914cb4
commit 5de0b1fbb6
2 changed files with 140 additions and 3 deletions

View File

@ -76,4 +76,38 @@ allExamples = concat
, "10원"
, "10₩"
]
, examples (between KRW (25000, 30000))
[ "25000 - 30000원"
, "25000원 - 30000원"
, "이만오천원 - 삼만원"
]
, examples (above KRW 5000)
[ "5000원 이상"
, "5000원 초과"
, "오천원 이상"
, "오천원 초과"
]
, examples (under KRW 10000)
[ "10000원 이하"
, "10000원 미만"
, "만원 이하"
, "만원 미만"
]
, examples (between Dollar (10, 20))
[ "10 - 20 달러"
, "10달러 - 20달러"
, "십달러 - 이십달러"
]
, examples (above Dollar 10)
[ "10달러 이상"
, "10달러 초과"
, "십달러 이상"
, "십달러 초과"
]
, examples (under Dollar 10)
[ "10달러 이하"
, "10달러 미만"
, "십달러 이하"
, "십달러 미만"
]
]

View File

@ -21,7 +21,7 @@ import Prelude
import Duckling.Dimensions.Types
import Duckling.AmountOfMoney.Helpers
import Duckling.AmountOfMoney.Types (Currency(..), AmountOfMoneyData (..))
import Duckling.Numeral.Helpers (isPositive)
import Duckling.Numeral.Helpers (isNatural, isPositive)
import Duckling.Numeral.Types (NumeralData (..))
import Duckling.Types
import qualified Duckling.AmountOfMoney.Types as TAmountOfMoney
@ -87,7 +87,7 @@ ruleCent :: Rule
ruleCent = Rule
{ name = "cent"
, pattern =
[ regex "cents?|(|츠)"
[ regex "센트"
]
, prod = \_ -> Just . Token AmountOfMoney $ currencyOnly Cent
}
@ -158,11 +158,108 @@ ruleDirham :: Rule
ruleDirham = Rule
{ name = "dirham"
, pattern =
[ regex "dirhams?"
[ regex "디르함"
]
, prod = \_ -> Just . Token AmountOfMoney $ currencyOnly AED
}
ruleIntervalBetweenNumeral :: Rule
ruleIntervalBetweenNumeral = Rule
{ name = "between|from <numeral> to|and <amount-of-money>"
, pattern =
[ Predicate isPositive
, regex "에서"
, Predicate isSimpleAmountOfMoney
]
, prod = \case
(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 =
[ 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}:
_) | 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}:
_) ->
(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}:
_) | 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 =
[ Predicate isSimpleAmountOfMoney
, regex "미만|이하"
]
, 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 =
[ Predicate isSimpleAmountOfMoney
, regex "초과|이상"
]
, prod = \case
(Token AmountOfMoney AmountOfMoneyData {TAmountOfMoney.value = Just to, TAmountOfMoney.currency = c}:
_:
_) -> (Just (Token AmountOfMoney $ withMin to $ currencyOnly c))
_ -> Nothing
}
rules :: [Rule]
rules =
[ ruleUnitAmount
@ -178,4 +275,10 @@ rules =
, ruleIntersectXCents
, ruleKrw
, rulePounds
, ruleIntervalBetweenNumeral
, ruleIntervalBetween
, ruleIntervalNumeralDash
, ruleIntervalDash
, ruleIntervalMax
, ruleIntervalMin
]