mirror of
https://github.com/facebook/duckling.git
synced 2024-12-11 06:46:26 +03:00
0527be1ce0
Summary: Adding locale rules for ES Numeral because Spain use "," as decimal but south american country use "." as decimal. Wiki: https://en.wikipedia.org/wiki/Decimal_separator Reviewed By: haoxuany Differential Revision: D20040111 fbshipit-source-id: e2a4bfc2928df19976ef98e90ee82e7d21b52313
59 lines
1.7 KiB
Haskell
59 lines
1.7 KiB
Haskell
-- 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.VE.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
|
|
]
|