From fd267ee80b7fe55dfa8e02f100f511a82d2ee114 Mon Sep 17 00:00:00 2001 From: RIAN DOUGLAS Date: Thu, 12 Apr 2018 13:58:34 -0700 Subject: [PATCH] Time/EN: Make "may" latent Summary: Extended method for making months from a pair, to take a 3-tuple, including a flag indicating whether to make the result latent. Implement the previous mkRuleMonths method in terms of this. Reviewed By: patapizza Differential Revision: D7491037 fbshipit-source-id: 4d4c41b46dc0390e17b521480f3daf8306f23834 --- Duckling/Time/EN/Corpus.hs | 3 +++ Duckling/Time/EN/Rules.hs | 26 +++++++++++++------------- Duckling/Time/Helpers.hs | 16 ++++++++++------ 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/Duckling/Time/EN/Corpus.hs b/Duckling/Time/EN/Corpus.hs index a1bba845..0ae67852 100644 --- a/Duckling/Time/EN/Corpus.hs +++ b/Duckling/Time/EN/Corpus.hs @@ -118,6 +118,9 @@ latentCorpus = (testContext, testOptions {withLatent = True}, xs) --, examples (datetime (1954, 1, 1, 0, 0, 0) Year) -- [ "1954" -- ] + , examples (datetime (2013, 5, 1, 0, 0, 0) Month) + [ "May" + ] , examples (datetimeInterval ((2013, 2, 12, 4, 0, 0), (2013, 2, 12, 12, 0, 0)) Hour) [ "morning" diff --git a/Duckling/Time/EN/Rules.hs b/Duckling/Time/EN/Rules.hs index 525a263a..0b354da9 100644 --- a/Duckling/Time/EN/Rules.hs +++ b/Duckling/Time/EN/Rules.hs @@ -1198,19 +1198,19 @@ ruleDaysOfWeek = mkRuleDaysOfWeek ] ruleMonths :: [Rule] -ruleMonths = mkRuleMonths - [ ( "January" , "january|jan\\.?" ) - , ( "February" , "february|feb\\.?" ) - , ( "March" , "march|mar\\.?" ) - , ( "April" , "april|apr\\.?" ) - , ( "May" , "may" ) - , ( "June" , "june|jun\\.?" ) - , ( "July" , "july|jul\\.?" ) - , ( "August" , "august|aug\\.?" ) - , ( "September", "september|sept?\\.?" ) - , ( "October" , "october|oct\\.?" ) - , ( "November" , "november|nov\\.?" ) - , ( "December" , "december|dec\\.?" ) +ruleMonths = mkRuleMonthsWithLatent + [ ( "January" , "january|jan\\.?" , False ) + , ( "February" , "february|feb\\.?" , False ) + , ( "March" , "march|mar\\.?" , False ) + , ( "April" , "april|apr\\.?" , False ) + , ( "May" , "may" , True ) + , ( "June" , "june|jun\\.?" , False ) + , ( "July" , "july|jul\\.?" , False ) + , ( "August" , "august|aug\\.?" , False ) + , ( "September", "september|sept?\\.?", False ) + , ( "October" , "october|oct\\.?" , False ) + , ( "November" , "november|nov\\.?" , False ) + , ( "December" , "december|dec\\.?" , False ) ] rulePartOfMonth :: Rule diff --git a/Duckling/Time/Helpers.hs b/Duckling/Time/Helpers.hs index 76d4173b..6f5ac3f2 100644 --- a/Duckling/Time/Helpers.hs +++ b/Duckling/Time/Helpers.hs @@ -8,7 +8,7 @@ {-# LANGUAGE GADTs #-} {-# LANGUAGE NoRebindableSyntax #-} - +{-# LANGUAGE TupleSections #-} module Duckling.Time.Helpers ( -- Patterns @@ -28,8 +28,8 @@ module Duckling.Time.Helpers -- Other , getIntValue, timeComputed -- Rule constructors - , mkRuleInstants, mkRuleDaysOfWeek, mkRuleMonths, mkRuleSeasons - , mkRuleHolidays, mkRuleHolidays' + , mkRuleInstants, mkRuleDaysOfWeek, mkRuleMonths, mkRuleMonthsWithLatent + , mkRuleSeasons, mkRuleHolidays, mkRuleHolidays' ) where import Data.Maybe @@ -646,10 +646,14 @@ mkRuleDaysOfWeek daysOfWeek = zipWith go daysOfWeek [1..7] mkSingleRegexRule name ptn . tt . mkOkForThisNext $ dayOfWeek i mkRuleMonths :: [(Text, String)] -> [Rule] -mkRuleMonths months = zipWith go months [1..12] +mkRuleMonths = mkRuleMonthsWithLatent . map (uncurry (,, False)) + +mkRuleMonthsWithLatent :: [(Text, String, Bool)] -> [Rule] +mkRuleMonthsWithLatent months = zipWith go months [1..12] where - go (name, ptn) i = - mkSingleRegexRule name ptn . tt . mkOkForThisNext $ month i + go (name, ptn, latent) i = + mkSingleRegexRule name ptn . tt . (if latent then mkLatent else id) + . mkOkForThisNext $ month i mkRuleSeasons :: [(Text, String, TimeData, TimeData)] -> [Rule] mkRuleSeasons = map go