From 8fbd6a04143730752666863846ce4d4963111e5a Mon Sep 17 00:00:00 2001 From: Michael Azzam Date: Wed, 29 Nov 2017 16:51:30 -0800 Subject: [PATCH] Consolidate days of week and months Summary: Refactor days of week and months rules to avoid mindless copy-pasta. Reviewed By: patapizza Differential Revision: D6438622 fbshipit-source-id: 489261b53ba50f6624996ad4581c2bf1206a8cc1 --- Duckling/Time/PT/Rules.hs | 226 ++++++-------------------------------- 1 file changed, 36 insertions(+), 190 deletions(-) diff --git a/Duckling/Time/PT/Rules.hs b/Duckling/Time/PT/Rules.hs index 7c138c86..a6c5c376 100644 --- a/Duckling/Time/PT/Rules.hs +++ b/Duckling/Time/PT/Rules.hs @@ -13,6 +13,7 @@ module Duckling.Time.PT.Rules ( rules ) where +import Data.Text (Text) import Prelude import qualified Data.Text as Text @@ -25,15 +26,6 @@ import Duckling.Types import qualified Duckling.Time.Types as TTime import qualified Duckling.TimeGrain.Types as TG -ruleNamedday :: Rule -ruleNamedday = Rule - { name = "named-day" - , pattern = - [ regex "segunda((\\s|\\-)feira)?|seg\\.?" - ] - , prod = \_ -> tt $ dayOfWeek 1 - } - ruleSHourmintimeofday :: Rule ruleSHourmintimeofday = Rule { name = "às (time-of-day)" @@ -56,24 +48,6 @@ ruleTheDayAfterTomorrow = Rule , prod = \_ -> tt $ cycleNth TG.Day 2 } -ruleNamedmonth12 :: Rule -ruleNamedmonth12 = Rule - { name = "named-month" - , pattern = - [ regex "dezembro|dez\\.?" - ] - , prod = \_ -> tt $ month 12 - } - -ruleNamedday2 :: Rule -ruleNamedday2 = Rule - { name = "named-day" - , pattern = - [ regex "ter(ç|c)a((\\s|\\-)feira)?|ter\\." - ] - , prod = \_ -> tt $ dayOfWeek 2 - } - ruleNatal :: Rule ruleNatal = Rule { name = "natal" @@ -135,15 +109,6 @@ ruleLastTime = Rule _ -> Nothing } -ruleNamedday6 :: Rule -ruleNamedday6 = Rule - { name = "named-day" - , pattern = - [ regex "s(á|a)bado|s(á|a)b\\.?" - ] - , prod = \_ -> tt $ dayOfWeek 6 - } - ruleDatetimeDatetimeInterval :: Rule ruleDatetimeDatetimeInterval = Rule { name = " - (interval)" @@ -158,15 +123,6 @@ ruleDatetimeDatetimeInterval = Rule _ -> Nothing } -ruleNamedmonth7 :: Rule -ruleNamedmonth7 = Rule - { name = "named-month" - , pattern = - [ regex "julho|jul\\.?" - ] - , prod = \_ -> tt $ month 7 - } - ruleEvening :: Rule ruleEvening = Rule { name = "evening" @@ -227,15 +183,6 @@ ruleHhhmmTimeofday = Rule _ -> Nothing } -ruleNamedday4 :: Rule -ruleNamedday4 = Rule - { name = "named-day" - , pattern = - [ regex "quinta((\\s|\\-)feira)?|qui\\.?" - ] - , prod = \_ -> tt $ dayOfWeek 4 - } - ruleProximoCycle :: Rule ruleProximoCycle = Rule { name = "proximo " @@ -583,15 +530,6 @@ ruleThreeQuarterParaAsHourofdayAsRelativeMinutes = Rule _ -> Nothing } -ruleNamedmonth :: Rule -ruleNamedmonth = Rule - { name = "named-month" - , pattern = - [ regex "janeiro|jan\\.?" - ] - , prod = \_ -> tt $ month 1 - } - ruleTiradentes :: Rule ruleTiradentes = Rule { name = "Tiradentes" @@ -627,15 +565,6 @@ rulePartofdayDessaSemana = Rule _ -> Nothing } -ruleNamedmonth3 :: Rule -ruleNamedmonth3 = Rule - { name = "named-month" - , pattern = - [ regex "mar(ç|c)o|mar\\.?" - ] - , prod = \_ -> tt $ month 3 - } - ruleDepoisDasTimeofday :: Rule ruleDepoisDasTimeofday = Rule { name = "depois das " @@ -689,15 +618,6 @@ ruleAfternoon = Rule interval TTime.Open from to } -ruleNamedmonth4 :: Rule -ruleNamedmonth4 = Rule - { name = "named-month" - , pattern = - [ regex "abril|abr\\.?" - ] - , prod = \_ -> tt $ month 4 - } - ruleDimTimeDaManha :: Rule ruleDimTimeDaManha = Rule { name = " da manha" @@ -737,15 +657,6 @@ ruleMidnight = Rule , prod = \_ -> tt $ hour False 0 } -ruleNamedday5 :: Rule -ruleNamedday5 = Rule - { name = "named-day" - , pattern = - [ regex "sexta((\\s|\\-)feira)?|sex\\.?" - ] - , prod = \_ -> tt $ dayOfWeek 5 - } - ruleDdddMonthinterval :: Rule ruleDdddMonthinterval = Rule { name = "dd-dd (interval)" @@ -797,15 +708,6 @@ ruleUltimoTime = Rule _ -> Nothing } -ruleNamedmonth2 :: Rule -ruleNamedmonth2 = Rule - { name = "named-month" - , pattern = - [ regex "fevereiro|fev\\.?" - ] - , prod = \_ -> tt $ month 2 - } - ruleNamedmonthnameddayPast :: Rule ruleNamedmonthnameddayPast = Rule { name = " past" @@ -948,15 +850,6 @@ ruleDeDatetimeDatetimeInterval = Rule _ -> Nothing } -ruleNamedmonth6 :: Rule -ruleNamedmonth6 = Rule - { name = "named-month" - , pattern = - [ regex "junho|jun\\.?" - ] - , prod = \_ -> tt $ month 6 - } - ruleDentroDeDuration :: Rule ruleDentroDeDuration = Rule { name = "dentro de " @@ -985,15 +878,6 @@ ruleSTimeofday = Rule _ -> Nothing } -ruleNamedmonth8 :: Rule -ruleNamedmonth8 = Rule - { name = "named-month" - , pattern = - [ regex "agosto|ago\\.?" - ] - , prod = \_ -> tt $ month 8 - } - ruleDimTimeDaTarde :: Rule ruleDimTimeDaTarde = Rule { name = " da tarde" @@ -1364,24 +1248,6 @@ ruleCyclePassado = Rule _ -> Nothing } -ruleNamedmonth5 :: Rule -ruleNamedmonth5 = Rule - { name = "named-month" - , pattern = - [ regex "maio|mai\\.?" - ] - , prod = \_ -> tt $ month 5 - } - -ruleNamedday7 :: Rule -ruleNamedday7 = Rule - { name = "named-day" - , pattern = - [ regex "domingo|dom\\.?" - ] - , prod = \_ -> tt $ dayOfWeek 7 - } - ruleNossaSenhoraAparecida :: Rule ruleNossaSenhoraAparecida = Rule { name = "Nossa Senhora Aparecida" @@ -1413,15 +1279,6 @@ ruleYear = Rule _ -> Nothing } -ruleNamedmonth10 :: Rule -ruleNamedmonth10 = Rule - { name = "named-month" - , pattern = - [ regex "outubro|out\\.?" - ] - , prod = \_ -> tt $ month 10 - } - ruleAntesDasTimeofday :: Rule ruleAntesDasTimeofday = Rule { name = "antes das " @@ -1465,15 +1322,6 @@ ruleDdmmyyyy = Rule _ -> Nothing } -ruleNamedmonth11 :: Rule -ruleNamedmonth11 = Rule - { name = "named-month" - , pattern = - [ regex "novembro|nov\\.?" - ] - , prod = \_ -> tt $ month 11 - } - ruleIndependecia :: Rule ruleIndependecia = Rule { name = "Independecia" @@ -1483,15 +1331,6 @@ ruleIndependecia = Rule , prod = \_ -> tt $ monthDay 9 7 } -ruleNamedday3 :: Rule -ruleNamedday3 = Rule - { name = "named-day" - , pattern = - [ regex "quarta((\\s|\\-)feira)?|qua\\.?" - ] - , prod = \_ -> tt $ dayOfWeek 3 - } - ruleTomorrow :: Rule ruleTomorrow = Rule { name = "tomorrow" @@ -1501,15 +1340,6 @@ ruleTomorrow = Rule , prod = \_ -> tt $ cycleNth TG.Day 1 } -ruleNamedmonth9 :: Rule -ruleNamedmonth9 = Rule - { name = "named-month" - , pattern = - [ regex "setembro|set\\.?" - ] - , prod = \_ -> tt $ month 9 - } - ruleTimezone :: Rule ruleTimezone = Rule { name = "