mirror of
https://github.com/facebook/duckling.git
synced 2024-09-11 21:27:13 +03:00
Added Duration support to Hindi (HI)
Summary: Hello! I have added __Hindi (HI)__ support for the __Duration__ dimension in ```Duckling/Duration/Rules.hs```. Written tests as well in ```Duckling/Duration/Corpus.hs``` and everything is passing and verified (`253 tests passed`). Cheers! Closes https://github.com/facebook/duckling/pull/194 Reviewed By: patapizza Differential Revision: D7999571 Pulled By: chinmay87 fbshipit-source-id: deb5d60ba7f7ecbc2aa4d97ce5fb96e9bbe63b3d
This commit is contained in:
parent
9f2fffec23
commit
8237ef4503
@ -14,6 +14,7 @@ import Duckling.Dimensions.Types
|
||||
|
||||
allDimensions :: [Some Dimension]
|
||||
allDimensions =
|
||||
[ This Numeral
|
||||
[ This Duration
|
||||
, This Numeral
|
||||
, This Ordinal
|
||||
]
|
||||
|
49
Duckling/Duration/HI/Corpus.hs
Normal file
49
Duckling/Duration/HI/Corpus.hs
Normal file
@ -0,0 +1,49 @@
|
||||
-- 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 OverloadedStrings #-}
|
||||
|
||||
module Duckling.Duration.HI.Corpus
|
||||
( corpus
|
||||
) where
|
||||
|
||||
import Data.String
|
||||
import Prelude
|
||||
|
||||
import Duckling.Duration.Types
|
||||
import Duckling.Locale
|
||||
import Duckling.Resolve
|
||||
import Duckling.Testing.Types
|
||||
import Duckling.TimeGrain.Types (Grain(..))
|
||||
|
||||
corpus :: Corpus
|
||||
corpus = (testContext {locale = makeLocale HI Nothing}, testOptions, allExamples)
|
||||
|
||||
allExamples :: [Example]
|
||||
allExamples = concat
|
||||
[ examples (DurationData 15 Minute)
|
||||
[ "पंद्रह मिनट"
|
||||
, "लगभग पंद्रह मिनट"
|
||||
]
|
||||
, examples (DurationData 30 Minute)
|
||||
[ "आधा घंटा"
|
||||
]
|
||||
, examples (DurationData 1 Day)
|
||||
[ "दिवस"
|
||||
, "एक दिन"
|
||||
]
|
||||
, examples (DurationData 14 Day)
|
||||
[ "पखवाड़ा"
|
||||
, "एक पखवाड़ा"
|
||||
]
|
||||
, examples (DurationData 1 Year)
|
||||
[ "एक साल"
|
||||
, "केवल एक वर्ष"
|
||||
, "लगभग एक साल"
|
||||
]
|
||||
]
|
114
Duckling/Duration/HI/Rules.hs
Normal file
114
Duckling/Duration/HI/Rules.hs
Normal file
@ -0,0 +1,114 @@
|
||||
-- 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.Duration.HI.Rules
|
||||
( rules
|
||||
) where
|
||||
|
||||
import Control.Monad (join)
|
||||
import Data.String
|
||||
import Data.HashMap.Strict (HashMap)
|
||||
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.Duration.Helpers
|
||||
import Duckling.Numeral.Helpers (parseInteger)
|
||||
import Duckling.Numeral.Types (NumeralData (..))
|
||||
import Duckling.Regex.Types
|
||||
import Duckling.Types
|
||||
import qualified Duckling.Numeral.Types as TNumeral
|
||||
import qualified Duckling.TimeGrain.Types as TG
|
||||
|
||||
avadhiMap :: HashMap Text TG.Grain
|
||||
avadhiMap = HashMap.fromList
|
||||
[ ("मिनट" , TG.Minute)
|
||||
, ("घंटा" , TG.Hour)
|
||||
, ("दिवस" , TG.Day)
|
||||
, ("दिन" , TG.Day)
|
||||
, ("महीना", TG.Month)
|
||||
, ("वर्ष" , TG.Year)
|
||||
, ("साल" , TG.Year)
|
||||
]
|
||||
|
||||
ruleAadha :: Rule
|
||||
ruleAadha = Rule
|
||||
{ name = "half of a duration"
|
||||
, pattern =
|
||||
[ regex "आधा ((साल|वर्ष)|(महीना)|(दिन|दिवस)|(घंटा)|(मिनट))"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token RegexMatch (GroupMatch (x:_)):_) -> do
|
||||
grain <- HashMap.lookup (Text.toLower x) avadhiMap
|
||||
Token Duration <$> timesOneAndAHalf grain 0
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleDurationPandrahMinat :: Rule
|
||||
ruleDurationPandrahMinat = Rule
|
||||
{ name = "quarter of an hour"
|
||||
, pattern =
|
||||
[ regex "पंद्रह मिनट"
|
||||
]
|
||||
, prod = \_ -> Just . Token Duration $ duration TG.Minute 15
|
||||
}
|
||||
|
||||
ruleDurationPakhwaada :: Rule
|
||||
ruleDurationPakhwaada = Rule
|
||||
{ name = "fortnight"
|
||||
, pattern =
|
||||
[ regex "((एक पखवाड़ा)|(पखवाड़ा))"
|
||||
]
|
||||
, prod = \_ -> Just . Token Duration $ duration TG.Day 14
|
||||
}
|
||||
|
||||
ruleDurationDin :: Rule
|
||||
ruleDurationDin = Rule
|
||||
{ name = "a day"
|
||||
, pattern =
|
||||
[ regex "((एक दिन)|(एक दिवस)|(दिन|दिवस))"
|
||||
]
|
||||
, prod = \_ -> Just . Token Duration $ duration TG.Day 1
|
||||
}
|
||||
|
||||
ruleDurationEkSaal :: Rule
|
||||
ruleDurationEkSaal = Rule
|
||||
{ name = "one year"
|
||||
, pattern =
|
||||
[ regex "एक (साल|वर्ष)"
|
||||
]
|
||||
, prod = \_ -> Just . Token Duration $ duration TG.Year 1
|
||||
}
|
||||
|
||||
ruleDurationPreciseImprecise :: Rule
|
||||
ruleDurationPreciseImprecise = Rule
|
||||
{ name = "about|exactly <duration>"
|
||||
, pattern =
|
||||
[ regex "(लगभग|बिल्कुल|केवल)"
|
||||
, dimension Duration
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(_:token:_) -> Just token
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
|
||||
rules :: [Rule]
|
||||
rules =
|
||||
[ ruleDurationPandrahMinat
|
||||
, ruleDurationPakhwaada
|
||||
, ruleDurationDin
|
||||
, ruleAadha
|
||||
, ruleDurationEkSaal
|
||||
, ruleDurationPreciseImprecise
|
||||
]
|
@ -19,6 +19,7 @@ import Duckling.Locale
|
||||
import Duckling.Types
|
||||
import qualified Duckling.Numeral.HI.Rules as Numeral
|
||||
import qualified Duckling.Ordinal.HI.Rules as Ordinal
|
||||
import qualified Duckling.Duration.HI.Rules as Duration
|
||||
|
||||
defaultRules :: Some Dimension -> [Rule]
|
||||
defaultRules = langRules
|
||||
@ -30,7 +31,7 @@ localeRules _ _ = []
|
||||
langRules :: Some Dimension -> [Rule]
|
||||
langRules (This AmountOfMoney) = []
|
||||
langRules (This Distance) = []
|
||||
langRules (This Duration) = []
|
||||
langRules (This Duration) = Duration.rules
|
||||
langRules (This Numeral) = Numeral.rules
|
||||
langRules (This Email) = []
|
||||
langRules (This Ordinal) = Ordinal.rules
|
||||
|
@ -259,6 +259,8 @@ library
|
||||
, Duckling.Duration.GA.Corpus
|
||||
, Duckling.Duration.GA.Rules
|
||||
, Duckling.Duration.HE.Rules
|
||||
, Duckling.Duration.HI.Corpus
|
||||
, Duckling.Duration.HI.Rules
|
||||
, Duckling.Duration.HR.Rules
|
||||
, Duckling.Duration.HU.Corpus
|
||||
, Duckling.Duration.HU.Rules
|
||||
@ -729,6 +731,7 @@ test-suite duckling-test
|
||||
, Duckling.Duration.FR.Tests
|
||||
, Duckling.Duration.GA.Tests
|
||||
, Duckling.Duration.HU.Tests
|
||||
, Duckling.Duration.HI.Tests
|
||||
, Duckling.Duration.JA.Tests
|
||||
, Duckling.Duration.KO.Tests
|
||||
, Duckling.Duration.NB.Tests
|
||||
|
24
tests/Duckling/Duration/HI/Tests.hs
Normal file
24
tests/Duckling/Duration/HI/Tests.hs
Normal file
@ -0,0 +1,24 @@
|
||||
-- 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.
|
||||
|
||||
|
||||
module Duckling.Duration.HI.Tests
|
||||
( tests
|
||||
) where
|
||||
|
||||
import Data.String
|
||||
import Prelude
|
||||
import Test.Tasty
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Duration.HI.Corpus
|
||||
import Duckling.Testing.Asserts
|
||||
|
||||
tests :: TestTree
|
||||
tests = testGroup "HI Tests"
|
||||
[ makeCorpusTest [This Duration] corpus
|
||||
]
|
@ -20,6 +20,7 @@ import qualified Duckling.Duration.EL.Tests as EL
|
||||
import qualified Duckling.Duration.EN.Tests as EN
|
||||
import qualified Duckling.Duration.FR.Tests as FR
|
||||
import qualified Duckling.Duration.GA.Tests as GA
|
||||
import qualified Duckling.Duration.HI.Tests as HI
|
||||
import qualified Duckling.Duration.HU.Tests as HU
|
||||
import qualified Duckling.Duration.JA.Tests as JA
|
||||
import qualified Duckling.Duration.KO.Tests as KO
|
||||
@ -41,6 +42,7 @@ tests = testGroup "Duration Tests"
|
||||
, EN.tests
|
||||
, FR.tests
|
||||
, GA.tests
|
||||
, HI.tests
|
||||
, HU.tests
|
||||
, JA.tests
|
||||
, KO.tests
|
||||
|
Loading…
Reference in New Issue
Block a user