-- 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.KO.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 = "에" , pattern = [ Predicate isADayOfWeek , regex "\xc5d0" ] , prod = \tokens -> case tokens of (x:_) -> Just x _ -> Nothing } ruleLiberationDay :: Rule ruleLiberationDay = Rule { name = "Liberation Day" , pattern = [ regex "\xad11\xbcf5\xc808" ] , prod = \_ -> tt $ monthDay 8 15 } ruleTheDayAfterTomorrow :: Rule ruleTheDayAfterTomorrow = Rule { name = "the day after tomorrow - 내일모레" , pattern = [ regex "(\xb0b4\xc77c)?\xbaa8\xb808" ] , prod = \_ -> tt . cycleNthAfter False TG.Day 1 $ cycleNth TG.Day 1 } ruleConstitutionDay :: Rule ruleConstitutionDay = Rule { name = "Constitution Day" , pattern = [ regex "\xc81c\xd5cc\xc808" ] , prod = \_ -> tt $ monthDay 6 17 } ruleTimeofday4 :: Rule ruleTimeofday4 = Rule { name = "이전" , pattern = [ Predicate isATimeOfDay , regex "(\xc774)?\xc804" ] , prod = \tokens -> case tokens of (Token Time td:_) -> tt $ withDirection TTime.Before td _ -> Nothing } ruleDay :: Rule ruleDay = Rule { name = "day" , pattern = [ Predicate isDOMInteger , regex "\xc77c" ] , prod = \tokens -> case tokens of (token:_) -> do v <- getIntValue token tt $ dayOfMonth v _ -> Nothing } ruleSinceTimeofday :: Rule ruleSinceTimeofday = Rule { name = "since " , pattern = [ Predicate isATimeOfDay , regex "\xc774\xb798\xb85c" ] , prod = \tokens -> case tokens of (Token Time td:_) -> tt . withDirection TTime.After $ predNth (- 1) False td _ -> Nothing } ruleThisDayofweek :: Rule ruleThisDayofweek = Rule { name = "this " , pattern = [ regex "\xc774\xbc88(\xc8fc)?|\xae08\xc8fc" , Predicate isADayOfWeek ] , prod = \tokens -> case tokens of (_:Token Time td:_) -> tt $ predNth 0 False td _ -> Nothing } ruleNewYearsDay :: Rule ruleNewYearsDay = Rule { name = "New Year's Day" , pattern = [ regex "\xc2e0\xc815|\xc124\xb0a0" ] , prod = \_ -> tt $ monthDay 1 1 } ruleLastTime :: Rule ruleLastTime = Rule { name = "last