From 3d23372913a1c3a4751cd10e0c00a274a0f90ee3 Mon Sep 17 00:00:00 2001 From: Julien Odent Date: Fri, 8 Jun 2018 09:38:05 -0700 Subject: [PATCH] Volume/RO: Fix for values above 20 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 --- Duckling/Volume/RO/Corpus.hs | 8 +++++++- Duckling/Volume/RO/Rules.hs | 24 +++++++++++++----------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/Duckling/Volume/RO/Corpus.hs b/Duckling/Volume/RO/Corpus.hs index 3e136ddb6..2b0a4f374 100644 --- a/Duckling/Volume/RO/Corpus.hs +++ b/Duckling/Volume/RO/Corpus.hs @@ -9,7 +9,8 @@ {-# LANGUAGE OverloadedStrings #-} module Duckling.Volume.RO.Corpus - ( corpus ) where + ( corpus + ) where import Data.String import Prelude @@ -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" @@ -45,4 +48,7 @@ allExamples = concat [ "jumatate de litru" , "jumătate de litru" ] + , examples (VolumeValue Gallon 20) + [ "douazeci de galoane" + ] ] diff --git a/Duckling/Volume/RO/Rules.hs b/Duckling/Volume/RO/Rules.hs index 012814a8a..4b63aa3b5 100644 --- a/Duckling/Volume/RO/Rules.hs +++ b/Duckling/Volume/RO/Rules.hs @@ -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 @@ -25,9 +27,9 @@ ruleLatentVolMl = Rule { name = " 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 @@ -38,9 +40,9 @@ ruleVolHectoliters = Rule { name = " 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 @@ -51,9 +53,9 @@ ruleVolLiters = Rule { name = " 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 @@ -65,7 +67,7 @@ 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 @@ -73,9 +75,9 @@ ruleLatentVolGalon = Rule { name = " 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