Quantity/RO: Fix for values above 20

Summary:
In Romanian, for numerals above 20, we say "20 de livre", not "20 livre".
This would actually allow things like "4 de livre", though it's fine as it doesn't alter meaning.

Differential Revision: D8332867

fbshipit-source-id: 78ff193b027e547aa32a8f531d2f7ad895c6b668
This commit is contained in:
Julien Odent 2018-06-08 09:38:05 -07:00 committed by Facebook Github Bot
parent bee838e1c5
commit 11316b34af
2 changed files with 22 additions and 14 deletions

View File

@ -9,10 +9,11 @@
{-# LANGUAGE OverloadedStrings #-}
module Duckling.Quantity.RO.Corpus
( corpus ) where
( corpus
) where
import Prelude
import Data.String
import Prelude
import Duckling.Locale
import Duckling.Quantity.Types
@ -32,5 +33,9 @@ allExamples = concat
]
, examples (simple Pound 500 (Just "zahăr"))
[ "cinci sute livre de zahăr"
, "cinci sute de livre de zahăr"
]
, examples (simple Pound 21 (Just "mamaliga"))
[ "douăzeci și unu de livre de mamaliga"
]
]

View File

@ -7,30 +7,33 @@
{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
module Duckling.Quantity.RO.Rules
( rules ) where
( rules
) where
import Prelude
import Data.String
import Prelude
import Duckling.Dimensions.Types
import Duckling.Numeral.Types (NumeralData (..))
import qualified Duckling.Numeral.Types as TNumeral
import Duckling.Numeral.Helpers (isPositive)
import Duckling.Numeral.Types (NumeralData(..))
import Duckling.Quantity.Helpers
import qualified Duckling.Quantity.Types as TQuantity
import Duckling.Regex.Types
import Duckling.Types
import qualified Duckling.Numeral.Types as TNumeral
import qualified Duckling.Quantity.Types as TQuantity
ruleNumeralUnits :: Rule
ruleNumeralUnits = Rule
{ name = "<number> <units>"
, pattern =
[ dimension Numeral
, regex "livr(a|e|ă)"
[ Predicate isPositive
, regex "(de )?livr(a|e|ă)"
]
, prod = \tokens -> case tokens of
, prod = \case
(Token Numeral NumeralData {TNumeral.value = v}:_) ->
Just . Token Quantity $ quantity TQuantity.Pound v
_ -> Nothing
@ -41,12 +44,12 @@ ruleQuantityOfProduct = Rule
{ name = "<quantity> of product"
, pattern =
[ dimension Quantity
, regex "de (carne|can(a|ă)|zah(a|ă)r)"
, regex "de (carne|can[aă]|zah[aă]r|mamaliga)"
]
, prod = \tokens -> case tokens of
, prod = \case
(Token Quantity qd:
Token RegexMatch (GroupMatch (match:_)):
_) -> Just . Token Quantity $ withProduct match qd
Token RegexMatch (GroupMatch (product:_)):
_) -> Just . Token Quantity $ withProduct product qd
_ -> Nothing
}