content: -- 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.CA.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.Types
  
  ruleLatentDistKm :: Rule
  ruleLatentDistKm = Rule
    { name = "<latent dist> km"
    , pattern =
      [ dimension Distance
      , regex "(k|qu)(il(o|ò|ó))?m?(etre)?s?"
      ]
    , prod = \tokens -> case tokens of
        (Token Distance dd:_) ->
          Just $ Token Distance $ withUnit TDistance.Kilometre dd
        _ -> Nothing
    }
  
  ruleDistMeters :: Rule
  ruleDistMeters = Rule
    { name = "<dist> meters"
    , pattern =
      [ dimension Distance
      , regex "m(etres?)?"
      ]
    , prod = \tokens -> case tokens of
        (Token Distance dd:_) ->
          Just $ Token Distance $ withUnit TDistance.Metre dd
        _ -> Nothing
    }
  
  ruleDistCentimeters :: Rule
  ruleDistCentimeters = Rule
    { name = "<dist> centimeters"
    , pattern =
      [ dimension Distance
      , regex "(cm|cent(í|i)m(etres?))"
      ]
    , prod = \tokens -> case tokens of
        (Token Distance dd:_) ->
          Just $ Token Distance $ withUnit TDistance.Centimetre dd
        _ -> Nothing
    }
  
  ruleDistMiles :: Rule
  ruleDistMiles = Rule
    { name = "<dist> miles"
    , pattern =
      [ dimension Distance
      , regex "milles?"
      ]
    , prod = \tokens -> case tokens of
        (Token Distance dd:_) ->
          Just $ Token Distance $ withUnit TDistance.Mile dd
        _ -> Nothing
    }
  
  rules :: [Rule]
  rules =
    [ ruleDistCentimeters
    , ruleDistMeters
    , ruleDistMiles
    , ruleLatentDistKm
    ]
  