-- Copyright (c) 2016-present, Facebook, Inc. -- All rights reserved. -- -- This source code is licensed under the BSD-style license found in the -- LICENSE file in the root directory of this source tree. An additional grant -- of patent rights can be found in the PATENTS file in the same directory. {-# LANGUAGE GADTs #-} {-# LANGUAGE NoRebindableSyntax #-} {-# LANGUAGE OverloadedStrings #-} module Duckling.Time.DE.Rules ( rules ) where import Control.Monad (liftM2) import qualified Data.Text as Text import Prelude import Duckling.Dimensions.Types import Duckling.Numeral.Helpers (parseInt) import Duckling.Ordinal.Types (OrdinalData (..)) import qualified Duckling.Ordinal.Types as TOrdinal import Duckling.Regex.Types import Duckling.Time.Helpers import Duckling.Time.Types (TimeData (..)) import qualified Duckling.Time.Types as TTime import qualified Duckling.TimeGrain.Types as TG import Duckling.Types ruleNamedday :: Rule ruleNamedday = Rule { name = "named-day" , pattern = [ regex "montags?|mo\\.?" ] , prod = \_ -> tt $ dayOfWeek 1 } ruleNamedmonth12 :: Rule ruleNamedmonth12 = Rule { name = "named-month" , pattern = [ regex "dezember|dez\\.?" ] , prod = \_ -> tt $ month 12 } ruleRelativeMinutesTotillbeforeIntegerHourofday :: Rule ruleRelativeMinutesTotillbeforeIntegerHourofday = Rule { name = "relative minutes to|till|before (hour-of-day)" , pattern = [ Predicate $ isIntegerBetween 1 59 , regex "vor" , Predicate isAnHourOfDay ] , prod = \tokens -> case tokens of (token:_:Token Time td:_) -> do n <- getIntValue token t <- minutesBefore n td Just $ Token Time t _ -> Nothing } ruleQuarterTotillbeforeIntegerHourofday :: Rule ruleQuarterTotillbeforeIntegerHourofday = Rule { name = "quarter to|till|before (hour-of-day)" , pattern = [regex "vie?rtel vor" , Predicate isAnHourOfDay ] , prod = \tokens -> case tokens of (_:Token Time td:_) -> do t <- minutesBefore 15 td Just $ Token Time t _ -> Nothing } ruleHalfTotillbeforeIntegerHourofday :: Rule ruleHalfTotillbeforeIntegerHourofday = Rule { name = "half to|till|before (hour-of-day)" , pattern = [ regex "halbe? vor" , Predicate isAnHourOfDay ] , prod = \tokens -> case tokens of (_:Token Time td:_) -> do t <- minutesBefore 30 td Just $ Token Time t _ -> Nothing } ruleNamedday2 :: Rule ruleNamedday2 = Rule { name = "named-day" , pattern = [ regex "die?nstags?|di\\.?" ] , prod = \_ -> tt $ dayOfWeek 2 } ruleValentinesDay :: Rule ruleValentinesDay = Rule { name = "valentine's day" , pattern = [ regex "valentin'?stag" ] , prod = \_ -> tt $ monthDay 2 14 } ruleTheOrdinalCycleOfTime :: Rule ruleTheOrdinalCycleOfTime = Rule { name = "the of