{-# LANGUAGE GADTs #-}
{-# LANGUAGE OverloadedStrings #-}
module Duckling.Distance.SV.Rules
( rules
) where
import Data.String
import Prelude
import Duckling.Dimensions.Types
import Duckling.Distance.Helpers
import Duckling.Distance.Types (DistanceData(..))
import Duckling.Types
import qualified Duckling.Distance.Types as TDistance
ruleLatentDistKm :: Rule
ruleLatentDistKm :: Rule
ruleLatentDistKm = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"<latent dist> km"
, pattern :: Pattern
pattern =
[ Dimension DistanceData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension DistanceData
Distance
, String -> PatternItem
regex String
"k(ilo)?m?(eter)?"
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(Token Dimension a
Distance a
dd:[Token]
_) ->
Token -> Maybe Token
forall a. a -> Maybe a
Just (Token -> Maybe Token)
-> (DistanceData -> Token) -> DistanceData -> Maybe Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Dimension DistanceData -> DistanceData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension DistanceData
Distance (DistanceData -> Maybe Token) -> DistanceData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Unit -> DistanceData -> DistanceData
withUnit Unit
TDistance.Kilometre a
DistanceData
dd
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleDistMeters :: Rule
ruleDistMeters :: Rule
ruleDistMeters = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"<dist> meter"
, pattern :: Pattern
pattern =
[ Dimension DistanceData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension DistanceData
Distance
, String -> PatternItem
regex String
"m(eter)?"
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(Token Dimension a
Distance a
dd:[Token]
_) ->
Token -> Maybe Token
forall a. a -> Maybe a
Just (Token -> Maybe Token)
-> (DistanceData -> Token) -> DistanceData -> Maybe Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Dimension DistanceData -> DistanceData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension DistanceData
Distance (DistanceData -> Maybe Token) -> DistanceData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Unit -> DistanceData -> DistanceData
withUnit Unit
TDistance.Metre a
DistanceData
dd
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleDistCentimeters :: Rule
ruleDistCentimeters :: Rule
ruleDistCentimeters = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"<dist> centimeters"
, pattern :: Pattern
pattern =
[ Dimension DistanceData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension DistanceData
Distance
, String -> PatternItem
regex String
"cm|centimeter"
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(Token Dimension a
Distance a
dd:[Token]
_) ->
Token -> Maybe Token
forall a. a -> Maybe a
Just (Token -> Maybe Token)
-> (DistanceData -> Token) -> DistanceData -> Maybe Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Dimension DistanceData -> DistanceData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension DistanceData
Distance (DistanceData -> Maybe Token) -> DistanceData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Unit -> DistanceData -> DistanceData
withUnit Unit
TDistance.Centimetre a
DistanceData
dd
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleDistMils :: Rule
ruleDistMils :: Rule
ruleDistMils = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"<dist> mils"
, pattern :: Pattern
pattern =
[ Dimension DistanceData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension DistanceData
Distance
, String -> PatternItem
regex String
"mils?"
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(Token Dimension a
Distance dd :: a
dd@DistanceData {TDistance.value = Just x}:[Token]
_) ->
Token -> Maybe Token
forall a. a -> Maybe a
Just (Token -> Maybe Token)
-> (DistanceData -> Token) -> DistanceData -> Maybe Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Dimension DistanceData -> DistanceData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension DistanceData
Distance (DistanceData -> Token)
-> (DistanceData -> DistanceData) -> DistanceData -> Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> DistanceData -> DistanceData
withValue (Double
10 Double -> Double -> Double
forall a. Num a => a -> a -> a
* Double
x)
(DistanceData -> Maybe Token) -> DistanceData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Unit -> DistanceData -> DistanceData
withUnit Unit
TDistance.Kilometre a
DistanceData
dd
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
rules :: [Rule]
rules :: [Rule]
rules =
[ Rule
ruleDistCentimeters
, Rule
ruleDistMeters
, Rule
ruleDistMils
, Rule
ruleLatentDistKm
]