{-# LANGUAGE GADTs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
module Duckling.Distance.RO.Rules
( rules
) where
import Data.HashMap.Strict (HashMap)
import Data.String
import Data.Text (Text)
import Prelude
import qualified Data.HashMap.Strict as HashMap
import qualified Data.Text as Text
import Duckling.Dimensions.Types
import Duckling.Distance.Helpers
import Duckling.Regex.Types
import Duckling.Types
import qualified Duckling.Distance.Types as TDistance
unitMap :: HashMap Text TDistance.Unit
unitMap :: HashMap Text Unit
unitMap = [(Text, Unit)] -> HashMap Text Unit
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
HashMap.fromList
[ ( Text
"cm", Unit
TDistance.Centimetre )
, ( Text
"centimetri", Unit
TDistance.Centimetre )
, ( Text
"centimetru", Unit
TDistance.Centimetre )
, ( Text
"picior", Unit
TDistance.Foot )
, ( Text
"picioare", Unit
TDistance.Foot )
, ( Text
"inch", Unit
TDistance.Inch )
, ( Text
"inchi", Unit
TDistance.Inch )
, ( Text
"inci", Unit
TDistance.Inch )
, ( Text
"km", Unit
TDistance.Kilometre )
, ( Text
"kilometri", Unit
TDistance.Kilometre )
, ( Text
"kilometru", Unit
TDistance.Kilometre )
, ( Text
"m", Unit
TDistance.Metre )
, ( Text
"metri", Unit
TDistance.Metre )
, ( Text
"metru", Unit
TDistance.Metre )
, ( Text
"mila", Unit
TDistance.Mile )
, ( Text
"milă", Unit
TDistance.Mile )
, ( Text
"mile", Unit
TDistance.Mile )
, ( Text
"y", Unit
TDistance.Yard )
, ( Text
"yar", Unit
TDistance.Yard )
, ( Text
"yard", Unit
TDistance.Yard )
, ( Text
"yarzi", Unit
TDistance.Yard )
, ( Text
"yd", Unit
TDistance.Yard )
, ( Text
"yzi", Unit
TDistance.Yard )
]
ruleLatentDistUnit :: Rule
ruleLatentDistUnit :: Rule
ruleLatentDistUnit = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"<latent dist> foot/inch/yard/meter/kilometer/centimeter"
, pattern :: Pattern
pattern =
[ Dimension DistanceData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension DistanceData
Distance
, String -> PatternItem
regex String
"(inc(hi?|i)|(centi|kilo)?metr[iu]|mil[eaă]|[ck]?m|picio(are|r)|y(ar)?(zi|d)?)"
]
, prod :: Production
prod = \case
(Token Dimension a
Distance a
dd:
Token Dimension a
RegexMatch (GroupMatch (match:_)):
[Token]
_) -> do
Unit
x <- Text -> HashMap Text Unit -> Maybe Unit
forall k v. (Eq k, Hashable k) => k -> HashMap k v -> Maybe v
HashMap.lookup (Text -> Text
Text.toLower Text
match) HashMap Text Unit
unitMap
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
x a
DistanceData
dd
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleLatentDistDeUnit :: Rule
ruleLatentDistDeUnit :: Rule
ruleLatentDistDeUnit = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"<latent dist> foot/inch/yard/meter/kilometer/centimeter"
, pattern :: Pattern
pattern =
[ Dimension DistanceData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension DistanceData
Distance
, String -> PatternItem
regex String
"de (inc(hi?|i)|(centi|kilo)?metr[iu]|mil[eaă]|[ck]?m|picio(are|r)|y(ar)?(zi|d)?)"
]
, prod :: Production
prod = \case
(Token Dimension a
Distance a
dd:
Token Dimension a
RegexMatch (GroupMatch (match:_)):
[Token]
_) -> do
Unit
x <- Text -> HashMap Text Unit -> Maybe Unit
forall k v. (Eq k, Hashable k) => k -> HashMap k v -> Maybe v
HashMap.lookup (Text -> Text
Text.toLower Text
match) HashMap Text Unit
unitMap
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
x a
DistanceData
dd
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
rules :: [Rule]
rules :: [Rule]
rules =
[ Rule
ruleLatentDistUnit
, Rule
ruleLatentDistDeUnit
]