Skip to content

Commit

Permalink
Volume/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 litri", not "20 litri".
This would actually allow things like "4 de litri", though it's fine as it
doesn't alter meaning.

Differential Revision: D8332996

fbshipit-source-id: 709a97cec3c09513281be19e1a9b20895874b9c4
  • Loading branch information
patapizza authored and facebook-github-bot committed Jun 8, 2018
1 parent f705206 commit 3d23372
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
8 changes: 7 additions & 1 deletion Duckling/Volume/RO/Corpus.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
{-# LANGUAGE OverloadedStrings #-}

module Duckling.Volume.RO.Corpus
( corpus ) where
( corpus
) where

import Data.String
import Prelude
Expand All @@ -26,8 +27,10 @@ allExamples :: [Example]
allExamples = concat
[ examples (VolumeValue Millilitre 250)
[ "250 mililitri"
, "250 de mililitri"
, "250ml"
, "250 ml"
, "250 de ml"
]
, examples (VolumeValue Litre 2)
[ "2 litri"
Expand All @@ -45,4 +48,7 @@ allExamples = concat
[ "jumatate de litru"
, "jumătate de litru"
]
, examples (VolumeValue Gallon 20)
[ "douazeci de galoane"
]
]
24 changes: 13 additions & 11 deletions Duckling/Volume/RO/Rules.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@


{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}

module Duckling.Volume.RO.Rules
( rules ) where
( rules
) where

import Prelude
import Data.String
import Prelude

import Duckling.Dimensions.Types
import Duckling.Types
Expand All @@ -25,9 +27,9 @@ ruleLatentVolMl = Rule
{ name = "<latent vol> ml"
, pattern =
[ dimension Volume
, regex "m(ililitr[ui]|l)"
, regex "(de )?m(ililitr[ui]|l)"
]
, prod = \tokens -> case tokens of
, prod = \case
(Token Volume vd:_) ->
Just . Token Volume $ withUnit TVolume.Millilitre vd
_ -> Nothing
Expand All @@ -38,9 +40,9 @@ ruleVolHectoliters = Rule
{ name = "<vol> hectoliters"
, pattern =
[ dimension Volume
, regex "hectolitr[ui]"
, regex "(de )?hectolitr[ui]"
]
, prod = \tokens -> case tokens of
, prod = \case
(Token Volume vd:_) ->
Just . Token Volume $ withUnit TVolume.Hectolitre vd
_ -> Nothing
Expand All @@ -51,9 +53,9 @@ ruleVolLiters = Rule
{ name = "<vol> liters"
, pattern =
[ dimension Volume
, regex "l(itr[ui])?"
, regex "(de )?l(itr[ui])?"
]
, prod = \tokens -> case tokens of
, prod = \case
(Token Volume vd:_) ->
Just . Token Volume $ withUnit TVolume.Litre vd
_ -> Nothing
Expand All @@ -65,17 +67,17 @@ ruleHalfLiter = Rule
, pattern =
[ regex "jum(a|ă)tate de litr[ui]"
]
, prod = \_ -> Just . Token Volume . withUnit TVolume.Litre $ volume 0.5
, prod = const . Just . Token Volume . withUnit TVolume.Litre $ volume 0.5
}

ruleLatentVolGalon :: Rule
ruleLatentVolGalon = Rule
{ name = "<latent vol> galon"
, pattern =
[ dimension Volume
, regex "gal(oane|on)?"
, regex "(de )?gal(oane|on)?"
]
, prod = \tokens -> case tokens of
, prod = \case
(Token Volume vd:_) ->
Just . Token Volume $ withUnit TVolume.Gallon vd
_ -> Nothing
Expand Down

0 comments on commit 3d23372

Please sign in to comment.