-- 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 OverloadedStrings #-}

module Duckling.Duration.IT.Rules
  ( rules ) where

import Prelude
import Data.String

import Duckling.Dimensions.Types
import Duckling.Duration.Helpers
import qualified Duckling.TimeGrain.Types as TG
import Duckling.Types

ruleUneUnitofduration :: Rule
ruleUneUnitofduration :: Rule
ruleUneUnitofduration = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"une <unit-of-duration>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"un[a']?"
    , Dimension Grain -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension Grain
TimeGrain
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
TimeGrain a
grain:[Token]
_) -> Token -> Maybe Token
forall a. a -> Maybe a
Just (Token -> Maybe Token)
-> (DurationData -> Token) -> DurationData -> Maybe Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Dimension DurationData -> DurationData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension DurationData
Duration (DurationData -> Maybe Token) -> DurationData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Grain -> Int -> DurationData
duration a
Grain
grain Int
1
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleUnQuartoDora :: Rule
ruleUnQuartoDora :: Rule
ruleUnQuartoDora = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"un quarto d'ora"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"un quarto d['i] ?ora"
    ]
  , prod :: Production
prod = \[Token]
_ -> Token -> Maybe Token
forall a. a -> Maybe a
Just (Token -> Maybe Token)
-> (DurationData -> Token) -> DurationData -> Maybe Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Dimension DurationData -> DurationData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension DurationData
Duration (DurationData -> Maybe Token) -> DurationData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Grain -> Int -> DurationData
duration Grain
TG.Minute Int
15
  }

ruleMezzOra :: Rule
ruleMezzOra :: Rule
ruleMezzOra = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"mezz'ora"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"mezz[a'] ?ora"
    ]
  , prod :: Production
prod = \[Token]
_ -> Token -> Maybe Token
forall a. a -> Maybe a
Just (Token -> Maybe Token)
-> (DurationData -> Token) -> DurationData -> Maybe Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Dimension DurationData -> DurationData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension DurationData
Duration (DurationData -> Maybe Token) -> DurationData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Grain -> Int -> DurationData
duration Grain
TG.Minute Int
30
  }

ruleTreQuartiDora :: Rule
ruleTreQuartiDora :: Rule
ruleTreQuartiDora = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"tre quarti d'ora"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"(3|tre) quarti d['i] ?ora"
    ]
  , prod :: Production
prod = \[Token]
_ -> Token -> Maybe Token
forall a. a -> Maybe a
Just (Token -> Maybe Token)
-> (DurationData -> Token) -> DurationData -> Maybe Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Dimension DurationData -> DurationData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension DurationData
Duration (DurationData -> Maybe Token) -> DurationData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Grain -> Int -> DurationData
duration Grain
TG.Minute Int
45
  }

rules :: [Rule]
rules :: [Rule]
rules =
  [ Rule
ruleUneUnitofduration
  , Rule
ruleUnQuartoDora
  , Rule
ruleMezzOra
  , Rule
ruleTreQuartiDora
  ]