mirror of
https://github.com/facebook/duckling.git
synced 2024-11-24 15:43:20 +03:00
Quantity for Croatian
Summary: Quantity dimension for Croatian. Reviewed By: niteria Differential Revision: D4958501 fbshipit-source-id: b90c8f6
This commit is contained in:
parent
0372f4f3da
commit
3cc3266e28
@ -18,6 +18,7 @@ allDimensions =
|
||||
, This Duration
|
||||
, This Numeral
|
||||
, This Ordinal
|
||||
, This Quantity
|
||||
, This Time
|
||||
, This Volume
|
||||
]
|
||||
|
33
Duckling/Quantity/HR/Corpus.hs
Normal file
33
Duckling/Quantity/HR/Corpus.hs
Normal file
@ -0,0 +1,33 @@
|
||||
-- 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.Quantity.HR.Corpus
|
||||
( corpus ) where
|
||||
|
||||
import Prelude
|
||||
import Data.String
|
||||
|
||||
import Duckling.Lang
|
||||
import Duckling.Quantity.Types
|
||||
import Duckling.Resolve
|
||||
import Duckling.Testing.Types
|
||||
|
||||
corpus :: Corpus
|
||||
corpus = (testContext {lang = HR}, allExamples)
|
||||
|
||||
allExamples :: [Example]
|
||||
allExamples = concat
|
||||
[ examples (QuantityData Gram 2000 (Just "meso"))
|
||||
[ "dvije kile mesa"
|
||||
, "dva kilograma mesa"
|
||||
]
|
||||
, examples (QuantityData Gram 1000 Nothing)
|
||||
[ "1 kilograma"
|
||||
]
|
||||
]
|
62
Duckling/Quantity/HR/Rules.hs
Normal file
62
Duckling/Quantity/HR/Rules.hs
Normal file
@ -0,0 +1,62 @@
|
||||
-- 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.Quantity.HR.Rules
|
||||
( rules ) where
|
||||
|
||||
import Data.String
|
||||
import Prelude
|
||||
import qualified Data.Text as Text
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Numeral.Types (NumeralData (..))
|
||||
import Duckling.Quantity.Helpers
|
||||
import Duckling.Regex.Types
|
||||
import Duckling.Types
|
||||
import qualified Duckling.Numeral.Types as TNumeral
|
||||
import qualified Duckling.Quantity.Types as TQuantity
|
||||
|
||||
ruleNumberUnits :: Rule
|
||||
ruleNumberUnits = Rule
|
||||
{ name = "<number> <units>"
|
||||
, pattern =
|
||||
[ dimension Numeral
|
||||
, regex "k(il(o|e|a))?(g(rama?)?)?"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Numeral NumeralData {TNumeral.value = v}:_) ->
|
||||
Just . Token Quantity $ quantity TQuantity.Gram (1000 * v)
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleQuantityProduct :: Rule
|
||||
ruleQuantityProduct = Rule
|
||||
{ name = "<quantity> product"
|
||||
, pattern =
|
||||
[ dimension Quantity
|
||||
, regex "(mes(o|a)|soli?)"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Quantity qd:
|
||||
Token RegexMatch (GroupMatch (match:_)):
|
||||
_) -> case Text.toLower match of
|
||||
"meso" -> Just . Token Quantity $ withProduct "meso" qd
|
||||
"mesa" -> Just . Token Quantity $ withProduct "meso" qd
|
||||
"sol" -> Just . Token Quantity $ withProduct "sol" qd
|
||||
"soli" -> Just . Token Quantity $ withProduct "sol" qd
|
||||
_ -> Nothing
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
rules :: [Rule]
|
||||
rules =
|
||||
[ ruleNumberUnits
|
||||
, ruleQuantityProduct
|
||||
]
|
@ -20,6 +20,7 @@ import qualified Duckling.Distance.HR.Rules as Distance
|
||||
import qualified Duckling.Duration.HR.Rules as Duration
|
||||
import qualified Duckling.Numeral.HR.Rules as Numeral
|
||||
import qualified Duckling.Ordinal.HR.Rules as Ordinal
|
||||
import qualified Duckling.Quantity.HR.Rules as Quantity
|
||||
import qualified Duckling.Time.HR.Rules as Time
|
||||
import qualified Duckling.TimeGrain.HR.Rules as TimeGrain
|
||||
import qualified Duckling.Volume.HR.Rules as Volume
|
||||
@ -32,7 +33,7 @@ rules (This Email) = []
|
||||
rules (This AmountOfMoney) = AmountOfMoney.rules
|
||||
rules (This Ordinal) = Ordinal.rules
|
||||
rules (This PhoneNumber) = []
|
||||
rules (This Quantity) = []
|
||||
rules (This Quantity) = Quantity.rules
|
||||
rules (This RegexMatch) = []
|
||||
rules (This Temperature) = []
|
||||
rules (This Time) = Time.rules
|
||||
|
@ -340,6 +340,8 @@ library
|
||||
, Duckling.Quantity.EN.Rules
|
||||
, Duckling.Quantity.FR.Corpus
|
||||
, Duckling.Quantity.FR.Rules
|
||||
, Duckling.Quantity.HR.Corpus
|
||||
, Duckling.Quantity.HR.Rules
|
||||
, Duckling.Quantity.KO.Corpus
|
||||
, Duckling.Quantity.KO.Rules
|
||||
, Duckling.Quantity.PT.Corpus
|
||||
@ -627,6 +629,7 @@ test-suite duckling-test
|
||||
-- Quantity
|
||||
, Duckling.Quantity.EN.Tests
|
||||
, Duckling.Quantity.FR.Tests
|
||||
, Duckling.Quantity.HR.Tests
|
||||
, Duckling.Quantity.KO.Tests
|
||||
, Duckling.Quantity.PT.Tests
|
||||
, Duckling.Quantity.RO.Tests
|
||||
|
22
tests/Duckling/Quantity/HR/Tests.hs
Normal file
22
tests/Duckling/Quantity/HR/Tests.hs
Normal file
@ -0,0 +1,22 @@
|
||||
-- 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.Quantity.HR.Tests
|
||||
( tests ) where
|
||||
|
||||
import Data.String
|
||||
import Prelude
|
||||
import Test.Tasty
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Quantity.HR.Corpus
|
||||
import Duckling.Testing.Asserts
|
||||
|
||||
tests :: TestTree
|
||||
tests = testGroup "HR Tests"
|
||||
[ makeCorpusTest [This Quantity] corpus
|
||||
]
|
@ -14,6 +14,7 @@ import Test.Tasty
|
||||
|
||||
import qualified Duckling.Quantity.EN.Tests as EN
|
||||
import qualified Duckling.Quantity.FR.Tests as FR
|
||||
import qualified Duckling.Quantity.HR.Tests as HR
|
||||
import qualified Duckling.Quantity.KO.Tests as KO
|
||||
import qualified Duckling.Quantity.PT.Tests as PT
|
||||
import qualified Duckling.Quantity.RO.Tests as RO
|
||||
@ -22,6 +23,7 @@ tests :: TestTree
|
||||
tests = testGroup "Quantity Tests"
|
||||
[ EN.tests
|
||||
, FR.tests
|
||||
, HR.tests
|
||||
, KO.tests
|
||||
, PT.tests
|
||||
, RO.tests
|
||||
|
Loading…
Reference in New Issue
Block a user