-- 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.RO.Rules ( rules ) where import Control.Monad (liftM2) import Data.Text (Text) import Prelude import Duckling.Dimensions.Types import Duckling.Numeral.Helpers (parseInt) 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 ruleAcum :: Rule ruleAcum = Rule { name = "acum" , pattern = [ regex "(chiar)? ?acum|imediat" ] , prod = \_ -> tt $ cycleNth TG.Second 0 } ruleDupamiaza :: Rule ruleDupamiaza = Rule { name = "dupamiaza" , pattern = [ regex "dupamiaz(a|\x0103)|dup(a|\x0103) amiaz(a|\x0103)" ] , prod = \_ -> Token Time . mkLatent . partOfDay <$> interval TTime.Open (hour False 12) (hour False 19) } ruleValentinesDay :: Rule ruleValentinesDay = Rule { name = "valentine's day" , pattern = [ regex "sf\\.?((a|\x00e2)ntul)? Valentin" ] , prod = \_ -> tt $ monthDay 2 14 } ruleSinceTimeofday :: Rule ruleSinceTimeofday = Rule { name = "since " , pattern = [ regex "de|din" , dimension Time ] , prod = \tokens -> case tokens of (_:Token Time td:_) -> tt $ withDirection TTime.After td _ -> Nothing } ruleNewYearsDay :: Rule ruleNewYearsDay = Rule { name = "new year's day" , pattern = [ regex "(siua de )? an(ul)? nou" ] , prod = \_ -> tt $ monthDay 1 1 } ruleOrdinalTrimestruYear :: Rule ruleOrdinalTrimestruYear = Rule { name = " trimestru " , pattern = [ dimension Ordinal , Predicate $ isGrain TG.Quarter , dimension Time ] , prod = \tokens -> case tokens of (token:_:Token Time td:_) -> do n <- getIntValue token tt $ cycleNthAfter False TG.Quarter (n - 1) td _ -> Nothing } ruleInNamedmonth :: Rule ruleInNamedmonth = Rule { name = "in " , pattern = [ regex "(i|\x00ee)n" , Predicate isAMonth ] , prod = \tokens -> case tokens of (_:x:_) -> Just x _ -> Nothing } ruleLastCycleOfTime :: Rule ruleLastCycleOfTime = Rule { name = "last of