Skip to content

Commit

Permalink
Quantity/RO: Fix for values above 20
Browse files Browse the repository at this point in the history
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
  • Loading branch information
patapizza authored and facebook-github-bot committed Jun 8, 2018
1 parent bee838e commit 11316b3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
9 changes: 7 additions & 2 deletions Duckling/Quantity/RO/Corpus.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
]
]
27 changes: 15 additions & 12 deletions Duckling/Quantity/RO/Rules.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

Expand Down

0 comments on commit 11316b3

Please sign in to comment.