-- 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.KO.Rules
  ( rules ) where

import Data.String
import Prelude

import Duckling.Dimensions.Types
import Duckling.Distance.Helpers
import qualified Duckling.Distance.Types as TDistance
import Duckling.Numeral.Types (NumeralData (..))
import qualified Duckling.Numeral.Types as TNumeral
import Duckling.Types

ruleLatentDistYard :: Rule
ruleLatentDistYard :: Rule
ruleLatentDistYard = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<latent dist> yard"
  , pattern :: Pattern
pattern =
    [ Dimension DistanceData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension DistanceData
Distance
    , String -> PatternItem
regex String
"y(ar)?ds?|야드"
    ]
  , 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.Yard 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|센(티|치)((미|메)터)?"
    ]
  , 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
  }

ruleLatentDistFeetAndLatentDistInch :: Rule
ruleLatentDistFeetAndLatentDistInch :: Rule
ruleLatentDistFeetAndLatentDistInch = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<latent dist> feet and <latent dist> inch "
  , pattern :: Pattern
pattern =
    [ Dimension DistanceData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension DistanceData
Distance
    , String -> PatternItem
regex String
"('|f(oo|ee)?ts?)|피트"
    , Dimension DistanceData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension DistanceData
Distance
    , String -> PatternItem
regex String
"(''|inch(es)?)|인치"
    ]
  , 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.Foot 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> 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.Metre a
DistanceData
dd
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleLatentDistFeet :: Rule
ruleLatentDistFeet :: Rule
ruleLatentDistFeet = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<latent dist> feet"
  , pattern :: Pattern
pattern =
    [ Dimension DistanceData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension DistanceData
Distance
    , String -> PatternItem
regex String
"('|f(oo|ee)?ts?)|피트"
    ]
  , 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.Foot a
DistanceData
dd
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

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
"km|(킬|키)로((미|메)터)?"
    ]
  , 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
  }

ruleHalf :: Rule
ruleHalf :: Rule
ruleHalf = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"half"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"반"
    ]
  , 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
  }

ruleDistMiles :: Rule
ruleDistMiles :: Rule
ruleDistMiles = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<dist> miles"
  , pattern :: Pattern
pattern =
    [ Dimension DistanceData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension DistanceData
Distance
    , String -> PatternItem
regex String
"miles?|마일(즈)?"
    ]
  , 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
  }

ruleLatentDistInch :: Rule
ruleLatentDistInch :: Rule
ruleLatentDistInch = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<latent dist> inch"
  , pattern :: Pattern
pattern =
    [ Dimension DistanceData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension DistanceData
Distance
    , String -> PatternItem
regex String
"(''|inch(es)?)|인치"
    ]
  , 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.Inch a
DistanceData
dd
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

rules :: [Rule]
rules :: [Rule]
rules =
  [ Rule
ruleDistCentimeters
  , Rule
ruleDistMeters
  , Rule
ruleDistMiles
  , Rule
ruleHalf
  , Rule
ruleLatentDistFeet
  , Rule
ruleLatentDistFeetAndLatentDistInch
  , Rule
ruleLatentDistInch
  , Rule
ruleLatentDistKm
  , Rule
ruleLatentDistYard
  ]