-- 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. {-# LANGUAGE GADTs #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE NamedFieldPuns #-} {-# LANGUAGE NoRebindableSyntax #-} {-# LANGUAGE OverloadedStrings #-} module Duckling.Time.KA.Rules ( rules ) where import Data.Maybe import Data.Text (Text) import Prelude import qualified Data.Text as Text import Duckling.Dimensions.Types import Duckling.Duration.Helpers (duration, isGrain) import Duckling.Duration.Types (DurationData(..)) import Duckling.Numeral.Helpers (isNatural, parseInt) import Duckling.Numeral.Types (NumeralData(..)) import Duckling.Ordinal.Types (OrdinalData(..)) import Duckling.Regex.Types import Duckling.Time.Computed import Duckling.Time.Helpers import Duckling.Time.Types (TimeData(..)) import Duckling.Types import qualified Duckling.Duration.Types as TDuration import qualified Duckling.Numeral.Types as TNumeral import qualified Duckling.Ordinal.Types as TOrdinal import qualified Duckling.Time.Types as TTime import qualified Duckling.TimeGrain.Types as TG -- Georgian weekend geoWeekend :: TimeData geoWeekend = case interval TTime.Open fri mon of Just td -> td Nothing -> weekend where fri = dayOfWeek 6 mon = dayOfWeek 7 ruleIntersect :: Rule ruleIntersect = Rule { name = "intersect" , pattern = [ Predicate $ or . sequence [isNotLatent, isGrainOfTime TG.Year] , Predicate $ or . sequence [isNotLatent, isGrainOfTime TG.Year] ] , prod = \case (Token Time td1:Token Time td2:_) | (not $ TTime.latent td1) || (not $ TTime.latent td2) -> Token Time . notLatent <$> intersect td1 td2 _ -> Nothing } ruleAbsorbInYear :: Rule ruleAbsorbInYear = Rule { name = "in year" , pattern = [ Predicate $ isGrainOfTime TG.Year , regex " ?წელს| ?წელი| ?წლის|-ში|ში" ] , prod = \case (Token Time td:_) -> tt $ notLatent td _ -> Nothing } ruleYearInterval :: Rule ruleYearInterval = Rule { name = " year" , pattern = [ Predicate isNatural , regex "წელიწად(ის|ი|ში)?|წლ(ის)?|წელ(შ?ი|ს)" ] , prod = \case (token:_) -> do n <- getIntValue token Token Time <$> interval TTime.Open (year n) (year $ n + 1) _ -> Nothing } ruleInstants :: [Rule] ruleInstants = mkRuleInstants [ ("ახლა", TG.Second, 0, "ახლავე|ეხლავე|ეხლა|ახლა|ამ წამს|ამ წუთას|ამ მომენტისთვი") , ("დღეს", TG.Day, 0, "დღეს") , ("ხვალ", TG.Day, 1, "ხვალე?") , ("ზეგ", TG.Day, 2, "ზეგ") , ("მაზეგ", TG.Day, 3, "მაზეგ") , ("გუშინ", TG.Day, -1, "გუშინ?") , ("გუშინწინ", TG.Day, -2, "გუშინ ?წინ") ] ruleNow :: Rule ruleNow = Rule { name = "now" , pattern = [ regex "ახლავე|ახლა|ამწუთას|ამ მომენტისთვის" ] , prod = const $ tt now } ruleNextDOW :: Rule ruleNextDOW = Rule { name = "this|next " , pattern = [ regex "შემდეგი|მომავალი" , Predicate isADayOfWeek ] , prod = \case (_:Token Time td:_) -> tt $ predNth 1 True td _ -> Nothing } ruleThisTime :: Rule ruleThisTime = Rule { name = "this