-- Copyright (c) 2016-present, Facebook, Inc.
-- All rights reserved.
--
-- This source code is licensed under the BSD-style license found in the
-- LICENSE file in the root directory of this source tree.


{-# LANGUAGE GADTs #-}
{-# LANGUAGE OverloadedStrings #-}

module Duckling.Distance.MN.Rules
  ( rules
  ) where

import Data.String
import Data.Text (Text)
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

distances :: [(Text, String, TDistance.Unit)]
distances :: [(Text, String, Unit)]
distances = [ (Text
"<latent dist> km", String
"км|километр", Unit
TDistance.Kilometre)
            , (Text
"<latent dist> feet", String
"('|фут)", Unit
TDistance.Foot)
            , (Text
"<latent dist> inch", String
"(\"|''|дюйм|инч)", Unit
TDistance.Inch)
            , (Text
"<latent dist> yard", String
"яард", Unit
TDistance.Yard)
            , (Text
"<dist> meters", String
"м(етр(ийн|ээр)?)?", Unit
TDistance.Metre)
            , (Text
"<dist> centimeters", String
"см|сантиметр", Unit
TDistance.Centimetre)
            , (Text
"<dist> millimeters", String
"мм|миллиметр", Unit
TDistance.Millimetre)
            , (Text
"<dist> miles", String
"мил(и|ь)", Unit
TDistance.Mile)
            ]

ruleDistances :: [Rule]
ruleDistances :: [Rule]
ruleDistances = ((Text, String, Unit) -> Rule) -> [(Text, String, Unit)] -> [Rule]
forall a b. (a -> b) -> [a] -> [b]
map (Text, String, Unit) -> Rule
go [(Text, String, Unit)]
distances
  where
    go :: (Text, String, TDistance.Unit) -> Rule
    go :: (Text, String, Unit) -> Rule
go (Text
name, String
regexPattern, Unit
u) = Rule :: Text -> Pattern -> Production -> Rule
Rule
      { name :: Text
name = Text
name
      , pattern :: Pattern
pattern = [ Dimension DistanceData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension DistanceData
Distance, String -> PatternItem
regex String
regexPattern ]
      , 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
u a
DistanceData
dd
          [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
      }

rules :: [Rule]
rules :: [Rule]
rules = [Rule]
ruleDistances