mirror of
https://github.com/facebook/duckling.git
synced 2024-09-11 21:27:13 +03:00
Support legalese numerals
Summary: Support numerals like "forty-five (45)". Commonly seen in legal documents. There are no classifiers to regenerate. Resolves #216 Reviewed By: stroxler Differential Revision: D28305725 fbshipit-source-id: b9b4e160f630ce3cf462fcf9f2e575738463c313
This commit is contained in:
parent
0efbfe5988
commit
59cb9e0879
@ -184,4 +184,8 @@ allExamples = concat
|
||||
, "three hundred krores"
|
||||
, "three hundred Kr"
|
||||
]
|
||||
, examples (NumeralValue 45)
|
||||
[ "forty-five (45)"
|
||||
, "45 (forty five)"
|
||||
]
|
||||
]
|
||||
|
@ -6,8 +6,9 @@
|
||||
|
||||
|
||||
{-# LANGUAGE GADTs #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
{-# LANGUAGE LambdaCase #-}
|
||||
{-# LANGUAGE NoRebindableSyntax #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Duckling.Numeral.EN.Rules
|
||||
( rules
|
||||
@ -23,7 +24,7 @@ import qualified Data.Text as Text
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Numeral.Helpers
|
||||
import Duckling.Numeral.Types (NumeralData (..))
|
||||
import Duckling.Numeral.Types (NumeralData (..), isInteger)
|
||||
import Duckling.Regex.Types
|
||||
import Duckling.Types
|
||||
import qualified Duckling.Numeral.Types as TNumeral
|
||||
@ -333,6 +334,24 @@ ruleMultiply = Rule
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleLegalParentheses :: Rule
|
||||
ruleLegalParentheses = Rule
|
||||
{ name = "<integer> '('<integer>')'"
|
||||
, pattern =
|
||||
[ numberWith TNumeral.value $ and . sequence [isInteger, (>0)]
|
||||
, regex "\\("
|
||||
, numberWith TNumeral.value $ and . sequence [isInteger, (>0)]
|
||||
, regex "\\)"
|
||||
]
|
||||
, prod = \case
|
||||
(Token Numeral NumeralData{TNumeral.value = n1}:
|
||||
_:
|
||||
Token Numeral NumeralData{TNumeral.value = n2}:
|
||||
_:
|
||||
_) | n1 == n2 -> double n1
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
rules :: [Rule]
|
||||
rules =
|
||||
[ ruleToNineteen
|
||||
@ -351,4 +370,5 @@ rules =
|
||||
, ruleSumAnd
|
||||
, ruleMultiply
|
||||
, ruleDozen
|
||||
, ruleLegalParentheses
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user