{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
module Duckling.Duration.RO.Rules
( rules
) where
import Data.String
import Prelude
import Duckling.Dimensions.Types
import Duckling.Duration.Helpers
import Duckling.Numeral.Helpers (numberWith)
import Duckling.Types
import qualified Duckling.Numeral.Types as TNumeral
import qualified Duckling.TimeGrain.Types as TG
ruleQuarterOfAnHour :: Rule
ruleQuarterOfAnHour :: Rule
ruleQuarterOfAnHour = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"quarter of an hour"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"(1/4\\s?(h|or(a|ă))|sfert de or(a|ă))"
]
, 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
}
ruleJumatateDeOra :: Rule
ruleJumatateDeOra :: Rule
ruleJumatateDeOra = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"jumatate de ora"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"(1/2\\s?(h|or(a|ă))|jum(a|ă)tate (de )?or(a|ă))"
]
, 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
}
ruleTreiSferturiDeOra :: Rule
ruleTreiSferturiDeOra :: Rule
ruleTreiSferturiDeOra = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"trei sferturi de ora"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"(3/4\\s?(h|or(a|ă))|trei sferturi de or(a|ă))"
]
, 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
}
ruleOUnitofduration :: Rule
ruleOUnitofduration :: Rule
ruleOUnitofduration = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"o <unit-of-duration>"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"o|un"
, Dimension Grain -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension Grain
TimeGrain
]
, prod :: Production
prod = \case
(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
}
ruleExactInJurDeDuration :: Rule
ruleExactInJurDeDuration :: Rule
ruleExactInJurDeDuration = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"exact|in jur de <duration>"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"(exact|aproximativ|(i|î)n jur de)"
, Dimension DurationData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension DurationData
Duration
]
, prod :: Production
prod = \case
(Token
_:Token
token:[Token]
_) -> Token -> Maybe Token
forall a. a -> Maybe a
Just Token
token
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleIntegerDeUnitofduration :: Rule
ruleIntegerDeUnitofduration :: Rule
ruleIntegerDeUnitofduration = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"<integer> <unit-of-duration>"
, pattern :: Pattern
pattern =
[ (NumeralData -> Double) -> (Double -> Bool) -> PatternItem
forall t. (NumeralData -> t) -> (t -> Bool) -> PatternItem
numberWith NumeralData -> Double
TNumeral.value (Double -> Double -> Bool
forall a. Ord a => a -> a -> Bool
>= Double
20)
, String -> PatternItem
regex String
"de"
, Dimension Grain -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension Grain
TimeGrain
]
, prod :: Production
prod = \case
(Token Dimension a
Numeral TNumeral.NumeralData{TNumeral.value = v}:
Token
_:
Token Dimension a
TimeGrain a
grain:
[Token]
_) -> Token -> Maybe Token
forall a. a -> Maybe a
Just (Token -> Maybe Token) -> (Int -> Token) -> Int -> 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 -> Token) -> (Int -> DurationData) -> Int -> Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Grain -> Int -> DurationData
duration a
Grain
grain (Int -> Maybe Token) -> Int -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Double -> Int
forall a b. (RealFrac a, Integral b) => a -> b
floor Double
v
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
rules :: [Rule]
rules :: [Rule]
rules =
[ Rule
ruleExactInJurDeDuration
, Rule
ruleJumatateDeOra
, Rule
ruleOUnitofduration
, Rule
ruleQuarterOfAnHour
, Rule
ruleTreiSferturiDeOra
, Rule
ruleIntegerDeUnitofduration
]