{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
module Duckling.Temperature.AR.Rules
( rules
) where
import Data.Maybe
import Data.String
import Prelude
import Duckling.Dimensions.Types
import Duckling.Temperature.Helpers
import Duckling.Temperature.Types (TemperatureData(..))
import Duckling.Types
import qualified Duckling.Temperature.Types as TTemperature
ruleTemperatureDegrees :: Rule
ruleTemperatureDegrees :: Rule
ruleTemperatureDegrees = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"<latent temp> degrees"
, pattern :: Pattern
pattern =
[ Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Bool -> Predicate
isValueOnly Bool
False
, String -> PatternItem
regex String
"(درج([ةه]|ات)( مئوي[ةه])?)|°"
]
, prod :: Production
prod = \case
(Token Dimension a
Temperature a
td:[Token]
_) -> Token -> Maybe Token
forall a. a -> Maybe a
Just (Token -> Maybe Token)
-> (TemperatureData -> Token) -> TemperatureData -> Maybe Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Dimension TemperatureData -> TemperatureData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TemperatureData
Temperature (TemperatureData -> Maybe Token) -> TemperatureData -> Maybe Token
forall a b. (a -> b) -> a -> b
$
TemperatureUnit -> TemperatureData -> TemperatureData
withUnit TemperatureUnit
TTemperature.Degree a
TemperatureData
td
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleTemperatureTwoDegrees :: Rule
ruleTemperatureTwoDegrees :: Rule
ruleTemperatureTwoDegrees = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"two degrees"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"درجت(ين|ان)"
]
, prod :: Production
prod = \[Token]
_ -> Token -> Maybe Token
forall a. a -> Maybe a
Just (Token -> Maybe Token)
-> (TemperatureData -> Token) -> TemperatureData -> Maybe Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Dimension TemperatureData -> TemperatureData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TemperatureData
Temperature (TemperatureData -> Maybe Token) -> TemperatureData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Double -> TemperatureData
valueOnly Double
2
}
ruleTemperatureCelsius :: Rule
ruleTemperatureCelsius :: Rule
ruleTemperatureCelsius = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"<temp> Celsius"
, pattern :: Pattern
pattern =
[ Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Bool -> Predicate
isValueOnly Bool
True
, String -> PatternItem
regex String
"(درج([ةه]|ات) )?سي?لي?[سز]ي?وس"
]
, prod :: Production
prod = \case
(Token Dimension a
Temperature a
td:[Token]
_) -> Token -> Maybe Token
forall a. a -> Maybe a
Just (Token -> Maybe Token)
-> (TemperatureData -> Token) -> TemperatureData -> Maybe Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Dimension TemperatureData -> TemperatureData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TemperatureData
Temperature (TemperatureData -> Maybe Token) -> TemperatureData -> Maybe Token
forall a b. (a -> b) -> a -> b
$
TemperatureUnit -> TemperatureData -> TemperatureData
withUnit TemperatureUnit
TTemperature.Celsius a
TemperatureData
td
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleTemperatureFahrenheit :: Rule
ruleTemperatureFahrenheit :: Rule
ruleTemperatureFahrenheit = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"<temp> Fahrenheit"
, pattern :: Pattern
pattern =
[ Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Bool -> Predicate
isValueOnly Bool
True
, String -> PatternItem
regex String
"(درج([ةه]|ات) )?ف(ا|ي)?هرنها?يت"
]
, prod :: Production
prod = \case
(Token Dimension a
Temperature a
td:[Token]
_) -> Token -> Maybe Token
forall a. a -> Maybe a
Just (Token -> Maybe Token)
-> (TemperatureData -> Token) -> TemperatureData -> Maybe Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Dimension TemperatureData -> TemperatureData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TemperatureData
Temperature (TemperatureData -> Maybe Token) -> TemperatureData -> Maybe Token
forall a b. (a -> b) -> a -> b
$
TemperatureUnit -> TemperatureData -> TemperatureData
withUnit TemperatureUnit
TTemperature.Fahrenheit a
TemperatureData
td
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleTemperatureBelowZero :: Rule
ruleTemperatureBelowZero :: Rule
ruleTemperatureBelowZero = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"<temp> below zero"
, pattern :: Pattern
pattern =
[ Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Bool -> Predicate
isValueOnly Bool
True
, String -> PatternItem
regex String
"تحت الصفر"
]
, prod :: Production
prod = \case
(Token Dimension a
Temperature td :: a
td@TemperatureData {TTemperature.value = Just v}:
[Token]
_) -> case TemperatureData -> Maybe TemperatureUnit
TTemperature.unit a
TemperatureData
td of
Maybe TemperatureUnit
Nothing -> Token -> Maybe Token
forall a. a -> Maybe a
Just (Token -> Maybe Token)
-> (TemperatureData -> Token) -> TemperatureData -> Maybe Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Dimension TemperatureData -> TemperatureData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TemperatureData
Temperature (TemperatureData -> Token)
-> (TemperatureData -> TemperatureData) -> TemperatureData -> Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TemperatureUnit -> TemperatureData -> TemperatureData
withUnit TemperatureUnit
TTemperature.Degree (TemperatureData -> Maybe Token) -> TemperatureData -> Maybe Token
forall a b. (a -> b) -> a -> b
$
a
TemperatureData
td {value :: Maybe Double
TTemperature.value = Double -> Maybe Double
forall a. a -> Maybe a
Just (- Double
v)}
Maybe TemperatureUnit
_ -> Token -> Maybe Token
forall a. a -> Maybe a
Just (Token -> Maybe Token)
-> (TemperatureData -> Token) -> TemperatureData -> Maybe Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Dimension TemperatureData -> TemperatureData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TemperatureData
Temperature (TemperatureData -> Maybe Token) -> TemperatureData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ a
TemperatureData
td {value :: Maybe Double
TTemperature.value = Double -> Maybe Double
forall a. a -> Maybe a
Just (- Double
v)}
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
rules :: [Rule]
rules :: [Rule]
rules =
[ Rule
ruleTemperatureDegrees
, Rule
ruleTemperatureTwoDegrees
, Rule
ruleTemperatureCelsius
, Rule
ruleTemperatureFahrenheit
, Rule
ruleTemperatureBelowZero
]