-- 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.PT.Rules ( rules ) where import Data.Text (Text) import Prelude import qualified Data.Text as Text import Duckling.Dimensions.Types import Duckling.Numeral.Helpers (parseInt) import Duckling.Regex.Types import Duckling.Time.Helpers import Duckling.Time.Types (TimeData (..)) import Duckling.Types import qualified Duckling.Time.Types as TTime import qualified Duckling.TimeGrain.Types as TG ruleSHourmintimeofday :: Rule ruleSHourmintimeofday = Rule { name = "às (time-of-day)" , pattern = [ regex "(à|a)s?" , Predicate isATimeOfDay , regex "horas?" ] , prod = \tokens -> case tokens of (_:x:_) -> Just x _ -> Nothing } ruleTheDayAfterTomorrow :: Rule ruleTheDayAfterTomorrow = Rule { name = "the day after tomorrow" , pattern = [ regex "depois de amanh(ã|a)" ] , prod = \_ -> tt $ cycleNth TG.Day 2 } ruleNatal :: Rule ruleNatal = Rule { name = "natal" , pattern = [ regex "natal" ] , prod = \_ -> tt $ monthDay 12 25 } ruleNaoDate :: Rule ruleNaoDate = Rule { name = "n[ao] " , pattern = [ regex "n[ao]" , Predicate $ isGrainOfTime TG.Day ] , prod = \tokens -> case tokens of (_:Token Time td:_) -> tt $ notLatent td _ -> Nothing } ruleIntersectByDaOrDe :: Rule ruleIntersectByDaOrDe = Rule { name = "intersect by `da` or `de`" , pattern = [ dimension Time , regex "d[ae]" , Predicate isNotLatent ] , prod = \tokens -> case tokens of (Token Time td1:_:Token Time td2:_) -> Token Time <$> intersect td1 td2 _ -> Nothing } rulePassadosNCycle :: Rule rulePassadosNCycle = Rule { name = "passados n " , pattern = [ regex "passad(a|o)s?" , Predicate $ isIntegerBetween 2 9999 , dimension TimeGrain ] , prod = \tokens -> case tokens of (_:token:Token TimeGrain grain:_) -> do v <- getIntValue token tt $ cycleN True grain (- v) _ -> Nothing } ruleLastTime :: Rule ruleLastTime = Rule { name = "last