-- 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.BG.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 = [ (" km", "км|километ(ра|ри|ър)", TDistance.Kilometre) , (" feet", "('|фут(а|ове)?)", TDistance.Foot) , (" inch", "(\"|''|инч(а|ове)?)", TDistance.Inch) , (" yard", "ярд(а|ове)?", TDistance.Yard) , (" meters", "м(етър|етр(а|и))?", TDistance.Metre) , (" centimeters", "см|сантимет(ри|ра|ър)", TDistance.Centimetre) , (" millimeters", "мм|милимет(ра|ри|ър)", TDistance.Millimetre) , (" miles", "мил(я|и)", TDistance.Mile) ] ruleDistances :: [Rule] ruleDistances = map go distances where go :: (Text, String, TDistance.Unit) -> Rule go (name, regexPattern, u) = Rule { name = name , pattern = [ dimension Distance, regex regexPattern ] , prod = \tokens -> case tokens of (Token Distance dd:_) -> Just . Token Distance $ withUnit u dd _ -> Nothing } rules :: [Rule] rules = ruleDistances