mirror of
https://github.com/facebook/duckling.git
synced 2024-09-11 21:27:13 +03:00
Added support for parsing new ES duration phrases like half hour, quarter of hour. (#489)
Summary: Pull Request resolved: https://github.com/facebook/duckling/pull/489 Differential Revision: D21959268 Pulled By: chinmay87 fbshipit-source-id: 2b785b44da5437c7b27af098daef551139dad990
This commit is contained in:
parent
0cfd8102da
commit
220c0f2d7d
48
Duckling/Duration/ES/Corpus.hs
Normal file
48
Duckling/Duration/ES/Corpus.hs
Normal file
@ -0,0 +1,48 @@
|
||||
-- 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 OverloadedStrings #-}
|
||||
|
||||
module Duckling.Duration.ES.Corpus
|
||||
( corpus
|
||||
) where
|
||||
|
||||
import Prelude
|
||||
import Data.String
|
||||
|
||||
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 ES Nothing}, testOptions, allExamples)
|
||||
|
||||
allExamples :: [Example]
|
||||
allExamples = concat
|
||||
[ examples (DurationData 30 Minute)
|
||||
[ "media hora"
|
||||
, "media horas"
|
||||
, "30 minutos"
|
||||
, "treinta minutos"
|
||||
]
|
||||
, examples (DurationData 15 Minute)
|
||||
[ "cuarto de hora"
|
||||
, "cuartos de hora"
|
||||
, "quince minutos"
|
||||
, "15 minutos"
|
||||
]
|
||||
, examples (DurationData 45 Minute)
|
||||
[ "tres cuartos de hora"
|
||||
, "tres cuartos de horas"
|
||||
, "tres cuarto de hora"
|
||||
, "tres cuarto de horas"
|
||||
, "cuarenta y cinco minutos"
|
||||
, "45 minutos"
|
||||
]
|
||||
]
|
54
Duckling/Duration/ES/Rules.hs
Normal file
54
Duckling/Duration/ES/Rules.hs
Normal file
@ -0,0 +1,54 @@
|
||||
-- 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 NoRebindableSyntax #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Duckling.Duration.ES.Rules
|
||||
( rules
|
||||
) where
|
||||
|
||||
import Duckling.Duration.Helpers
|
||||
import Data.Maybe
|
||||
import Duckling.Types
|
||||
import qualified Duckling.TimeGrain.Types as TG
|
||||
import Prelude
|
||||
|
||||
ruleDurationQuarterOfAnHour :: Rule
|
||||
ruleDurationQuarterOfAnHour = Rule
|
||||
{ name = "quarter of an hour"
|
||||
, pattern =
|
||||
[ regex "cuartos? de hora"
|
||||
]
|
||||
, prod = \_ -> Just $ Token Duration $ duration TG.Minute 15
|
||||
}
|
||||
|
||||
ruleDurationHalfOfAnHour :: Rule
|
||||
ruleDurationHalfOfAnHour = Rule
|
||||
{ name = "half of an hour"
|
||||
, pattern =
|
||||
[ regex "media horas?"
|
||||
]
|
||||
, prod = \_ -> Just $ Token Duration $ duration TG.Minute 30
|
||||
}
|
||||
|
||||
ruleDurationThreeQuartersOfAnHour :: Rule
|
||||
ruleDurationThreeQuartersOfAnHour = Rule
|
||||
{ name = "three-quarters of an hour"
|
||||
, pattern =
|
||||
[ regex "tres cuartos? de horas?"
|
||||
]
|
||||
, prod = \_ -> Just $ Token Duration $ duration TG.Minute 45
|
||||
}
|
||||
|
||||
rules :: [Rule]
|
||||
rules =
|
||||
[ ruleDurationHalfOfAnHour
|
||||
, ruleDurationQuarterOfAnHour
|
||||
, ruleDurationThreeQuartersOfAnHour
|
||||
]
|
@ -38,6 +38,7 @@ import qualified Duckling.Time.ES.Rules as Time
|
||||
import qualified Duckling.TimeGrain.ES.Rules as TimeGrain
|
||||
import Duckling.Types
|
||||
import qualified Duckling.Volume.ES.Rules as Volume
|
||||
import qualified Duckling.Duration.ES.Rules as Duration
|
||||
|
||||
defaultRules :: Some Dimension -> [Rule]
|
||||
defaultRules dim@(This Numeral) =
|
||||
@ -59,7 +60,7 @@ langRules :: Some Dimension -> [Rule]
|
||||
langRules (This AmountOfMoney) = AmountOfMoney.rules
|
||||
langRules (This CreditCardNumber) = []
|
||||
langRules (This Distance) = Distance.rules
|
||||
langRules (This Duration) = []
|
||||
langRules (This Duration) = Duration.rules
|
||||
langRules (This Email) = []
|
||||
langRules (This Numeral) = Numeral.rules
|
||||
langRules (This Ordinal) = Ordinal.rules
|
||||
|
@ -335,6 +335,8 @@ library
|
||||
, Duckling.Duration.EL.Rules
|
||||
, Duckling.Duration.EN.Corpus
|
||||
, Duckling.Duration.EN.Rules
|
||||
, Duckling.Duration.ES.Corpus
|
||||
, Duckling.Duration.ES.Rules
|
||||
, Duckling.Duration.FR.Corpus
|
||||
, Duckling.Duration.FR.Rules
|
||||
, Duckling.Duration.GA.Corpus
|
||||
@ -917,6 +919,7 @@ test-suite duckling-test
|
||||
, Duckling.Duration.BG.Tests
|
||||
, Duckling.Duration.EL.Tests
|
||||
, Duckling.Duration.EN.Tests
|
||||
, Duckling.Duration.ES.Tests
|
||||
, Duckling.Duration.FR.Tests
|
||||
, Duckling.Duration.GA.Tests
|
||||
, Duckling.Duration.HU.Tests
|
||||
|
16
tests/Duckling/Duration/ES/Tests.hs
Normal file
16
tests/Duckling/Duration/ES/Tests.hs
Normal file
@ -0,0 +1,16 @@
|
||||
module Duckling.Duration.ES.Tests
|
||||
( tests
|
||||
) where
|
||||
|
||||
import Prelude
|
||||
import Data.String
|
||||
import Test.Tasty
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Duration.ES.Corpus
|
||||
import Duckling.Testing.Asserts
|
||||
|
||||
tests :: TestTree
|
||||
tests = testGroup "ES Tests"
|
||||
[ makeCorpusTest [This Duration] corpus
|
||||
]
|
@ -17,6 +17,7 @@ import qualified Duckling.Duration.AR.Tests as AR
|
||||
import qualified Duckling.Duration.BG.Tests as BG
|
||||
import qualified Duckling.Duration.EL.Tests as EL
|
||||
import qualified Duckling.Duration.EN.Tests as EN
|
||||
import qualified Duckling.Duration.ES.Tests as ES
|
||||
import qualified Duckling.Duration.FR.Tests as FR
|
||||
import qualified Duckling.Duration.GA.Tests as GA
|
||||
import qualified Duckling.Duration.HI.Tests as HI
|
||||
@ -42,6 +43,7 @@ tests = testGroup "Duration Tests"
|
||||
, BG.tests
|
||||
, EL.tests
|
||||
, EN.tests
|
||||
, ES.tests
|
||||
, FR.tests
|
||||
, GA.tests
|
||||
, HI.tests
|
||||
|
Loading…
Reference in New Issue
Block a user