{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
module Duckling.Temperature.MN.Rules
( rules ) where
import Prelude
import Data.String
import Duckling.Dimensions.Types
import Duckling.Temperature.Helpers
import Duckling.Temperature.Types (TemperatureData(..))
import qualified Duckling.Temperature.Types as TTemperature
import Duckling.Types
ruleTemperatureDegrees :: Rule
ruleTemperatureDegrees :: Rule
ruleTemperatureDegrees = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"<latent temp> градус"
, 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
}
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
"c(el[cs]?(ius)?)?\\.?"
]
, 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
}
ruleTempC :: Rule
ruleTempC :: Rule
ruleTempC = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"<temp> °C"
, 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
"c"
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(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
"((f(ah?rh?eh?n(h?eit)?)?\\.?)|фарангейт)"
]
, 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
}
ruleIntervalMax :: Rule
ruleIntervalMax :: Rule
ruleIntervalMax = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"under/less/lower/no more than <temp>"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"доогуур|(бага|ихгүй|их биш)"
, Predicate -> PatternItem
Predicate Predicate
isSimpleTemperature
]
, prod :: Production
prod = \case
(Token
_:
Token Dimension a
Temperature TemperatureData{TTemperature.value = Just to,
TTemperature.unit = Just u}:
[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 -> Token)
-> (TemperatureData -> TemperatureData) -> TemperatureData -> Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> TemperatureData -> TemperatureData
withMax Double
to (TemperatureData -> Maybe Token) -> TemperatureData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ TemperatureUnit -> TemperatureData
unitOnly TemperatureUnit
u
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleIntervalMin :: Rule
ruleIntervalMin :: Rule
ruleIntervalMin = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"over/above/at least/more than <temp>"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"дээгүүр|их|багадаа"
, Predicate -> PatternItem
Predicate Predicate
isSimpleTemperature
]
, prod :: Production
prod = \case
(Token
_:
Token Dimension a
Temperature TemperatureData{TTemperature.value = Just from,
TTemperature.unit = Just u}:
[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 -> Token)
-> (TemperatureData -> TemperatureData) -> TemperatureData -> Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> TemperatureData -> TemperatureData
withMin Double
from (TemperatureData -> Maybe Token) -> TemperatureData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ TemperatureUnit -> TemperatureData
unitOnly TemperatureUnit
u
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
rules :: [Rule]
rules :: [Rule]
rules =
[ Rule
ruleTemperatureDegrees
, Rule
ruleTemperatureCelsius
, Rule
ruleTemperatureFahrenheit
, Rule
ruleTemperatureBelowZero
, Rule
ruleTempC
, Rule
ruleIntervalMin
, Rule
ruleIntervalMax
]