mirror of
https://github.com/facebook/duckling.git
synced 2024-11-28 00:31:28 +03:00
AmountOfMoney/ES: Add support for intervals
Summary: This change applies roughly the same rules for supporting intervals in Spanish AmountOfMoney that we suppor in English: intervals using `entre _ e _` / `de _ a _` / `_ - _` with either money in both slots or a number in the first slot and money in the second. My Spanish is okay but not great - I'm confident these rules are good and cover the most likely phrases, but there's probably room to add more coverage. Reviewed By: patapizza Differential Revision: D20425979 fbshipit-source-id: deb17fc331e1aa192d91dd47bc7f3864a246f0be
This commit is contained in:
parent
2f38255cf8
commit
e3114c08f5
@ -64,4 +64,18 @@ allExamples = concat
|
||||
, "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"
|
||||
]
|
||||
]
|
||||
|
@ -127,6 +127,114 @@ ruleIntersect = Rule
|
||||
_ -> 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
|
||||
@ -137,4 +245,10 @@ rules =
|
||||
, ruleIntersectAndXCents
|
||||
, ruleIntersectXCents
|
||||
, rulePounds
|
||||
, ruleIntervalBetweenNumeral
|
||||
, ruleIntervalBetween
|
||||
, ruleIntervalNumeralDash
|
||||
, ruleIntervalDash
|
||||
, ruleIntervalMax
|
||||
, ruleIntervalMin
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user