-- 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.VI.Rules ( rules ) where import Prelude import Data.Text (Text) import qualified Data.Text as Text import Duckling.Dimensions.Types import Duckling.Numeral.Helpers (parseInt) import Duckling.Numeral.Types (NumeralData(..)) import Duckling.Ordinal.Types (OrdinalData(..)) import Duckling.Regex.Types import Duckling.Time.Helpers import Duckling.Time.Types (TimeData (..)) import Duckling.Types 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 ruleTtDng :: Rule ruleTtDng = Rule { name = "tết dương" , pattern = [ regex "(t(ế)t d(ư)(ơ)ng)(l(ị)ch)?" ] , prod = \_ -> tt $ monthDay 1 1 } daysOfWeek :: [(Text, String)] daysOfWeek = [ ( "Monday" , "th(ứ) (2|hai)" ) , ( "Tuesday" , "th(ứ) (3|ba)" ) , ( "Wednesday", "th(ứ) 4|th(ứ) b(ố)n|th(ứ) t(ư)" ) , ( "Thursday" , "th(ứ) (5|n(ă)m)" ) , ( "Friday" , "th(ứ) 6|th(ứ) s(á)u" ) , ( "Saturday" , "th(ứ) (7|b((ả)|(ẩ))y)" ) , ( "Sunday" , "ch(ủ) nh(ậ)t" ) ] ruleDaysOfWeek :: [Rule] ruleDaysOfWeek = zipWith go daysOfWeek [1..7] where go (name, regexPattern) i = Rule { name = name , pattern = [regex regexPattern] , prod = \_ -> tt $ dayOfWeek i } months :: [(Text, String)] months = [ ( "January" , "th(á)ng (gi(ê)ng|m(ộ)t)" ) , ( "February" , "th(á)ng hai" ) , ( "March" , "th(á)ng ba" ) , ( "April" , "th(á)ng t(ư)|th(á)ng b(ố)n" ) , ( "May" , "th(á)ng n(ă)m" ) , ( "June" , "th(á)ng s(á)u" ) , ( "July" , "th(á)ng b(ả)y" ) , ( "August" , "th(á)ng t(á)m" ) , ( "September", "th(á)ng ch(í)n" ) , ( "October" , "th(á)ng m(ư)(ờ)i" ) , ( "November" , "th(á)ng m(ư)(ờ)i m(ộ)t" ) , ( "December" , "th(á)ng m(ư)(ờ)i hai" ) ] ruleMonths :: [Rule] ruleMonths = zipWith go months [1..12] where go (name, regexPattern) i = Rule { name = name , pattern = [regex regexPattern] , prod = \_ -> tt $ month i } ruleDayofmonthNamedmonth :: Rule ruleDayofmonthNamedmonth = Rule { name = " (numeric with day symbol) " , pattern = [ regex "(ng(à)y|m(ồ)ng)( m(ồ)ng)?" , Predicate isDOMInteger , Predicate isAMonth ] , prod = \tokens -> case tokens of (_:token:Token Time td:_) -> Token Time <$> intersectDOM td token _ -> Nothing } ruleDayofweekCuiCngCaTime :: Rule ruleDayofweekCuiCngCaTime = Rule { name = " cuối cùng của