mirror of
https://github.com/facebook/duckling.git
synced 2024-12-11 06:46:26 +03:00
6df3b26707
Summary: * `ruleIntegerNumeric` was used in all languages but Burmese. * it seems like the hindu-arabic numerals are slowly getting in Burmese (e.g. recent car plates) * Moving the rule in `Duckling/Numeral/Common.hs` Reviewed By: blandinw Differential Revision: D6498349 fbshipit-source-id: e868dc9960f18f0781e4aa98a0dfcd14969537c9
65 lines
1.6 KiB
Haskell
65 lines
1.6 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. An additional grant
|
|
-- of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
|
|
{-# LANGUAGE GADTs #-}
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
module Duckling.Numeral.CS.Rules
|
|
( rules
|
|
) where
|
|
|
|
import Data.HashMap.Strict (HashMap)
|
|
import Data.Maybe
|
|
import Data.String
|
|
import Data.Text (Text)
|
|
import Prelude
|
|
import qualified Data.HashMap.Strict as HashMap
|
|
import qualified Data.Text as Text
|
|
|
|
import Duckling.Dimensions.Types
|
|
import Duckling.Numeral.Helpers
|
|
import Duckling.Numeral.Types (NumeralData (..))
|
|
import Duckling.Regex.Types
|
|
import Duckling.Types
|
|
import qualified Duckling.Numeral.Types as TNumeral
|
|
|
|
ruleNumeralMap :: HashMap Text Integer
|
|
ruleNumeralMap = HashMap.fromList
|
|
[ ( "nula", 0 )
|
|
, ( "jeden", 1 )
|
|
, ( "jedna", 1 )
|
|
, ( "jedno", 1 )
|
|
, ( "dva", 2 )
|
|
, ( "dv\x0115", 2 )
|
|
, ( "t\x0159i", 3 )
|
|
, ( "čty\x0159i", 4 )
|
|
, ( "p\x0115t", 5)
|
|
, ( "šest", 6)
|
|
, ( "sedm", 7)
|
|
, ( "osm", 8)
|
|
, ( "dev\x0115t", 9)
|
|
, ( "deset", 10)
|
|
]
|
|
|
|
ruleNumeral :: Rule
|
|
ruleNumeral = Rule
|
|
{ name = "number (0..10)"
|
|
, pattern =
|
|
[ regex "(nula|jed(en|n[ao])|dv(a|\x0115)|t(\x0159)i|(č)ty(\x0159)i|p(\x0115)t|(š)est|sedm|osm|dev(\x0115)t|deset)"
|
|
]
|
|
, prod = \tokens -> case tokens of
|
|
(Token RegexMatch (GroupMatch (match:_)):_) ->
|
|
HashMap.lookup (Text.toLower match) ruleNumeralMap >>= integer
|
|
_ -> Nothing
|
|
}
|
|
|
|
rules :: [Rule]
|
|
rules =
|
|
[ ruleNumeral
|
|
]
|