mirror of
https://github.com/facebook/duckling.git
synced 2024-11-30 23:33:33 +03:00
georgian numeral support
Summary: Introducing Georgian (KA), and the very beginnings of numeral support Reviewed By: patapizza Differential Revision: D5757952 fbshipit-source-id: 89d05f8
This commit is contained in:
parent
434e88b511
commit
6f774abe38
@ -36,6 +36,7 @@ import qualified Duckling.Dimensions.HU as HUDimensions
|
||||
import qualified Duckling.Dimensions.ID as IDDimensions
|
||||
import qualified Duckling.Dimensions.IT as ITDimensions
|
||||
import qualified Duckling.Dimensions.JA as JADimensions
|
||||
import qualified Duckling.Dimensions.KA as KADimensions
|
||||
import qualified Duckling.Dimensions.KO as KODimensions
|
||||
import qualified Duckling.Dimensions.MY as MYDimensions
|
||||
import qualified Duckling.Dimensions.NB as NBDimensions
|
||||
@ -95,6 +96,7 @@ langDimensions HU = HUDimensions.allDimensions
|
||||
langDimensions ID = IDDimensions.allDimensions
|
||||
langDimensions IT = ITDimensions.allDimensions
|
||||
langDimensions JA = JADimensions.allDimensions
|
||||
langDimensions KA = KADimensions.allDimensions
|
||||
langDimensions KO = KODimensions.allDimensions
|
||||
langDimensions MY = MYDimensions.allDimensions
|
||||
langDimensions NB = NBDimensions.allDimensions
|
||||
|
17
Duckling/Dimensions/KA.hs
Normal file
17
Duckling/Dimensions/KA.hs
Normal file
@ -0,0 +1,17 @@
|
||||
-- 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.Dimensions.KA
|
||||
( allDimensions
|
||||
) where
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
|
||||
allDimensions :: [Some Dimension]
|
||||
allDimensions =
|
||||
[ This Numeral ]
|
@ -38,6 +38,7 @@ data Lang
|
||||
| ID
|
||||
| IT
|
||||
| JA
|
||||
| KA
|
||||
| KO
|
||||
| MY
|
||||
| NB
|
||||
|
43
Duckling/Numeral/KA/Corpus.hs
Normal file
43
Duckling/Numeral/KA/Corpus.hs
Normal file
@ -0,0 +1,43 @@
|
||||
-- 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.Numeral.KA.Corpus
|
||||
( corpus ) where
|
||||
|
||||
import Data.String
|
||||
import Prelude
|
||||
|
||||
import Duckling.Lang
|
||||
import Duckling.Numeral.Types
|
||||
import Duckling.Resolve
|
||||
import Duckling.Testing.Types
|
||||
|
||||
corpus :: Corpus
|
||||
corpus = (testContext {lang = KA}, allExamples)
|
||||
|
||||
allExamples :: [Example]
|
||||
allExamples = concat
|
||||
[ examples (NumeralValue 0)
|
||||
[ "0"
|
||||
, "ნული"
|
||||
]
|
||||
, examples (NumeralValue 1)
|
||||
[ "1"
|
||||
, "ერთი"
|
||||
]
|
||||
, examples (NumeralValue 2)
|
||||
[ "2"
|
||||
, "ორი"
|
||||
]
|
||||
, examples (NumeralValue 3)
|
||||
[ "3"
|
||||
, "სამი"
|
||||
]
|
||||
]
|
75
Duckling/Numeral/KA/Rules.hs
Normal file
75
Duckling/Numeral/KA/Rules.hs
Normal file
@ -0,0 +1,75 @@
|
||||
-- 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.Numeral.KA.Rules
|
||||
( rules ) where
|
||||
|
||||
import Data.HashMap.Strict (HashMap)
|
||||
import Data.Maybe
|
||||
import Data.String
|
||||
import Data.Text (Text)
|
||||
import Prelude
|
||||
import qualified Data.HashMap.Strict as HashMap
|
||||
import qualified Data.Text as Text
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Numeral.Helpers
|
||||
import Duckling.Numeral.Types (NumeralData (..))
|
||||
import Duckling.Regex.Types
|
||||
import Duckling.Types
|
||||
import qualified Duckling.Numeral.Types as TNumeral
|
||||
|
||||
ruleIntegerNumeric :: Rule
|
||||
ruleIntegerNumeric = Rule
|
||||
{ name = "integer (numeric)"
|
||||
, pattern =
|
||||
[ regex "(\\d{1,18})"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token RegexMatch (GroupMatch (match:_)):
|
||||
_) -> do
|
||||
v <- parseInt match
|
||||
integer $ toInteger v
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
ruleNumeralMap :: HashMap Text Integer
|
||||
ruleNumeralMap = HashMap.fromList
|
||||
[ ( "ნული", 0 )
|
||||
, ( "ერთი", 1 )
|
||||
, ( "ორი", 2 )
|
||||
, ( "სამი", 3 )
|
||||
, ( "ოთხი", 4 )
|
||||
, ( "ხუთი", 5)
|
||||
, ( "ექვსი", 6)
|
||||
, ( "შვიდი", 7)
|
||||
, ( "რვა", 8)
|
||||
, ( "ცხრა", 9)
|
||||
, ( "ათი", 10)
|
||||
]
|
||||
|
||||
ruleNumeral :: Rule
|
||||
ruleNumeral = Rule
|
||||
{ name = "number (0..10)"
|
||||
, pattern =
|
||||
[ regex "(ნული|ერთი|ორი|სამი|ოთხი|ხუთი|ექვსი|შვიდი|რვა|ცხრა|ათი)"
|
||||
]
|
||||
, prod = \tokens -> case tokens of
|
||||
(Token RegexMatch (GroupMatch (match:_)):_) ->
|
||||
HashMap.lookup (Text.toLower match) ruleNumeralMap >>= integer
|
||||
_ -> Nothing
|
||||
}
|
||||
|
||||
rules :: [Rule]
|
||||
rules =
|
||||
[ ruleIntegerNumeric
|
||||
, ruleNumeral
|
||||
]
|
@ -27,6 +27,7 @@ import qualified Duckling.Ranking.Classifiers.HU as HUClassifiers
|
||||
import qualified Duckling.Ranking.Classifiers.ID as IDClassifiers
|
||||
import qualified Duckling.Ranking.Classifiers.IT as ITClassifiers
|
||||
import qualified Duckling.Ranking.Classifiers.JA as JAClassifiers
|
||||
import qualified Duckling.Ranking.Classifiers.KA as KAClassifiers
|
||||
import qualified Duckling.Ranking.Classifiers.KO as KOClassifiers
|
||||
import qualified Duckling.Ranking.Classifiers.MY as MYClassifiers
|
||||
import qualified Duckling.Ranking.Classifiers.NB as NBClassifiers
|
||||
@ -59,6 +60,7 @@ classifiers HU = HUClassifiers.classifiers
|
||||
classifiers ID = IDClassifiers.classifiers
|
||||
classifiers IT = ITClassifiers.classifiers
|
||||
classifiers JA = JAClassifiers.classifiers
|
||||
classifiers KA = KAClassifiers.classifiers
|
||||
classifiers KO = KOClassifiers.classifiers
|
||||
classifiers MY = MYClassifiers.classifiers
|
||||
classifiers NB = NBClassifiers.classifiers
|
||||
|
22
Duckling/Ranking/Classifiers/KA.hs
Normal file
22
Duckling/Ranking/Classifiers/KA.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.
|
||||
|
||||
-----------------------------------------------------------------
|
||||
-- Auto-generated by regenClassifiers
|
||||
--
|
||||
-- DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
|
||||
-- @generated
|
||||
-----------------------------------------------------------------
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
module Duckling.Ranking.Classifiers.KA (classifiers) where
|
||||
import Prelude
|
||||
import Duckling.Ranking.Types
|
||||
import qualified Data.HashMap.Strict as HashMap
|
||||
import Data.String
|
||||
|
||||
classifiers :: Classifiers
|
||||
classifiers = HashMap.fromList []
|
@ -38,6 +38,7 @@ import qualified Duckling.Rules.HU as HURules
|
||||
import qualified Duckling.Rules.ID as IDRules
|
||||
import qualified Duckling.Rules.IT as ITRules
|
||||
import qualified Duckling.Rules.JA as JARules
|
||||
import qualified Duckling.Rules.KA as KARules
|
||||
import qualified Duckling.Rules.KO as KORules
|
||||
import qualified Duckling.Rules.MY as MYRules
|
||||
import qualified Duckling.Rules.NB as NBRules
|
||||
@ -86,6 +87,7 @@ langRules HU = HURules.rules
|
||||
langRules ID = IDRules.rules
|
||||
langRules IT = ITRules.rules
|
||||
langRules JA = JARules.rules
|
||||
langRules KA = KARules.rules
|
||||
langRules KO = KORules.rules
|
||||
langRules MY = MYRules.rules
|
||||
langRules NB = NBRules.rules
|
||||
|
34
Duckling/Rules/KA.hs
Normal file
34
Duckling/Rules/KA.hs
Normal file
@ -0,0 +1,34 @@
|
||||
-- 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.Rules.KA
|
||||
( rules
|
||||
) where
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Types
|
||||
import qualified Duckling.Numeral.KA.Rules as Numeral
|
||||
|
||||
rules :: Some Dimension -> [Rule]
|
||||
rules (This Distance) = []
|
||||
rules (This Duration) = []
|
||||
rules (This Numeral) = Numeral.rules
|
||||
rules (This Email) = []
|
||||
rules (This AmountOfMoney) = []
|
||||
rules (This Ordinal) = []
|
||||
rules (This PhoneNumber) = []
|
||||
rules (This Quantity) = []
|
||||
rules (This RegexMatch) = []
|
||||
rules (This Temperature) = []
|
||||
rules (This Time) = []
|
||||
rules (This TimeGrain) = []
|
||||
rules (This Url) = []
|
||||
rules (This Volume) = []
|
@ -56,6 +56,7 @@ library
|
||||
, Duckling.Rules.ID
|
||||
, Duckling.Rules.IT
|
||||
, Duckling.Rules.JA
|
||||
, Duckling.Rules.KA
|
||||
, Duckling.Rules.KO
|
||||
, Duckling.Rules.MY
|
||||
, Duckling.Rules.NB
|
||||
@ -92,6 +93,7 @@ library
|
||||
, Duckling.Ranking.Classifiers.ID
|
||||
, Duckling.Ranking.Classifiers.IT
|
||||
, Duckling.Ranking.Classifiers.JA
|
||||
, Duckling.Ranking.Classifiers.KA
|
||||
, Duckling.Ranking.Classifiers.KO
|
||||
, Duckling.Ranking.Classifiers.MY
|
||||
, Duckling.Ranking.Classifiers.NB
|
||||
@ -127,6 +129,7 @@ library
|
||||
, Duckling.Dimensions.ID
|
||||
, Duckling.Dimensions.IT
|
||||
, Duckling.Dimensions.JA
|
||||
, Duckling.Dimensions.KA
|
||||
, Duckling.Dimensions.KO
|
||||
, Duckling.Dimensions.MY
|
||||
, Duckling.Dimensions.NB
|
||||
@ -276,6 +279,8 @@ library
|
||||
, Duckling.Numeral.IT.Rules
|
||||
, Duckling.Numeral.JA.Corpus
|
||||
, Duckling.Numeral.JA.Rules
|
||||
, Duckling.Numeral.KA.Corpus
|
||||
, Duckling.Numeral.KA.Rules
|
||||
, Duckling.Numeral.KO.Corpus
|
||||
, Duckling.Numeral.KO.Rules
|
||||
, Duckling.Numeral.MY.Corpus
|
||||
@ -624,6 +629,7 @@ test-suite duckling-test
|
||||
, Duckling.Numeral.ID.Tests
|
||||
, Duckling.Numeral.IT.Tests
|
||||
, Duckling.Numeral.JA.Tests
|
||||
, Duckling.Numeral.KA.Tests
|
||||
, Duckling.Numeral.KO.Tests
|
||||
, Duckling.Numeral.MY.Tests
|
||||
, Duckling.Numeral.NB.Tests
|
||||
|
@ -85,6 +85,7 @@ regenClassifiers lang = do
|
||||
ID -> (testContext, [])
|
||||
IT -> ITTime.corpus
|
||||
JA -> (testContext, [])
|
||||
KA -> (testContext, [])
|
||||
KO -> KOTime.corpus
|
||||
MY -> (testContext, [])
|
||||
NB -> NBTime.corpus
|
||||
|
22
tests/Duckling/Numeral/KA/Tests.hs
Normal file
22
tests/Duckling/Numeral/KA/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.Numeral.KA.Tests
|
||||
( tests ) where
|
||||
|
||||
import Data.String
|
||||
import Prelude
|
||||
import Test.Tasty
|
||||
|
||||
import Duckling.Dimensions.Types
|
||||
import Duckling.Numeral.KA.Corpus
|
||||
import Duckling.Testing.Asserts
|
||||
|
||||
tests :: TestTree
|
||||
tests = testGroup "KA Tests"
|
||||
[ makeCorpusTest [This Numeral] corpus
|
||||
]
|
@ -28,6 +28,7 @@ import qualified Duckling.Numeral.HU.Tests as HU
|
||||
import qualified Duckling.Numeral.ID.Tests as ID
|
||||
import qualified Duckling.Numeral.IT.Tests as IT
|
||||
import qualified Duckling.Numeral.JA.Tests as JA
|
||||
import qualified Duckling.Numeral.KA.Tests as KA
|
||||
import qualified Duckling.Numeral.KO.Tests as KO
|
||||
import qualified Duckling.Numeral.MY.Tests as MY
|
||||
import qualified Duckling.Numeral.NB.Tests as NB
|
||||
@ -60,6 +61,7 @@ tests = testGroup "Numeral Tests"
|
||||
, ID.tests
|
||||
, IT.tests
|
||||
, JA.tests
|
||||
, KA.tests
|
||||
, KO.tests
|
||||
, MY.tests
|
||||
, NB.tests
|
||||
|
Loading…
Reference in New Issue
Block a user