{-# LANGUAGE GADTs #-}
{-# LANGUAGE OverloadedStrings #-}
module Duckling.Distance.Rules
( rules
) where
import Data.String
import Prelude
import Duckling.Dimensions.Types
import Duckling.Distance.Helpers
import Duckling.Numeral.Types (NumeralData (..))
import Duckling.Types
import qualified Duckling.Numeral.Types as TNumeral
ruleNumeralAsDistance :: Rule
ruleNumeralAsDistance :: Rule
ruleNumeralAsDistance = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"number as distance"
, pattern :: Pattern
pattern =
[ Dimension NumeralData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension NumeralData
Numeral
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(Token Dimension a
Numeral NumeralData {TNumeral.value = v}:[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
$ Double -> DistanceData
distance Double
v
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
rules :: [Rule]
rules :: [Rule]
rules =
[ Rule
ruleNumeralAsDistance
]