mirror of
https://github.com/facebook/duckling.git
synced 2025-01-06 04:53:13 +03:00
Volume for IT lang
Summary: I notice that there are several missing dimensions for the IT language: this patch is for the Volume dimension Regards Matteo Closes https://github.com/facebookincubator/duckling/pull/4 Reviewed By: JonCoens Differential Revision: D4986389 Pulled By: patapizza fbshipit-source-id: 314d33e
This commit is contained in:
parent
88639e8a56
commit
e11014dc4b
@ -19,4 +19,5 @@ allDimensions =
|
||||
, This Ordinal
|
||||
, This Temperature
|
||||
, This Time
|
||||
, This Volume
|
||||
]
|
||||
|
@ -21,6 +21,7 @@ import qualified Duckling.Ordinal.IT.Rules as Ordinal
|
||||
import qualified Duckling.Temperature.IT.Rules as Temperature
|
||||
import qualified Duckling.Time.IT.Rules as Time
|
||||
import qualified Duckling.TimeGrain.IT.Rules as TimeGrain
|
||||
import qualified Duckling.Volume.IT.Rules as Volume
|
||||
import Duckling.Types
|
||||
|
||||
rules :: Some Dimension -> [Rule]
|
||||
@ -37,4 +38,4 @@ rules (This Temperature) = Temperature.rules
|
||||
rules (This Time) = Time.rules
|
||||
rules (This TimeGrain) = TimeGrain.rules
|
||||
rules (This Url) = []
|
||||
rules (This Volume) = []
|
||||
rules (This Volume) = Volume.rules
|
||||
|
46
Duckling/Volume/IT/Corpus.hs
Normal file
46
Duckling/Volume/IT/Corpus.hs
Normal file
@ -0,0 +1,46 @@
|
||||
-- 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.Volume.IT.Corpus
|
||||
( corpus ) where
|
||||
|
||||
import Data.String
|
||||
import Prelude
|
||||
|
||||
import Duckling.Lang
|
||||
import Duckling.Resolve
|
||||
import Duckling.Volume.Types
|
||||
import Duckling.Testing.Types
|
||||
|
||||
corpus :: Corpus
|
||||
corpus = (testContext {lang = IT}, allExamples)
|
||||
|
||||
allExamples :: [Example]
|
||||
allExamples = concat
|
||||
[ examples (VolumeValue Millilitre 250)
|
||||
[ "250 millilitri"
|
||||
, "250ml"
|
||||
, "250 ml"
|
||||
]
|
||||
, examples (VolumeValue Litre 2)
|
||||
[ "2 litri"
|
||||
, "2l"
|
||||
]
|
||||
, examples (VolumeValue Gallon 3)
|
||||
[ "3 galloni"
|
||||
, "3 gal"
|
||||
]
|
||||
, examples (VolumeValue Hectolitre 3)
|
||||
[ "3 ettolitri"
|
||||
]
|
||||
, examples (VolumeValue Litre 0.5)
|
||||
[ "mezzo litro"
|
||||
]
|
||||
]
|
89
Duckling/Volume/IT/Rules.hs
Normal file
89
Duckling/Volume/IT/Rules.hs
Normal file
@ -0,0 +1,89 @@
|
||||
-- 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.Volume.IT.Rules
|
||||
( rules ) where
|
||||
|
||||
import Prelude
|
||||
import Data.String
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Types
|
||||
import Duckling.Volume.Helpers
|
||||
import qualified Duckling.Volume.Types as TVolume
|
||||
|
||||
ruleLatentVolMl :: Rule
|
||||
ruleLatentVolMl = Rule
|
||||
{ name = "<latent vol> ml"
|
||||
, pattern =
|
||||
[ dimension Volume
|
||||
, regex "m(l|illilitr(i|o))"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Volume vd:_) ->
|
||||
Just . Token Volume $ withUnit TVolume.Millilitre vd
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleVolHectoliters :: Rule
|
||||
ruleVolHectoliters = Rule
|
||||
{ name = "<vol> hectoliters"
|
||||
, pattern =
|
||||
[ dimension Volume
|
||||
, regex "ettolitr(i|o)"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Volume vd:_) ->
|
||||
Just . Token Volume $ withUnit TVolume.Hectolitre vd
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleVolLiters :: Rule
|
||||
ruleVolLiters = Rule
|
||||
{ name = "<vol> liters"
|
||||
, pattern =
|
||||
[ dimension Volume
|
||||
, regex "l(itr(i|o))?"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Volume vd:_) -> Just . Token Volume $ withUnit TVolume.Litre vd
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleHalfLiter :: Rule
|
||||
ruleHalfLiter = Rule
|
||||
{ name = "half liter"
|
||||
, pattern =
|
||||
[ regex "mezzo litro"
|
||||
]
|
||||
, prod = \_ -> Just . Token Volume . withUnit TVolume.Litre $ volume 0.5
|
||||
}
|
||||
|
||||
ruleLatentVolGallon :: Rule
|
||||
ruleLatentVolGallon = Rule
|
||||
{ name = "<latent vol> gallon"
|
||||
, pattern =
|
||||
[ dimension Volume
|
||||
, regex "gal(lon(e|i))?"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token Volume vd:_) -> Just . Token Volume $ withUnit TVolume.Gallon vd
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
rules :: [Rule]
|
||||
rules =
|
||||
[ ruleHalfLiter
|
||||
, ruleLatentVolGallon
|
||||
, ruleLatentVolMl
|
||||
, ruleVolHectoliters
|
||||
, ruleVolLiters
|
||||
]
|
@ -462,6 +462,8 @@ library
|
||||
, Duckling.Volume.GA.Rules
|
||||
, Duckling.Volume.HR.Corpus
|
||||
, Duckling.Volume.HR.Rules
|
||||
, Duckling.Volume.IT.Corpus
|
||||
, Duckling.Volume.IT.Rules
|
||||
, Duckling.Volume.KO.Corpus
|
||||
, Duckling.Volume.KO.Rules
|
||||
, Duckling.Volume.PT.Corpus
|
||||
@ -687,6 +689,7 @@ test-suite duckling-test
|
||||
, Duckling.Volume.FR.Tests
|
||||
, Duckling.Volume.GA.Tests
|
||||
, Duckling.Volume.HR.Tests
|
||||
, Duckling.Volume.IT.Tests
|
||||
, Duckling.Volume.KO.Tests
|
||||
, Duckling.Volume.PT.Tests
|
||||
, Duckling.Volume.NL.Tests
|
||||
|
22
tests/Duckling/Volume/IT/Tests.hs
Normal file
22
tests/Duckling/Volume/IT/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.Volume.IT.Tests
|
||||
( tests ) where
|
||||
|
||||
import Data.String
|
||||
import Prelude
|
||||
import Test.Tasty
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Testing.Asserts
|
||||
import Duckling.Volume.IT.Corpus
|
||||
|
||||
tests :: TestTree
|
||||
tests = testGroup "IT Tests"
|
||||
[ makeCorpusTest [This Volume] corpus
|
||||
]
|
@ -17,6 +17,7 @@ import qualified Duckling.Volume.ES.Tests as ES
|
||||
import qualified Duckling.Volume.FR.Tests as FR
|
||||
import qualified Duckling.Volume.GA.Tests as GA
|
||||
import qualified Duckling.Volume.HR.Tests as HR
|
||||
import qualified Duckling.Volume.IT.Tests as IT
|
||||
import qualified Duckling.Volume.KO.Tests as KO
|
||||
import qualified Duckling.Volume.NL.Tests as NL
|
||||
import qualified Duckling.Volume.PT.Tests as PT
|
||||
@ -29,6 +30,7 @@ tests = testGroup "Volume Tests"
|
||||
, FR.tests
|
||||
, GA.tests
|
||||
, HR.tests
|
||||
, IT.tests
|
||||
, KO.tests
|
||||
, NL.tests
|
||||
, PT.tests
|
||||
|
Loading…
Reference in New Issue
Block a user