mirror of
https://github.com/facebook/duckling.git
synced 2025-01-08 06:46:39 +03:00
Init
Summary: Initialises Distance for CA (Catalan) language Reviewed By: stroxler Differential Revision: D28297521 Pulled By: chessai fbshipit-source-id: eb8641568f5981ea6e2d481c305e36cdb683dcfb
This commit is contained in:
parent
213d1f12a5
commit
1322cd69ec
@ -7,6 +7,7 @@
|
|||||||
### Rulesets
|
### Rulesets
|
||||||
* CA (Catalan)
|
* CA (Catalan)
|
||||||
* AmountOfMoney: **new!**
|
* AmountOfMoney: **new!**
|
||||||
|
* Distance: **new!**
|
||||||
|
|
||||||
* EN (English)
|
* EN (English)
|
||||||
* Time: Allow latent match for \<part-of-day\> \<latent-time-of-day\>
|
* Time: Allow latent match for \<part-of-day\> \<latent-time-of-day\>
|
||||||
|
@ -14,6 +14,7 @@ import Duckling.Dimensions.Types
|
|||||||
allDimensions :: [Seal Dimension]
|
allDimensions :: [Seal Dimension]
|
||||||
allDimensions =
|
allDimensions =
|
||||||
[ Seal AmountOfMoney
|
[ Seal AmountOfMoney
|
||||||
|
, Seal Distance
|
||||||
, Seal Numeral
|
, Seal Numeral
|
||||||
, Seal Ordinal
|
, Seal Ordinal
|
||||||
]
|
]
|
||||||
|
55
Duckling/Distance/CA/Corpus.hs
Normal file
55
Duckling/Distance/CA/Corpus.hs
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
-- 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.Distance.CA.Corpus
|
||||||
|
( corpus
|
||||||
|
) where
|
||||||
|
|
||||||
|
import Data.String
|
||||||
|
import Prelude
|
||||||
|
|
||||||
|
import Duckling.Distance.Types
|
||||||
|
import Duckling.Locale
|
||||||
|
import Duckling.Resolve
|
||||||
|
import Duckling.Testing.Types
|
||||||
|
|
||||||
|
corpus :: Corpus
|
||||||
|
corpus = (testContext {locale = makeLocale CA Nothing}, testOptions, allExamples)
|
||||||
|
|
||||||
|
allExamples :: [Example]
|
||||||
|
allExamples = concat
|
||||||
|
[ examples (simple Kilometre 3)
|
||||||
|
[ "3 kilòmetres"
|
||||||
|
, "3 kilometres"
|
||||||
|
, "3 kilómetres"
|
||||||
|
, "3 quilòmetres"
|
||||||
|
, "3 km"
|
||||||
|
, "3km"
|
||||||
|
]
|
||||||
|
, examples (simple Kilometre 3.0)
|
||||||
|
[ "3 km"
|
||||||
|
]
|
||||||
|
, examples (simple Mile 8)
|
||||||
|
[ "8 milles"
|
||||||
|
]
|
||||||
|
, examples (simple Metre 9)
|
||||||
|
[ "9m"
|
||||||
|
, "9 metres"
|
||||||
|
, "9 m"
|
||||||
|
]
|
||||||
|
, examples (simple Metre 1)
|
||||||
|
[ "1m"
|
||||||
|
, "1 metre"
|
||||||
|
]
|
||||||
|
, examples (simple Centimetre 2)
|
||||||
|
[ "2cm"
|
||||||
|
, "2 centímetres"
|
||||||
|
, "2 cm"
|
||||||
|
]
|
||||||
|
]
|
80
Duckling/Distance/CA/Rules.hs
Normal file
80
Duckling/Distance/CA/Rules.hs
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
-- 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 OverloadedStrings #-}
|
||||||
|
|
||||||
|
module Duckling.Distance.CA.Rules
|
||||||
|
( rules ) where
|
||||||
|
|
||||||
|
import Data.String
|
||||||
|
import Prelude
|
||||||
|
|
||||||
|
import Duckling.Dimensions.Types
|
||||||
|
import Duckling.Distance.Helpers
|
||||||
|
import qualified Duckling.Distance.Types as TDistance
|
||||||
|
import Duckling.Types
|
||||||
|
|
||||||
|
ruleLatentDistKm :: Rule
|
||||||
|
ruleLatentDistKm = Rule
|
||||||
|
{ name = "<latent dist> km"
|
||||||
|
, pattern =
|
||||||
|
[ dimension Distance
|
||||||
|
, regex "(k|qu)(il(o|ò|ó))?m?(etre)?s?"
|
||||||
|
]
|
||||||
|
, prod = \tokens -> case tokens of
|
||||||
|
(Token Distance dd:_) ->
|
||||||
|
Just $ Token Distance $ withUnit TDistance.Kilometre dd
|
||||||
|
_ -> Nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
ruleDistMeters :: Rule
|
||||||
|
ruleDistMeters = Rule
|
||||||
|
{ name = "<dist> meters"
|
||||||
|
, pattern =
|
||||||
|
[ dimension Distance
|
||||||
|
, regex "m(etres?)?"
|
||||||
|
]
|
||||||
|
, prod = \tokens -> case tokens of
|
||||||
|
(Token Distance dd:_) ->
|
||||||
|
Just $ Token Distance $ withUnit TDistance.Metre dd
|
||||||
|
_ -> Nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
ruleDistCentimeters :: Rule
|
||||||
|
ruleDistCentimeters = Rule
|
||||||
|
{ name = "<dist> centimeters"
|
||||||
|
, pattern =
|
||||||
|
[ dimension Distance
|
||||||
|
, regex "(cm|cent(í|i)m(etres?))"
|
||||||
|
]
|
||||||
|
, prod = \tokens -> case tokens of
|
||||||
|
(Token Distance dd:_) ->
|
||||||
|
Just $ Token Distance $ withUnit TDistance.Centimetre dd
|
||||||
|
_ -> Nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
ruleDistMiles :: Rule
|
||||||
|
ruleDistMiles = Rule
|
||||||
|
{ name = "<dist> miles"
|
||||||
|
, pattern =
|
||||||
|
[ dimension Distance
|
||||||
|
, regex "milles?"
|
||||||
|
]
|
||||||
|
, prod = \tokens -> case tokens of
|
||||||
|
(Token Distance dd:_) ->
|
||||||
|
Just $ Token Distance $ withUnit TDistance.Mile dd
|
||||||
|
_ -> Nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
rules :: [Rule]
|
||||||
|
rules =
|
||||||
|
[ ruleDistCentimeters
|
||||||
|
, ruleDistMeters
|
||||||
|
, ruleDistMiles
|
||||||
|
, ruleLatentDistKm
|
||||||
|
]
|
@ -18,6 +18,7 @@ module Duckling.Rules.CA
|
|||||||
import Duckling.Dimensions.Types
|
import Duckling.Dimensions.Types
|
||||||
import Duckling.Locale
|
import Duckling.Locale
|
||||||
import qualified Duckling.AmountOfMoney.CA.Rules as AmountOfMoney
|
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.Numeral.CA.Rules as Numeral
|
||||||
import qualified Duckling.Ordinal.CA.Rules as Ordinal
|
import qualified Duckling.Ordinal.CA.Rules as Ordinal
|
||||||
import Duckling.Types
|
import Duckling.Types
|
||||||
@ -32,7 +33,7 @@ localeRules _ _ = []
|
|||||||
langRules :: Seal Dimension -> [Rule]
|
langRules :: Seal Dimension -> [Rule]
|
||||||
langRules (Seal AmountOfMoney) = AmountOfMoney.rules
|
langRules (Seal AmountOfMoney) = AmountOfMoney.rules
|
||||||
langRules (Seal CreditCardNumber) = []
|
langRules (Seal CreditCardNumber) = []
|
||||||
langRules (Seal Distance) = []
|
langRules (Seal Distance) = Distance.rules
|
||||||
langRules (Seal Duration) = []
|
langRules (Seal Duration) = []
|
||||||
langRules (Seal Email) = []
|
langRules (Seal Email) = []
|
||||||
langRules (Seal Numeral) = Numeral.rules
|
langRules (Seal Numeral) = Numeral.rules
|
||||||
|
@ -298,6 +298,8 @@ library
|
|||||||
-- Distance
|
-- Distance
|
||||||
, Duckling.Distance.BG.Corpus
|
, Duckling.Distance.BG.Corpus
|
||||||
, Duckling.Distance.BG.Rules
|
, Duckling.Distance.BG.Rules
|
||||||
|
, Duckling.Distance.CA.Corpus
|
||||||
|
, Duckling.Distance.CA.Rules
|
||||||
, Duckling.Distance.CS.Corpus
|
, Duckling.Distance.CS.Corpus
|
||||||
, Duckling.Distance.CS.Rules
|
, Duckling.Distance.CS.Rules
|
||||||
, Duckling.Distance.DE.Corpus
|
, Duckling.Distance.DE.Corpus
|
||||||
@ -935,6 +937,7 @@ test-suite duckling-test
|
|||||||
|
|
||||||
-- Distance
|
-- Distance
|
||||||
, Duckling.Distance.BG.Tests
|
, Duckling.Distance.BG.Tests
|
||||||
|
, Duckling.Distance.CA.Tests
|
||||||
, Duckling.Distance.CS.Tests
|
, Duckling.Distance.CS.Tests
|
||||||
, Duckling.Distance.DE.Tests
|
, Duckling.Distance.DE.Tests
|
||||||
, Duckling.Distance.EN.Tests
|
, Duckling.Distance.EN.Tests
|
||||||
|
22
tests/Duckling/Distance/CA/Tests.hs
Normal file
22
tests/Duckling/Distance/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.Distance.CA.Tests
|
||||||
|
( tests ) where
|
||||||
|
|
||||||
|
import Data.String
|
||||||
|
import Prelude
|
||||||
|
import Test.Tasty
|
||||||
|
|
||||||
|
import Duckling.Distance.CA.Corpus
|
||||||
|
import Duckling.Dimensions.Types
|
||||||
|
import Duckling.Testing.Asserts
|
||||||
|
|
||||||
|
tests :: TestTree
|
||||||
|
tests = testGroup "CA Tests"
|
||||||
|
[ makeCorpusTest [Seal Distance] corpus
|
||||||
|
]
|
Loading…
Reference in New Issue
Block a user