From f705206fb208612d80a1dd578ec628a32790a658 Mon Sep 17 00:00:00 2001 From: Julien Odent Date: Fri, 8 Jun 2018 09:38:05 -0700 Subject: [PATCH] Temperature/RO: Fix for values above 20 Summary: In Romanian, for numerals above 20, we say "20 de grade", not "20 grade". Here we optimize for recall and allow "20 de grade de celsius", "20 de grade celsius", "20 grade de celsius", "20 grade celsius". This would actually allow things like "4 de grade", though it's fine as it doesn't alter meaning. Differential Revision: D8332923 fbshipit-source-id: e6ae0ecc902ac5db9be504b5ff6a14b1ec996413 --- Duckling/Temperature/RO/Corpus.hs | 8 ++++++-- Duckling/Temperature/RO/Rules.hs | 20 +++++++++++--------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/Duckling/Temperature/RO/Corpus.hs b/Duckling/Temperature/RO/Corpus.hs index c2c9a2210..7208280fd 100644 --- a/Duckling/Temperature/RO/Corpus.hs +++ b/Duckling/Temperature/RO/Corpus.hs @@ -9,10 +9,11 @@ {-# LANGUAGE OverloadedStrings #-} module Duckling.Temperature.RO.Corpus - ( corpus ) where + ( corpus + ) where -import Prelude import Data.String +import Prelude import Duckling.Locale import Duckling.Resolve @@ -30,7 +31,9 @@ allExamples = concat , "37 grade Celsius" , "treizeci si sapte celsius" , "37 grade Celsius" + , "37 de grade de Celsius" , "treizeci si sapte celsius" + , "treizeci si sapte de celsius" ] , examples (simple Fahrenheit 70) [ "70°F" @@ -41,5 +44,6 @@ allExamples = concat , examples (simple Degree 45) [ "45°" , "45 grade" + , "45 de grade" ] ] diff --git a/Duckling/Temperature/RO/Rules.hs b/Duckling/Temperature/RO/Rules.hs index 800a9c7e2..850f36bc4 100644 --- a/Duckling/Temperature/RO/Rules.hs +++ b/Duckling/Temperature/RO/Rules.hs @@ -7,27 +7,29 @@ {-# LANGUAGE GADTs #-} +{-# LANGUAGE LambdaCase #-} {-# LANGUAGE OverloadedStrings #-} module Duckling.Temperature.RO.Rules - ( rules ) where + ( rules + ) where -import Prelude import Data.String +import Prelude import Duckling.Dimensions.Types import Duckling.Temperature.Helpers -import qualified Duckling.Temperature.Types as TTemperature import Duckling.Types +import qualified Duckling.Temperature.Types as TTemperature ruleLatentTempGrade :: Rule ruleLatentTempGrade = Rule { name = " grade" , pattern = [ Predicate $ isValueOnly False - , regex "(grade)|°" + , regex "(de )?(grade)|°" ] - , prod = \tokens -> case tokens of + , prod = \case (Token Temperature td:_) -> Just . Token Temperature $ withUnit TTemperature.Degree td _ -> Nothing @@ -38,9 +40,9 @@ ruleTempCelcius = Rule { name = " Celcius" , pattern = [ Predicate $ isValueOnly True - , regex "c(el[cs]?(ius)?)?\\.?" + , regex "(de )?c(el[cs]?(ius)?)?\\.?" ] - , prod = \tokens -> case tokens of + , prod = \case (Token Temperature td:_) -> Just . Token Temperature $ withUnit TTemperature.Celsius td _ -> Nothing @@ -51,9 +53,9 @@ ruleTempFahrenheit = Rule { name = " Fahrenheit" , pattern = [ Predicate $ isValueOnly True - , regex "f(ah?rh?eh?n(h?eit)?)?\\.?" + , regex "(de )?f(ah?rh?eh?n(h?eit)?)?\\.?" ] - , prod = \tokens -> case tokens of + , prod = \case (Token Temperature td:_) -> Just . Token Temperature $ withUnit TTemperature.Fahrenheit td _ -> Nothing