-- 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 Prelude import qualified Data.Text as Text import Duckling.Dimensions.Types import Duckling.Numeral.Helpers (parseInt) import Duckling.Ordinal.Types (OrdinalData (..)) import Duckling.Regex.Types import Duckling.Time.Helpers import Duckling.Time.Types (TimeData (..)) import Duckling.Types import qualified Duckling.Ordinal.Types as TOrdinal import qualified Duckling.Time.Types as TTime import qualified Duckling.TimeGrain.Types as TG ruleNamedday :: Rule ruleNamedday = Rule { name = "에" , pattern = [ Predicate isADayOfWeek , regex "에" ] , prod = \tokens -> case tokens of (x:_) -> Just x _ -> Nothing } ruleLiberationDay :: Rule ruleLiberationDay = Rule { name = "Liberation Day" , pattern = [ regex "광복절" ] , prod = \_ -> tt $ monthDay 8 15 } ruleTheDayAfterTomorrow :: Rule ruleTheDayAfterTomorrow = Rule { name = "the day after tomorrow - 내일모레" , pattern = [ regex "(내일)?모\xb808" ] , prod = \_ -> tt . cycleNthAfter False TG.Day 1 $ cycleNth TG.Day 1 } ruleConstitutionDay :: Rule ruleConstitutionDay = Rule { name = "Constitution Day" , pattern = [ regex "제헌절" ] , prod = \_ -> tt $ monthDay 6 17 } ruleTimeofday4 :: Rule ruleTimeofday4 = Rule { name = "이전" , pattern = [ Predicate isATimeOfDay , regex "(이)?전" ] , prod = \tokens -> case tokens of (Token Time td:_) -> tt $ withDirection TTime.Before td _ -> Nothing } ruleDay :: Rule ruleDay = Rule { name = "day" , pattern = [ Predicate isDOMInteger , regex "일" ] , prod = \tokens -> case tokens of (token:_) -> do v <- getIntValue token tt $ dayOfMonth v _ -> Nothing } ruleSinceTimeofday :: Rule ruleSinceTimeofday = Rule { name = "since " , pattern = [ Predicate isATimeOfDay , regex "이래로" ] , 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 "이번(주)?|금주" , 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 "신정|설날" ] , prod = \_ -> tt $ monthDay 1 1 } ruleLastTime :: Rule ruleLastTime = Rule { name = "last