Duration/EN: Leverage TimeGrain for number.number hours

Summary: also kill redundant `isGrain` helper from `Time`.

Reviewed By: dwhit, haoxuany

Differential Revision: D18937649

fbshipit-source-id: ed658cc3bac70e6592dabae536a31a4c2da8a578
This commit is contained in:
Julien Odent 2019-12-11 12:19:11 -08:00 committed by Facebook Github Bot
parent 0ebaf378dc
commit a6b7253aa4
21 changed files with 80 additions and 58 deletions

View File

@ -101,7 +101,8 @@ ruleDurationDotNumeralHours :: Rule
ruleDurationDotNumeralHours = Rule ruleDurationDotNumeralHours = Rule
{ name = "number.number hours" { name = "number.number hours"
, pattern = , pattern =
[ regex "(\\d+)\\.(\\d+) *h((ou)?rs?)?" [ regex "(\\d+)\\.(\\d+)"
, Predicate $ isGrain TG.Hour
] ]
, prod = \case , prod = \case
(Token RegexMatch (GroupMatch (h:m:_)):_) -> do (Token RegexMatch (GroupMatch (h:m:_)):_) -> do

View File

@ -17,6 +17,7 @@ import Data.Text (Text)
import Prelude import Prelude
import Duckling.Dimensions.Types import Duckling.Dimensions.Types
import Duckling.Duration.Helpers (isGrain)
import Duckling.Numeral.Helpers (parseInt) import Duckling.Numeral.Helpers (parseInt)
import Duckling.Ordinal.Types (OrdinalData (..)) import Duckling.Ordinal.Types (OrdinalData (..))
import Duckling.Time.Helpers import Duckling.Time.Helpers

View File

@ -18,13 +18,14 @@ import Data.Text (Text)
import qualified Data.Text as Text import qualified Data.Text as Text
import Duckling.Dimensions.Types import Duckling.Dimensions.Types
import Duckling.Duration.Helpers (isGrain)
import Duckling.Numeral.Helpers (parseInt) import Duckling.Numeral.Helpers (parseInt)
import Duckling.Ordinal.Types (OrdinalData (..)) import Duckling.Ordinal.Types (OrdinalData(..))
import Duckling.Regex.Types (GroupMatch(..)) import Duckling.Regex.Types (GroupMatch(..))
import Duckling.Time.Computed import Duckling.Time.Computed
import Duckling.Time.Helpers import Duckling.Time.Helpers
import Duckling.Time.HolidayHelpers import Duckling.Time.HolidayHelpers
import Duckling.Time.Types (TimeData (..)) import Duckling.Time.Types (TimeData(..))
import Duckling.Types import Duckling.Types
import qualified Duckling.Ordinal.Types as TOrdinal import qualified Duckling.Ordinal.Types as TOrdinal
import qualified Duckling.Time.Types as TTime import qualified Duckling.Time.Types as TTime

View File

@ -10,7 +10,8 @@
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedStrings #-}
module Duckling.Time.EL.Rules module Duckling.Time.EL.Rules
( rules ) where ( rules
) where
import Data.HashMap.Strict (HashMap) import Data.HashMap.Strict (HashMap)
import Data.Text (Text) import Data.Text (Text)
@ -19,14 +20,14 @@ import qualified Data.HashMap.Strict as HashMap
import qualified Data.Text as Text import qualified Data.Text as Text
import Duckling.Dimensions.Types import Duckling.Dimensions.Types
import Duckling.Duration.Helpers (duration) import Duckling.Duration.Helpers (duration, isGrain)
import Duckling.Duration.Types (DurationData (DurationData)) import Duckling.Duration.Types (DurationData(DurationData))
import Duckling.Numeral.Helpers (parseInt, numeralMapEL) import Duckling.Numeral.Helpers (parseInt, numeralMapEL)
import Duckling.Numeral.Types (NumeralData (..)) import Duckling.Numeral.Types (NumeralData(..))
import Duckling.Ordinal.Types (OrdinalData (..), isBetween) import Duckling.Ordinal.Types (OrdinalData(..), isBetween)
import Duckling.Regex.Types import Duckling.Regex.Types
import Duckling.Time.Helpers import Duckling.Time.Helpers
import Duckling.Time.Types (TimeData (..)) import Duckling.Time.Types (TimeData(..))
import Duckling.Types import Duckling.Types
import qualified Duckling.Numeral.Types as TNumeral import qualified Duckling.Numeral.Types as TNumeral
import qualified Duckling.Ordinal.Types as TOrdinal import qualified Duckling.Ordinal.Types as TOrdinal

View File

@ -20,7 +20,7 @@ import Prelude
import qualified Data.Text as Text import qualified Data.Text as Text
import Duckling.Dimensions.Types import Duckling.Dimensions.Types
import Duckling.Duration.Helpers (duration) import Duckling.Duration.Helpers (duration, isGrain)
import Duckling.Duration.Types (DurationData (..)) import Duckling.Duration.Types (DurationData (..))
import Duckling.Numeral.Helpers (isNatural, parseInt) import Duckling.Numeral.Helpers (isNatural, parseInt)
import Duckling.Numeral.Types (NumeralData (..)) import Duckling.Numeral.Types (NumeralData (..))

View File

@ -10,17 +10,19 @@
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedStrings #-}
module Duckling.Time.ES.Rules module Duckling.Time.ES.Rules
( rules ) where ( rules
) where
import Prelude import Prelude
import qualified Data.Text as Text import qualified Data.Text as Text
import Duckling.Dimensions.Types import Duckling.Dimensions.Types
import Duckling.Duration.Helpers (isGrain)
import Duckling.Numeral.Helpers (parseInt) import Duckling.Numeral.Helpers (parseInt)
import Duckling.Ordinal.Types (OrdinalData (..)) import Duckling.Ordinal.Types (OrdinalData(..))
import Duckling.Regex.Types import Duckling.Regex.Types
import Duckling.Time.Helpers import Duckling.Time.Helpers
import Duckling.Time.Types (TimeData (..)) import Duckling.Time.Types (TimeData(..))
import Duckling.Types import Duckling.Types
import qualified Duckling.Ordinal.Types as TOrdinal import qualified Duckling.Ordinal.Types as TOrdinal
import qualified Duckling.Time.Types as TTime import qualified Duckling.Time.Types as TTime

View File

@ -10,18 +10,20 @@
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedStrings #-}
module Duckling.Time.GA.Rules module Duckling.Time.GA.Rules
( rules ) where ( rules
) where
import Data.Text (Text) import Data.Text (Text)
import Prelude import Prelude
import Duckling.Dimensions.Types import Duckling.Dimensions.Types
import Duckling.Duration.Helpers (isGrain)
import Duckling.Numeral.Helpers (parseInt) import Duckling.Numeral.Helpers (parseInt)
import qualified Duckling.Ordinal.Types as TOrdinal
import Duckling.Regex.Types import Duckling.Regex.Types
import Duckling.Time.Helpers import Duckling.Time.Helpers
import qualified Duckling.TimeGrain.Types as TG
import Duckling.Types import Duckling.Types
import qualified Duckling.Ordinal.Types as TOrdinal
import qualified Duckling.TimeGrain.Types as TG
ruleArInn :: Rule ruleArInn :: Rule
ruleArInn = Rule ruleArInn = Rule

View File

@ -9,7 +9,8 @@
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedStrings #-}
module Duckling.Time.HE.Rules module Duckling.Time.HE.Rules
( rules ) where ( rules
) where
import Data.Maybe import Data.Maybe
import Data.String import Data.String
@ -18,12 +19,13 @@ import Prelude
import qualified Data.Text as Text import qualified Data.Text as Text
import Duckling.Dimensions.Types import Duckling.Dimensions.Types
import Duckling.Duration.Helpers (isGrain)
import Duckling.Numeral.Helpers (parseInt) import Duckling.Numeral.Helpers (parseInt)
import Duckling.Numeral.Types (NumeralData (..)) import Duckling.Numeral.Types (NumeralData(..))
import Duckling.Ordinal.Types (OrdinalData (..)) import Duckling.Ordinal.Types (OrdinalData(..))
import Duckling.Regex.Types import Duckling.Regex.Types
import Duckling.Time.Helpers import Duckling.Time.Helpers
import Duckling.Time.Types (TimeData (..)) import Duckling.Time.Types (TimeData(..))
import Duckling.Types import Duckling.Types
import qualified Duckling.Numeral.Types as TNumeral import qualified Duckling.Numeral.Types as TNumeral
import qualified Duckling.Ordinal.Types as TOrdinal import qualified Duckling.Ordinal.Types as TOrdinal

View File

@ -19,12 +19,13 @@ import Prelude
import qualified Data.Text as Text import qualified Data.Text as Text
import Duckling.Dimensions.Types import Duckling.Dimensions.Types
import Duckling.Duration.Helpers (isGrain)
import Duckling.Numeral.Helpers (parseInt) import Duckling.Numeral.Helpers (parseInt)
import Duckling.Numeral.Types (NumeralData (..)) import Duckling.Numeral.Types (NumeralData(..))
import Duckling.Ordinal.Types (OrdinalData (..)) import Duckling.Ordinal.Types (OrdinalData(..))
import Duckling.Regex.Types import Duckling.Regex.Types
import Duckling.Time.Helpers import Duckling.Time.Helpers
import Duckling.Time.Types (TimeData (..)) import Duckling.Time.Types (TimeData(..))
import Duckling.Types import Duckling.Types
import qualified Duckling.Numeral.Types as TNumeral import qualified Duckling.Numeral.Types as TNumeral
import qualified Duckling.Ordinal.Types as TOrdinal import qualified Duckling.Ordinal.Types as TOrdinal

View File

@ -13,7 +13,7 @@ module Duckling.Time.Helpers
( -- Patterns ( -- Patterns
hasNoDirection, isADayOfWeek, isAMonth, isAnHourOfDay, isAPartOfDay hasNoDirection, isADayOfWeek, isAMonth, isAnHourOfDay, isAPartOfDay
, isATimeOfDay, isDurationGreaterThan, isDOMInteger, isDOMOrdinal, isDOMValue , isATimeOfDay, isDurationGreaterThan, isDOMInteger, isDOMOrdinal, isDOMValue
, isGrain, isGrainFinerThan, isGrainCoarserThan, isGrainOfTime , isGrainFinerThan, isGrainCoarserThan, isGrainOfTime
, isIntegerBetween, isNotLatent , isOrdinalBetween, isMidnightOrNoon , isIntegerBetween, isNotLatent , isOrdinalBetween, isMidnightOrNoon
, isOkWithThisNext, sameGrain, hasTimezone, hasNoTimezone, today , isOkWithThisNext, sameGrain, hasTimezone, hasNoTimezone, today
-- Production -- Production
@ -267,10 +267,6 @@ shiftTimezone providedSeries pred1 =
-- ----------------------------------------------------------------- -- -----------------------------------------------------------------
-- Patterns -- Patterns
isGrain :: TG.Grain -> Predicate
isGrain value (Token TimeGrain grain) = grain == value
isGrain _ _ = False
isGrainFinerThan :: TG.Grain -> Predicate isGrainFinerThan :: TG.Grain -> Predicate
isGrainFinerThan value (Token Time TimeData{TTime.timeGrain = g}) = g < value isGrainFinerThan value (Token Time TimeData{TTime.timeGrain = g}) = g < value
isGrainFinerThan _ _ = False isGrainFinerThan _ _ = False

View File

@ -10,19 +10,21 @@
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedStrings #-}
module Duckling.Time.IT.Rules module Duckling.Time.IT.Rules
( rules ) where ( rules
) where
import Data.Text (Text) import Data.Text (Text)
import Prelude import Prelude
import qualified Data.Text as Text import qualified Data.Text as Text
import Duckling.Dimensions.Types import Duckling.Dimensions.Types
import Duckling.Duration.Helpers (isGrain)
import Duckling.Numeral.Helpers (parseInt) import Duckling.Numeral.Helpers (parseInt)
import Duckling.Numeral.Types (NumeralData(..)) import Duckling.Numeral.Types (NumeralData(..))
import Duckling.Ordinal.Types (OrdinalData(..)) import Duckling.Ordinal.Types (OrdinalData(..))
import Duckling.Regex.Types import Duckling.Regex.Types
import Duckling.Time.Helpers import Duckling.Time.Helpers
import Duckling.Time.Types (TimeData (..)) import Duckling.Time.Types (TimeData(..))
import Duckling.Types import Duckling.Types
import qualified Duckling.Numeral.Types as TNumeral import qualified Duckling.Numeral.Types as TNumeral
import qualified Duckling.Ordinal.Types as TOrdinal import qualified Duckling.Ordinal.Types as TOrdinal

View File

@ -21,15 +21,15 @@ import Prelude
import qualified Data.Text as Text import qualified Data.Text as Text
import Duckling.Dimensions.Types import Duckling.Dimensions.Types
import Duckling.Duration.Helpers (duration) import Duckling.Duration.Helpers (duration, isGrain)
import Duckling.Duration.Types (DurationData (..)) import Duckling.Duration.Types (DurationData(..))
import Duckling.Numeral.Helpers (isNatural, parseInt) import Duckling.Numeral.Helpers (isNatural, parseInt)
import Duckling.Numeral.Types (NumeralData (..)) import Duckling.Numeral.Types (NumeralData(..))
import Duckling.Ordinal.Types (OrdinalData (..)) import Duckling.Ordinal.Types (OrdinalData(..))
import Duckling.Regex.Types import Duckling.Regex.Types
import Duckling.Time.Computed import Duckling.Time.Computed
import Duckling.Time.Helpers import Duckling.Time.Helpers
import Duckling.Time.Types (TimeData (..)) import Duckling.Time.Types (TimeData(..))
import Duckling.Types import Duckling.Types
import qualified Duckling.Duration.Types as TDuration import qualified Duckling.Duration.Types as TDuration
import qualified Duckling.Numeral.Types as TNumeral import qualified Duckling.Numeral.Types as TNumeral

View File

@ -16,11 +16,12 @@ import Prelude
import qualified Data.Text as Text import qualified Data.Text as Text
import Duckling.Dimensions.Types import Duckling.Dimensions.Types
import Duckling.Duration.Helpers (isGrain)
import Duckling.Numeral.Helpers (parseInt) import Duckling.Numeral.Helpers (parseInt)
import Duckling.Ordinal.Types (OrdinalData (..)) import Duckling.Ordinal.Types (OrdinalData(..))
import Duckling.Regex.Types import Duckling.Regex.Types
import Duckling.Time.Helpers import Duckling.Time.Helpers
import Duckling.Time.Types (TimeData (..)) import Duckling.Time.Types (TimeData(..))
import Duckling.Types import Duckling.Types
import qualified Duckling.Ordinal.Types as TOrdinal import qualified Duckling.Ordinal.Types as TOrdinal
import qualified Duckling.Time.Types as TTime import qualified Duckling.Time.Types as TTime

View File

@ -10,17 +10,19 @@
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedStrings #-}
module Duckling.Time.NB.Rules module Duckling.Time.NB.Rules
( rules ) where ( rules
) where
import Data.Text (Text) import Data.Text (Text)
import Prelude import Prelude
import Duckling.Dimensions.Types import Duckling.Dimensions.Types
import Duckling.Duration.Helpers (isGrain)
import Duckling.Numeral.Helpers (parseInt) import Duckling.Numeral.Helpers (parseInt)
import Duckling.Ordinal.Types (OrdinalData (..)) import Duckling.Ordinal.Types (OrdinalData(..))
import Duckling.Regex.Types import Duckling.Regex.Types
import Duckling.Time.Helpers import Duckling.Time.Helpers
import Duckling.Time.Types (TimeData (..)) import Duckling.Time.Types (TimeData(..))
import Duckling.Types import Duckling.Types
import qualified Data.Text as Text import qualified Data.Text as Text
import qualified Duckling.Ordinal.Types as TOrdinal import qualified Duckling.Ordinal.Types as TOrdinal

View File

@ -18,14 +18,14 @@ import Prelude
import qualified Data.Text as Text import qualified Data.Text as Text
import Duckling.Dimensions.Types import Duckling.Dimensions.Types
import Duckling.Duration.Helpers (duration) import Duckling.Duration.Helpers (duration, isGrain)
import Duckling.Numeral.Helpers (parseInt) import Duckling.Numeral.Helpers (parseInt)
import Duckling.Numeral.Types (NumeralData (..)) import Duckling.Numeral.Types (NumeralData(..))
import Duckling.Ordinal.Types (OrdinalData (..)) import Duckling.Ordinal.Types (OrdinalData(..))
import Duckling.Regex.Types import Duckling.Regex.Types
import Duckling.Time.Helpers import Duckling.Time.Helpers
import Duckling.Time.HolidayHelpers import Duckling.Time.HolidayHelpers
import Duckling.Time.Types (TimeData (..)) import Duckling.Time.Types (TimeData(..))
import Duckling.Types import Duckling.Types
import qualified Duckling.Numeral.Types as TNumeral import qualified Duckling.Numeral.Types as TNumeral
import qualified Duckling.Ordinal.Types as TOrdinal import qualified Duckling.Ordinal.Types as TOrdinal

View File

@ -10,17 +10,19 @@
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedStrings #-}
module Duckling.Time.PL.Rules module Duckling.Time.PL.Rules
( rules ) where ( rules
) where
import Prelude import Prelude
import qualified Data.Text as Text import qualified Data.Text as Text
import Duckling.Dimensions.Types import Duckling.Dimensions.Types
import Duckling.Duration.Helpers (isGrain)
import Duckling.Numeral.Helpers (parseInt) import Duckling.Numeral.Helpers (parseInt)
import Duckling.Ordinal.Types (OrdinalData(..)) import Duckling.Ordinal.Types (OrdinalData(..))
import Duckling.Regex.Types import Duckling.Regex.Types
import Duckling.Time.Helpers import Duckling.Time.Helpers
import Duckling.Time.Types (TimeData (..)) import Duckling.Time.Types (TimeData(..))
import Duckling.Time.Computed import Duckling.Time.Computed
import Duckling.Types import Duckling.Types
import qualified Duckling.Ordinal.Types as TOrdinal import qualified Duckling.Ordinal.Types as TOrdinal

View File

@ -18,15 +18,16 @@ import Prelude
import qualified Data.Text as Text import qualified Data.Text as Text
import Duckling.Dimensions.Types import Duckling.Dimensions.Types
import Duckling.Duration.Helpers (isGrain)
import Duckling.Numeral.Helpers (parseInt) import Duckling.Numeral.Helpers (parseInt)
import Duckling.Ordinal.Types (OrdinalData(..))
import Duckling.Regex.Types import Duckling.Regex.Types
import Duckling.Time.Helpers import Duckling.Time.Helpers
import Duckling.Time.Types (TimeData (..)) import Duckling.Time.Types (TimeData(..))
import Duckling.Types import Duckling.Types
import Duckling.Ordinal.Types (OrdinalData (..)) import qualified Duckling.Ordinal.Types as TOrdinal
import qualified Duckling.Time.Types as TTime import qualified Duckling.Time.Types as TTime
import qualified Duckling.TimeGrain.Types as TG import qualified Duckling.TimeGrain.Types as TG
import qualified Duckling.Ordinal.Types as TOrdinal
ruleSHourmintimeofday :: Rule ruleSHourmintimeofday :: Rule
ruleSHourmintimeofday = Rule ruleSHourmintimeofday = Rule

View File

@ -16,10 +16,11 @@ import Data.Text (Text)
import Prelude import Prelude
import Duckling.Dimensions.Types import Duckling.Dimensions.Types
import Duckling.Duration.Helpers (isGrain)
import Duckling.Numeral.Helpers (parseInt) import Duckling.Numeral.Helpers (parseInt)
import Duckling.Regex.Types import Duckling.Regex.Types
import Duckling.Time.Helpers import Duckling.Time.Helpers
import Duckling.Time.Types (TimeData (..)) import Duckling.Time.Types (TimeData(..))
import Duckling.Types import Duckling.Types
import qualified Data.Text as Text import qualified Data.Text as Text
import qualified Duckling.Time.Types as TTime import qualified Duckling.Time.Types as TTime

View File

@ -10,17 +10,19 @@
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedStrings #-}
module Duckling.Time.SV.Rules module Duckling.Time.SV.Rules
( rules ) where ( rules
) where
import Data.Text (Text) import Data.Text (Text)
import Prelude import Prelude
import Duckling.Dimensions.Types import Duckling.Dimensions.Types
import Duckling.Duration.Helpers (isGrain)
import Duckling.Numeral.Helpers (parseInt) import Duckling.Numeral.Helpers (parseInt)
import Duckling.Ordinal.Types (OrdinalData (..)) import Duckling.Ordinal.Types (OrdinalData(..))
import Duckling.Regex.Types import Duckling.Regex.Types
import Duckling.Time.Helpers import Duckling.Time.Helpers
import Duckling.Time.Types (TimeData (..)) import Duckling.Time.Types (TimeData(..))
import Duckling.Types import Duckling.Types
import qualified Data.Text as Text import qualified Data.Text as Text
import qualified Duckling.Ordinal.Types as TOrdinal import qualified Duckling.Ordinal.Types as TOrdinal

View File

@ -10,18 +10,20 @@
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedStrings #-}
module Duckling.Time.UK.Rules module Duckling.Time.UK.Rules
( rules ) where ( rules
) where
import Prelude import Prelude
import Data.Text (Text) import Data.Text (Text)
import qualified Data.Text as Text import qualified Data.Text as Text
import Duckling.Dimensions.Types import Duckling.Dimensions.Types
import Duckling.Duration.Helpers (isGrain)
import Duckling.Numeral.Helpers (parseInt) import Duckling.Numeral.Helpers (parseInt)
import Duckling.Ordinal.Types (OrdinalData (..)) import Duckling.Ordinal.Types (OrdinalData(..))
import Duckling.Regex.Types import Duckling.Regex.Types
import Duckling.Time.Helpers import Duckling.Time.Helpers
import Duckling.Time.Types (TimeData (..)) import Duckling.Time.Types (TimeData(..))
import Duckling.Types import Duckling.Types
import qualified Duckling.Ordinal.Types as TOrdinal import qualified Duckling.Ordinal.Types as TOrdinal
import qualified Duckling.Time.Types as TTime import qualified Duckling.Time.Types as TTime

View File

@ -9,19 +9,21 @@
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedStrings #-}
module Duckling.Time.VI.Rules module Duckling.Time.VI.Rules
( rules ) where ( rules
) where
import Prelude import Prelude
import Data.Text (Text) import Data.Text (Text)
import qualified Data.Text as Text import qualified Data.Text as Text
import Duckling.Dimensions.Types import Duckling.Dimensions.Types
import Duckling.Duration.Helpers (isGrain)
import Duckling.Numeral.Helpers (parseInt) import Duckling.Numeral.Helpers (parseInt)
import Duckling.Numeral.Types (NumeralData(..)) import Duckling.Numeral.Types (NumeralData(..))
import Duckling.Ordinal.Types (OrdinalData(..)) import Duckling.Ordinal.Types (OrdinalData(..))
import Duckling.Regex.Types import Duckling.Regex.Types
import Duckling.Time.Helpers import Duckling.Time.Helpers
import Duckling.Time.Types (TimeData (..)) import Duckling.Time.Types (TimeData(..))
import Duckling.Types import Duckling.Types
import qualified Duckling.Numeral.Types as TNumeral import qualified Duckling.Numeral.Types as TNumeral
import qualified Duckling.Ordinal.Types as TOrdinal import qualified Duckling.Ordinal.Types as TOrdinal