-- 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.Numeral.ES.AR.Rules (rules) where import Data.Maybe import Data.String import qualified Data.Text as Text import Prelude import Duckling.Dimensions.Types import Duckling.Numeral.Helpers import Duckling.Regex.Types import Duckling.Types ruleDecimalWithThousandsSeparator :: Rule ruleDecimalWithThousandsSeparator = Rule { name = "decimal with thousands separator ." , pattern = [regex "(\\d+(\\.\\d\\d\\d)+,\\d+)"] , prod = \tokens -> case tokens of (Token RegexMatch (GroupMatch (match : _)) : _) -> let fmt = Text.replace "," "." $ Text.replace "." Text.empty match in parseDouble fmt >>= double _ -> Nothing } ruleDecimalNumeral :: Rule ruleDecimalNumeral = Rule { name = "decimal number ," , pattern = [regex "(\\d*,\\d+)"] , prod = \tokens -> case tokens of (Token RegexMatch (GroupMatch (match : _)) : _) -> parseDecimal False match _ -> Nothing } ruleIntegerWithThousandsSeparator :: Rule ruleIntegerWithThousandsSeparator = Rule { name = "integer with thousands separator ." , pattern = [regex "(\\d{1,3}(\\.\\d\\d\\d){1,5})"] , prod = \tokens -> case tokens of (Token RegexMatch (GroupMatch (match : _)) : _) -> parseDouble (Text.replace "." Text.empty match) >>= double _ -> Nothing } rules :: [Rule] rules = [ ruleDecimalNumeral , ruleDecimalWithThousandsSeparator , ruleIntegerWithThousandsSeparator ]