mirror of
https://github.com/facebook/duckling.git
synced 2025-01-06 04:53:13 +03:00
fix intersect rule to work with negative numbers
Summary: Numerals that require intersection with negative numbers don't work, since the negative sign gets parsed before the intersect rules happen. This fixes it by adding a guard in for positive in the intersection rule. Reviewed By: patapizza Differential Revision: D7592225 fbshipit-source-id: 2bc9c708cadeea4012c1f3ef487c61a144325f2a
This commit is contained in:
parent
17e1845e12
commit
babe317723
@ -310,7 +310,7 @@ ruleNumeralDotNumeral = Rule
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, regex "فاصل[ةه]"
|
||||
, numberWith TNumeral.grain isNothing
|
||||
, Predicate $ not . hasGrain
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral NumeralData{TNumeral.value = v1}:
|
||||
|
@ -164,7 +164,7 @@ ruleDotSpelledOut = Rule
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, regex "цяло и"
|
||||
, numberWith TNumeral.grain isNothing
|
||||
, Predicate $ not . hasGrain
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral nd1:_:Token Numeral nd2:_) ->
|
||||
|
@ -110,7 +110,7 @@ ruleIntersect :: Rule
|
||||
ruleIntersect = Rule
|
||||
{ name = "intersect"
|
||||
, pattern =
|
||||
[ numberWith (fromMaybe 0 . TNumeral.grain) (>1)
|
||||
[ Predicate hasGrain
|
||||
, Predicate $ and . sequence [not . isMultipliable, isPositive]
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
@ -269,7 +269,7 @@ ruleNumeralDotNumeral = Rule
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, regex "komma"
|
||||
, numberWith TNumeral.grain isNothing
|
||||
, Predicate $ not . hasGrain
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral NumeralData{TNumeral.value = v1}:
|
||||
|
@ -151,7 +151,7 @@ ruleIntersect :: Rule
|
||||
ruleIntersect = Rule
|
||||
{ name = "intersect"
|
||||
, pattern =
|
||||
[ numberWith (fromMaybe 0 . TNumeral.grain) (>1)
|
||||
[ Predicate hasGrain
|
||||
, Predicate $ and . sequence [not . isMultipliable, isPositive]
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
@ -294,7 +294,7 @@ ruleNumeralDotNumeral = Rule
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, regex "komma"
|
||||
, numberWith TNumeral.grain isNothing
|
||||
, Predicate $ not . hasGrain
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral NumeralData{TNumeral.value = v1}:
|
||||
|
@ -190,7 +190,7 @@ ruleSum :: Rule
|
||||
ruleSum = Rule
|
||||
{ name = "intersect 2 numbers"
|
||||
, pattern =
|
||||
[ numberWith (fromMaybe 0 . TNumeral.grain) (>1)
|
||||
[ Predicate hasGrain
|
||||
, Predicate $ and . sequence [not . isMultipliable, isPositive]
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
@ -230,7 +230,7 @@ ruleCommaSpelledOut = Rule
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, regex "κόμμα"
|
||||
, numberWith TNumeral.grain isNothing
|
||||
, Predicate $ not . hasGrain
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral nd1:_:Token Numeral nd2:_) ->
|
||||
|
@ -127,6 +127,10 @@ allExamples = concat
|
||||
[ "5 thousand"
|
||||
, "five thousand"
|
||||
]
|
||||
, examples (NumeralValue (-504))
|
||||
[ "-504"
|
||||
, "negative five hundred and four"
|
||||
]
|
||||
, examples (NumeralValue (-1.2e6))
|
||||
[ "- 1,200,000"
|
||||
, "-1200000"
|
||||
|
@ -205,7 +205,7 @@ ruleDotSpelledOut = Rule
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, regex "point|dot"
|
||||
, numberWith TNumeral.grain isNothing
|
||||
, Predicate $ not . hasGrain
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral nd1:_:Token Numeral nd2:_) ->
|
||||
@ -218,7 +218,7 @@ ruleLeadingDotSpelledOut = Rule
|
||||
{ name = "point 77"
|
||||
, pattern =
|
||||
[ regex "point|dot"
|
||||
, numberWith TNumeral.grain isNothing
|
||||
, Predicate $ not . hasGrain
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(_:Token Numeral nd:_) -> double . decimalsToDouble $ TNumeral.value nd
|
||||
@ -282,7 +282,7 @@ ruleSum :: Rule
|
||||
ruleSum = Rule
|
||||
{ name = "intersect 2 numbers"
|
||||
, pattern =
|
||||
[ numberWith (fromMaybe 0 . TNumeral.grain) (>1)
|
||||
[ Predicate $ and . sequence [hasGrain, isPositive]
|
||||
, Predicate $ and . sequence [not . isMultipliable, isPositive]
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
@ -296,7 +296,7 @@ ruleSumAnd :: Rule
|
||||
ruleSumAnd = Rule
|
||||
{ name = "intersect 2 numbers (with and)"
|
||||
, pattern =
|
||||
[ numberWith (fromMaybe 0 . TNumeral.grain) (>1)
|
||||
[ Predicate $ and . sequence [hasGrain, isPositive]
|
||||
, regex "and"
|
||||
, Predicate $ and . sequence [not . isMultipliable, isPositive]
|
||||
]
|
||||
|
@ -260,7 +260,7 @@ ruleNumeralDotNumeral = Rule
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, regex "punto"
|
||||
, numberWith TNumeral.grain isNothing
|
||||
, Predicate $ not . hasGrain
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral NumeralData{TNumeral.value = v1}:
|
||||
|
@ -121,7 +121,7 @@ ruleIntersect :: Rule
|
||||
ruleIntersect = Rule
|
||||
{ name = "intersect"
|
||||
, pattern =
|
||||
[ numberWith (fromMaybe 0 . TNumeral.grain) (>1)
|
||||
[ Predicate hasGrain
|
||||
, Predicate $ and . sequence [not . isMultipliable, isPositive]
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
@ -247,7 +247,7 @@ ruleNumeralDotNumeral = Rule
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, regex "dot|point"
|
||||
, numberWith TNumeral.grain isNothing
|
||||
, Predicate $ not . hasGrain
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral NumeralData{TNumeral.value = v1}:
|
||||
|
@ -270,7 +270,7 @@ ruleSum :: Rule
|
||||
ruleSum = Rule
|
||||
{ name = "intersect 2 numbers"
|
||||
, pattern =
|
||||
[ numberWith (fromMaybe 0 . TNumeral.grain) (>1)
|
||||
[ Predicate hasGrain
|
||||
, Predicate $ and . sequence [not . isMultipliable, isPositive]
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
|
@ -38,7 +38,7 @@ ruleIntersectNumerals :: Rule
|
||||
ruleIntersectNumerals = Rule
|
||||
{ name = "intersect numbers"
|
||||
, pattern =
|
||||
[ numberWith (fromMaybe 0 . TNumeral.grain) (>1)
|
||||
[ Predicate hasGrain
|
||||
, Predicate $ and . sequence [not . isMultipliable, isPositive]
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
@ -52,7 +52,7 @@ ruleIntersectWithAnd :: Rule
|
||||
ruleIntersectWithAnd = Rule
|
||||
{ name = "intersect (with and)"
|
||||
, pattern =
|
||||
[ numberWith (fromMaybe 0 . TNumeral.grain) (>1)
|
||||
[ Predicate hasGrain
|
||||
, regex "ו"
|
||||
, Predicate isMultipliable
|
||||
]
|
||||
@ -324,7 +324,7 @@ ruleNumeralDotNumeral = Rule
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, regex "נקודה"
|
||||
, numberWith TNumeral.grain isNothing
|
||||
, Predicate $ not . hasGrain
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral nd1:_:Token Numeral nd2:_) ->
|
||||
|
@ -158,7 +158,7 @@ ruleSum :: Rule
|
||||
ruleSum = Rule
|
||||
{ name = "intersect"
|
||||
, pattern =
|
||||
[ numberWith (fromMaybe 0 . TNumeral.grain) (>1)
|
||||
[ Predicate hasGrain
|
||||
, Predicate $ and . sequence [not . isMultipliable, isPositive]
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
@ -309,7 +309,7 @@ ruleNumberDotNumber = Rule
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, regex "cijela|to(c|č)ka|zarez"
|
||||
, numberWith TNumeral.grain isNothing
|
||||
, Predicate $ not . hasGrain
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral NumeralData{TNumeral.value = v1}:
|
||||
|
@ -18,6 +18,7 @@ module Duckling.Numeral.Helpers
|
||||
, isMultipliable
|
||||
, isNatural
|
||||
, isPositive
|
||||
, hasGrain
|
||||
, divide
|
||||
, notOkForAnyTime
|
||||
, numberBetween
|
||||
@ -121,6 +122,10 @@ isMultipliable :: Predicate
|
||||
isMultipliable (Token Numeral nd) = multipliable nd
|
||||
isMultipliable _ = False
|
||||
|
||||
hasGrain :: Predicate
|
||||
hasGrain (Token Numeral NumeralData {grain = Just g}) = g > 1
|
||||
hasGrain _ = False
|
||||
|
||||
oneOf :: [Double] -> PatternItem
|
||||
oneOf vs = Predicate $ \x ->
|
||||
case x of
|
||||
|
@ -62,7 +62,7 @@ ruleNumeralCommaNumeral = Rule
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, regex "koma"
|
||||
, numberWith TNumeral.grain isNothing
|
||||
, Predicate $ not . hasGrain
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral nd1:_:Token Numeral nd2:_) ->
|
||||
@ -146,7 +146,7 @@ ruleIntersect :: Rule
|
||||
ruleIntersect = Rule
|
||||
{ name = "intersect"
|
||||
, pattern =
|
||||
[ numberWith (fromMaybe 0 . TNumeral.grain) (>1)
|
||||
[ Predicate hasGrain
|
||||
, Predicate $ and . sequence [not . isMultipliable, isPositive]
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
|
@ -206,7 +206,7 @@ ruleSum :: Rule
|
||||
ruleSum = Rule
|
||||
{ name = "intersect 2 numbers"
|
||||
, pattern =
|
||||
[ numberWith (fromMaybe 0 . TNumeral.grain) (>1)
|
||||
[ Predicate hasGrain
|
||||
, Predicate $ and . sequence [not . isMultipliable, isPositive]
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
|
@ -32,7 +32,7 @@ ruleIntersectWithAnd :: Rule
|
||||
ruleIntersectWithAnd = Rule
|
||||
{ name = "intersect (with and)"
|
||||
, pattern =
|
||||
[ numberWith (fromMaybe 0 . TNumeral.grain) (>1)
|
||||
[ Predicate hasGrain
|
||||
, regex "og"
|
||||
, Predicate $ and . sequence [not . isMultipliable, isPositive]
|
||||
]
|
||||
@ -129,7 +129,7 @@ ruleIntersect :: Rule
|
||||
ruleIntersect = Rule
|
||||
{ name = "intersect"
|
||||
, pattern =
|
||||
[ numberWith (fromMaybe 0 . TNumeral.grain) (>1)
|
||||
[ Predicate hasGrain
|
||||
, Predicate $ and . sequence [not . isMultipliable, isPositive]
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
@ -268,7 +268,7 @@ ruleNumeralDotNumeral = Rule
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, regex "komma"
|
||||
, numberWith TNumeral.grain isNothing
|
||||
, Predicate $ not . hasGrain
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral nd1:_:Token Numeral nd2:_) ->
|
||||
|
@ -115,7 +115,7 @@ ruleIntersect :: Rule
|
||||
ruleIntersect = Rule
|
||||
{ name = "intersect"
|
||||
, pattern =
|
||||
[ numberWith (fromMaybe 0 . TNumeral.grain) (>1)
|
||||
[ Predicate hasGrain
|
||||
, Predicate $ and . sequence [not . isMultipliable, isPositive]
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
|
@ -65,7 +65,7 @@ ruleIntersectWithAnd :: Rule
|
||||
ruleIntersectWithAnd = Rule
|
||||
{ name = "intersect (with and)"
|
||||
, pattern =
|
||||
[ numberWith (fromMaybe 0 . TNumeral.grain) (>1)
|
||||
[ Predicate hasGrain
|
||||
, regex "i|a"
|
||||
, Predicate $ and . sequence [not . isMultipliable, isPositive]
|
||||
]
|
||||
@ -328,7 +328,7 @@ ruleIntersect :: Rule
|
||||
ruleIntersect = Rule
|
||||
{ name = "intersect"
|
||||
, pattern =
|
||||
[ numberWith (fromMaybe 0 . TNumeral.grain) (>1)
|
||||
[ Predicate hasGrain
|
||||
, Predicate $ and . sequence [not . isMultipliable, isPositive]
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
@ -514,7 +514,7 @@ ruleNumeralDotNumeral = Rule
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, regex "dot|point"
|
||||
, numberWith TNumeral.grain isNothing
|
||||
, Predicate $ not . hasGrain
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral nd1:_:Token Numeral nd2:_) ->
|
||||
|
@ -249,7 +249,7 @@ ruleDotSpelledOut = Rule
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, regex "ponto"
|
||||
, numberWith TNumeral.grain isNothing
|
||||
, Predicate $ not . hasGrain
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral nd1:_:Token Numeral nd2:_) ->
|
||||
@ -262,7 +262,7 @@ ruleLeadingDotSpelledOut = Rule
|
||||
{ name = "point 77"
|
||||
, pattern =
|
||||
[ regex "ponto"
|
||||
, numberWith TNumeral.grain isNothing
|
||||
, Predicate $ not . hasGrain
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(_:Token Numeral nd:_) -> double . decimalsToDouble $ TNumeral.value nd
|
||||
@ -326,7 +326,7 @@ ruleSum :: Rule
|
||||
ruleSum = Rule
|
||||
{ name = "intersect 2 numbers"
|
||||
, pattern =
|
||||
[ numberWith (fromMaybe 0 . TNumeral.grain) (>1)
|
||||
[ Predicate hasGrain
|
||||
, Predicate $ and . sequence [not . isMultipliable, isPositive]
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
@ -340,7 +340,7 @@ ruleSumAnd :: Rule
|
||||
ruleSumAnd = Rule
|
||||
{ name = "intersect 2 numbers (with and)"
|
||||
, pattern =
|
||||
[ numberWith (fromMaybe 0 . TNumeral.grain) (>1)
|
||||
[ Predicate hasGrain
|
||||
, regex "e"
|
||||
, Predicate $ and . sequence [not . isMultipliable, isPositive]
|
||||
]
|
||||
|
@ -109,7 +109,7 @@ ruleIntersect :: Rule
|
||||
ruleIntersect = Rule
|
||||
{ name = "intersect"
|
||||
, pattern =
|
||||
[ numberWith (fromMaybe 0 . TNumeral.grain) (>1)
|
||||
[ Predicate hasGrain
|
||||
, Predicate $ and . sequence [not . isMultipliable, isPositive]
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
@ -123,7 +123,7 @@ ruleIntersectCuI :: Rule
|
||||
ruleIntersectCuI = Rule
|
||||
{ name = "intersect (cu și)"
|
||||
, pattern =
|
||||
[ numberWith (fromMaybe 0 . TNumeral.grain) (>1)
|
||||
[ Predicate hasGrain
|
||||
, regex "(s|ș)i"
|
||||
, Predicate $ and . sequence [not . isMultipliable, isPositive]
|
||||
]
|
||||
|
@ -248,7 +248,7 @@ ruleNumeralDotNumeral = Rule
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, regex "точка"
|
||||
, numberWith TNumeral.grain isNothing
|
||||
, Predicate $ not . hasGrain
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral nd1:_:Token Numeral nd2:_) ->
|
||||
|
@ -32,7 +32,7 @@ ruleIntersectWithAnd :: Rule
|
||||
ruleIntersectWithAnd = Rule
|
||||
{ name = "intersect (with and)"
|
||||
, pattern =
|
||||
[ numberWith (fromMaybe 0 . TNumeral.grain) (>1)
|
||||
[ Predicate hasGrain
|
||||
, regex "och"
|
||||
, Predicate $ and . sequence [not . isMultipliable, isPositive]
|
||||
]
|
||||
@ -119,7 +119,7 @@ ruleIntersect :: Rule
|
||||
ruleIntersect = Rule
|
||||
{ name = "intersect"
|
||||
, pattern =
|
||||
[ numberWith (fromMaybe 0 . TNumeral.grain) (>1)
|
||||
[ Predicate hasGrain
|
||||
, Predicate $ and . sequence [not . isMultipliable, isPositive]
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
@ -264,7 +264,7 @@ ruleNumeralDotNumeral = Rule
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, regex "komma"
|
||||
, numberWith TNumeral.grain isNothing
|
||||
, Predicate $ not . hasGrain
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral nd1:_:Token Numeral nd2:_) ->
|
||||
|
@ -305,7 +305,7 @@ ruleIntersect :: Rule
|
||||
ruleIntersect = Rule
|
||||
{ name = "intersect"
|
||||
, pattern =
|
||||
[ numberWith (fromMaybe 0 . TNumeral.grain) (>1)
|
||||
[ Predicate hasGrain
|
||||
, Predicate $ and . sequence [not . isMultipliable, isPositive]
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
@ -666,7 +666,7 @@ ruleNumeralDotNumeral = Rule
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, regex "nokta|virgül"
|
||||
, numberWith TNumeral.grain isNothing
|
||||
, Predicate $ not . hasGrain
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral NumeralData{TNumeral.value = v1}:
|
||||
|
@ -225,7 +225,7 @@ ruleNumeralDotNumeral = Rule
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, regex "крапка"
|
||||
, numberWith TNumeral.grain isNothing
|
||||
, Predicate $ not . hasGrain
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral nd1:_:Token Numeral nd2:_) ->
|
||||
|
@ -118,7 +118,7 @@ ruleNumeralDot = Rule
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, regex "chấm|phẩy"
|
||||
, numberWith TNumeral.grain isNothing
|
||||
, Predicate $ not . hasGrain
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral nd1:_:Token Numeral nd2:_) ->
|
||||
@ -130,7 +130,7 @@ ruleIntersect :: Rule
|
||||
ruleIntersect = Rule
|
||||
{ name = "intersect"
|
||||
, pattern =
|
||||
[ numberWith (fromMaybe 0 . TNumeral.grain) (>1)
|
||||
[ Predicate hasGrain
|
||||
, Predicate $ and . sequence [not . isMultipliable, isPositive]
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
|
Loading…
Reference in New Issue
Block a user