-- 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.KA.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 [ ( "ნული", 0 ) , ( "ერთი", 1 ) , ( "ორი", 2 ) , ( "სამი", 3 ) , ( "ოთხი", 4 ) , ( "ხუთი", 5) , ( "ექვსი", 6) , ( "შვიდი", 7) , ( "რვა", 8) , ( "ცხრა", 9) , ( "ათი", 10) ] ruleNumeral :: Rule ruleNumeral = Rule { name = "number (0..10)" , pattern = [ regex "(ნული|ერთი|ორი|სამი|ოთხი|ხუთი|ექვსი|შვიდი|რვა|ცხრა|ათი)" ] , prod = \tokens -> case tokens of (Token RegexMatch (GroupMatch (match:_)):_) -> HashMap.lookup (Text.toLower match) ruleNumeralMap >>= integer _ -> Nothing } rules :: [Rule] rules = [ ruleNumeral ]