{-# LANGUAGE GADTs #-}
{-# LANGUAGE OverloadedStrings #-}
module Duckling.Distance.HR.Rules
( rules ) where
import Data.String
import Prelude
import Duckling.Dimensions.Types
import Duckling.Distance.Helpers
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?(eta?r)?a?"
]
, 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
}
ruleDistMetar :: Rule
ruleDistMetar :: Rule
ruleDistMetar = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"<dist> metar"
, pattern :: Pattern
pattern =
[ Dimension DistanceData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension DistanceData
Distance
, String -> PatternItem
regex String
"metara?"
]
, 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
}
ruleDistCentimetar :: Rule
ruleDistCentimetar :: Rule
ruleDistCentimetar = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"<dist> centimetar"
, pattern :: Pattern
pattern =
[ Dimension DistanceData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension DistanceData
Distance
, String -> PatternItem
regex String
"cm|centimeta?ra?"
]
, 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
}
ruleDistMilja :: Rule
ruleDistMilja :: Rule
ruleDistMilja = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"<dist> milja"
, pattern :: Pattern
pattern =
[ Dimension DistanceData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension DistanceData
Distance
, String -> PatternItem
regex String
"milja"
]
, 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.Mile a
DistanceData
dd
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleDistMAmbiguousMilesOrMeters :: Rule
ruleDistMAmbiguousMilesOrMeters :: Rule
ruleDistMAmbiguousMilesOrMeters = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"<dist> m (ambiguous miles or meters)"
, pattern :: Pattern
pattern =
[ Dimension DistanceData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension DistanceData
Distance
, String -> PatternItem
regex String
"m"
]
, 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.M a
DistanceData
dd
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
rules :: [Rule]
rules :: [Rule]
rules =
[ Rule
ruleDistCentimetar
, Rule
ruleDistMAmbiguousMilesOrMeters
, Rule
ruleDistMetar
, Rule
ruleDistMilja
, Rule
ruleLatentDistKm
]