mirror of
https://github.com/facebook/duckling.git
synced 2024-08-17 09:10:29 +03:00
Init
Summary: Initialise Temperature for CA (Catalan) language Reviewed By: stroxler Differential Revision: D28298423 Pulled By: chessai fbshipit-source-id: 73b87d002196b6b707388e9f83f42591510f40eb
This commit is contained in:
parent
ff342868d7
commit
219e5600d6
@ -8,6 +8,7 @@
|
||||
* CA (Catalan)
|
||||
* AmountOfMoney: **new!**
|
||||
* Distance: **new!**
|
||||
* Temperature: **new!**
|
||||
|
||||
* EN (English)
|
||||
* Time: Allow latent match for \<part-of-day\> \<latent-time-of-day\>
|
||||
|
@ -17,4 +17,5 @@ allDimensions =
|
||||
, Seal Distance
|
||||
, Seal Numeral
|
||||
, Seal Ordinal
|
||||
, Seal Temperature
|
||||
]
|
||||
|
@ -21,6 +21,7 @@ import qualified Duckling.AmountOfMoney.CA.Rules as AmountOfMoney
|
||||
import qualified Duckling.Distance.CA.Rules as Distance
|
||||
import qualified Duckling.Numeral.CA.Rules as Numeral
|
||||
import qualified Duckling.Ordinal.CA.Rules as Ordinal
|
||||
import qualified Duckling.Temperature.CA.Rules as Temperature
|
||||
import Duckling.Types
|
||||
|
||||
defaultRules :: Seal Dimension -> [Rule]
|
||||
@ -41,7 +42,7 @@ langRules (Seal Ordinal) = Ordinal.rules
|
||||
langRules (Seal PhoneNumber) = []
|
||||
langRules (Seal Quantity) = []
|
||||
langRules (Seal RegexMatch) = []
|
||||
langRules (Seal Temperature) = []
|
||||
langRules (Seal Temperature) = Temperature.rules
|
||||
langRules (Seal Time) = []
|
||||
langRules (Seal TimeGrain) = []
|
||||
langRules (Seal Url) = []
|
||||
|
54
Duckling/Temperature/CA/Corpus.hs
Normal file
54
Duckling/Temperature/CA/Corpus.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 OverloadedStrings #-}
|
||||
|
||||
module Duckling.Temperature.CA.Corpus
|
||||
( corpus ) where
|
||||
|
||||
import Prelude
|
||||
import Data.String
|
||||
|
||||
import Duckling.Locale
|
||||
import Duckling.Resolve
|
||||
import Duckling.Temperature.Types
|
||||
import Duckling.Testing.Types
|
||||
|
||||
corpus :: Corpus
|
||||
corpus = (testContext {locale = makeLocale CA Nothing}, testOptions, allExamples)
|
||||
|
||||
allExamples :: [Example]
|
||||
allExamples = concat
|
||||
[ examples (simple Celsius 37)
|
||||
[ "37°C"
|
||||
, "37 ° celsius"
|
||||
, "37 graus Celsius"
|
||||
, "37 graus C"
|
||||
, "37 centígrads"
|
||||
, "37 graus centígrads"
|
||||
, "37 Celsius"
|
||||
]
|
||||
, examples (simple Fahrenheit 70)
|
||||
[ "70°F"
|
||||
, "70 ° Fahrenheit"
|
||||
, "70 graus F"
|
||||
, "setanta Fahrenheit"
|
||||
]
|
||||
, examples (simple Degree 45)
|
||||
[ "45°"
|
||||
, "45 graus"
|
||||
]
|
||||
, examples (simple Degree 37)
|
||||
[ "trenta-set graus"
|
||||
, "37 grads"
|
||||
]
|
||||
, examples (simple Degree (-10))
|
||||
[ "-10°"
|
||||
, "- deu graus"
|
||||
, "10 sota zero"
|
||||
]
|
||||
]
|
85
Duckling/Temperature/CA/Rules.hs
Normal file
85
Duckling/Temperature/CA/Rules.hs
Normal file
@ -0,0 +1,85 @@
|
||||
-- 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 LambdaCase #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Duckling.Temperature.CA.Rules
|
||||
( rules ) where
|
||||
|
||||
import Prelude
|
||||
import Data.String
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Temperature.Helpers
|
||||
import Duckling.Temperature.Types (TemperatureData (..))
|
||||
import qualified Duckling.Temperature.Types as TTemperature
|
||||
import Duckling.Types
|
||||
|
||||
ruleLatentTempTemp :: Rule
|
||||
ruleLatentTempTemp = Rule
|
||||
{ name = "<latent temp> temp"
|
||||
, pattern =
|
||||
[ Predicate $ isValueOnly False
|
||||
, regex "(gra(d|u)s?|°)"
|
||||
]
|
||||
, prod = \case
|
||||
(Token Temperature td:_) ->
|
||||
Just $ Token Temperature $ withUnit TTemperature.Degree td
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleTempCelsius :: Rule
|
||||
ruleTempCelsius = Rule
|
||||
{ name = "<temp> Celsius"
|
||||
, pattern =
|
||||
[ Predicate $ isValueOnly True
|
||||
, regex "(cent(i|í)gra(d|u)s?|(C|c)(el[cs]?(ius)?)?\\.?)"
|
||||
]
|
||||
, prod = \case
|
||||
(Token Temperature td:_) ->
|
||||
Just $ Token Temperature $ withUnit TTemperature.Celsius td
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleTempFahrenheit :: Rule
|
||||
ruleTempFahrenheit = Rule
|
||||
{ name = "<temp> Fahrenheit"
|
||||
, pattern =
|
||||
[ Predicate $ isValueOnly True
|
||||
, regex "f(ah?reh?n(h?eit)?)?\\.?"
|
||||
]
|
||||
, prod = \case
|
||||
(Token Temperature td:_) -> Just $ Token Temperature $
|
||||
withUnit TTemperature.Fahrenheit td
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleLatentTempTempBajoCero :: Rule
|
||||
ruleLatentTempTempBajoCero = Rule
|
||||
{ name = "<latent temp> temp bajo zero"
|
||||
, pattern =
|
||||
[ Predicate $ isValueOnly True
|
||||
, regex "sota zero"
|
||||
]
|
||||
, prod = \case
|
||||
(Token Temperature td@TemperatureData{TTemperature.value = Just v}:_) ->
|
||||
case TTemperature.unit td of
|
||||
Nothing -> Just $ Token Temperature $ withUnit TTemperature.Degree $
|
||||
td {TTemperature.value = Just (- v)}
|
||||
_ -> Just $ Token Temperature $ td {TTemperature.value = Just (- v)}
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
rules :: [Rule]
|
||||
rules =
|
||||
[ ruleLatentTempTemp
|
||||
, ruleLatentTempTempBajoCero
|
||||
, ruleTempCelsius
|
||||
, ruleTempFahrenheit
|
||||
]
|
@ -650,6 +650,8 @@ library
|
||||
-- Temperature
|
||||
, Duckling.Temperature.AR.Corpus
|
||||
, Duckling.Temperature.AR.Rules
|
||||
, Duckling.Temperature.CA.Corpus
|
||||
, Duckling.Temperature.CA.Rules
|
||||
, Duckling.Temperature.EN.Corpus
|
||||
, Duckling.Temperature.EN.Rules
|
||||
, Duckling.Temperature.ES.Corpus
|
||||
@ -1105,6 +1107,7 @@ test-suite duckling-test
|
||||
|
||||
-- Temperature
|
||||
, Duckling.Temperature.AR.Tests
|
||||
, Duckling.Temperature.CA.Tests
|
||||
, Duckling.Temperature.EN.Tests
|
||||
, Duckling.Temperature.ES.Tests
|
||||
, Duckling.Temperature.FR.Tests
|
||||
|
22
tests/Duckling/Temperature/CA/Tests.hs
Normal file
22
tests/Duckling/Temperature/CA/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.
|
||||
|
||||
|
||||
module Duckling.Temperature.CA.Tests
|
||||
( tests ) where
|
||||
|
||||
import Data.String
|
||||
import Prelude
|
||||
import Test.Tasty
|
||||
|
||||
import Duckling.Temperature.CA.Corpus
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Testing.Asserts
|
||||
|
||||
tests :: TestTree
|
||||
tests = testGroup "CA Tests"
|
||||
[ makeCorpusTest [Seal Temperature] corpus
|
||||
]
|
Loading…
Reference in New Issue
Block a user