forked from facebook/duckling
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: Adding support for swahili numerals Reviewed By: patapizza Differential Revision: D13637092 fbshipit-source-id: 6fe0facfa74caae6fd00e0e84b09571aca616f21
- Loading branch information
1 parent
a707be9
commit 392e584
Showing
13 changed files
with
317 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
-- 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.SW | ||
( allDimensions | ||
) where | ||
|
||
import Duckling.Dimensions.Types | ||
|
||
allDimensions :: [Some Dimension] | ||
allDimensions = | ||
[ This Numeral | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,6 +70,7 @@ data Lang | |
| RO | ||
| RU | ||
| SV | ||
| SW | ||
| TA | ||
| TR | ||
| UK | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
-- 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.SW.Corpus | ||
( corpus ) where | ||
|
||
import Data.String | ||
import Prelude | ||
|
||
import Duckling.Locale | ||
import Duckling.Numeral.Types | ||
import Duckling.Resolve | ||
import Duckling.Testing.Types | ||
|
||
corpus :: Corpus | ||
corpus = (testContext {locale = makeLocale SW Nothing}, testOptions, allExamples) | ||
|
||
allExamples :: [Example] | ||
allExamples = concat | ||
[ examples (NumeralValue 0) | ||
[ "0" | ||
, "sufuri" | ||
, "zero" | ||
] | ||
, examples (NumeralValue 1) | ||
[ "moja" | ||
] | ||
, examples (NumeralValue 2) | ||
[ "mbili" | ||
] | ||
, examples (NumeralValue 3) | ||
[ "tatu" | ||
] | ||
, examples (NumeralValue 4) | ||
[ "nne" | ||
] | ||
, examples (NumeralValue 5) | ||
[ "tano" | ||
] | ||
, examples (NumeralValue 6) | ||
[ "sita" | ||
] | ||
, examples (NumeralValue 7) | ||
[ "saba" | ||
] | ||
, examples (NumeralValue 8) | ||
[ "nane" | ||
] | ||
, examples (NumeralValue 9) | ||
[ "tisa" | ||
] | ||
, examples (NumeralValue 10) | ||
[ "kumi" | ||
] | ||
, examples (NumeralValue 20) | ||
[ "ishirini" | ||
] | ||
, examples (NumeralValue 30) | ||
[ "thelathini" | ||
] | ||
, examples (NumeralValue 40) | ||
[ "arubaini" | ||
, "arobaini" | ||
] | ||
, examples (NumeralValue 50) | ||
[ "hamsini" | ||
] | ||
, examples (NumeralValue 60) | ||
[ "sitini" | ||
] | ||
, examples (NumeralValue 70) | ||
[ "sabini" | ||
] | ||
, examples (NumeralValue 80) | ||
[ "themanini" | ||
] | ||
, examples (NumeralValue 90) | ||
[ "tisini" | ||
] | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
-- 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 #-} | ||
{-# LANGUAGE NoRebindableSyntax #-} | ||
|
||
module Duckling.Numeral.SW.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 | ||
|
||
ruleNumeralMap :: HashMap Text Integer | ||
ruleNumeralMap = HashMap.fromList | ||
[ ( "sufuri", 0 ) | ||
, ( "zero", 0 ) | ||
, ( "moja", 1 ) | ||
, ( "mbili", 2 ) | ||
, ( "tatu", 3 ) | ||
, ( "nne", 4 ) | ||
, ( "tano", 5) | ||
, ( "sita", 6) | ||
, ( "saba", 7) | ||
, ( "nane", 8) | ||
, ( "tisa", 9) | ||
, ( "kumi", 10) | ||
] | ||
|
||
ruleNumeral :: Rule | ||
ruleNumeral = Rule | ||
{ name = "number (0..10)" | ||
, pattern = | ||
[ regex "(sufuri|zero|moja|mbili|tatu|nne|tano|sita|saba|nane|tisa|kumi)" | ||
] | ||
, prod = \tokens -> case tokens of | ||
(Token RegexMatch (GroupMatch (match:_)):_) -> | ||
HashMap.lookup (Text.toLower match) ruleNumeralMap >>= integer | ||
_ -> Nothing | ||
} | ||
|
||
tensMap :: HashMap Text Integer | ||
tensMap = HashMap.fromList | ||
[ ( "ishirini", 20 ) | ||
, ( "thelathini", 30 ) | ||
, ( "arubaini", 40 ) | ||
, ( "arobaini", 40 ) | ||
, ( "hamsini", 50 ) | ||
, ( "sitini", 60 ) | ||
, ( "sabini", 70 ) | ||
, ( "themanini", 80 ) | ||
, ( "tisini", 90 ) | ||
] | ||
|
||
ruleTens :: Rule | ||
ruleTens = Rule | ||
{ name = "integer (20,30..90)" | ||
, pattern = | ||
[ regex "(ishirini|thelathini|arubaini|arobaini|hamsini|sitini|sabini|themanini|tisini)" | ||
] | ||
, prod = \tokens -> case tokens of | ||
(Token RegexMatch (GroupMatch (match:_)):_) -> | ||
HashMap.lookup (Text.toLower match) tensMap >>= integer | ||
_ -> Nothing | ||
} | ||
|
||
|
||
ruleCompositeTens :: Rule | ||
ruleCompositeTens = Rule | ||
{ name = "integer 11..19 21..29 .. 91..99" | ||
, pattern = [oneOf [20,30..90] | ||
, regex "-?na-?" | ||
, numberBetween 1 10] | ||
, prod = \tokens -> case tokens of | ||
(Token Numeral NumeralData{TNumeral.value = v1}: | ||
Token Numeral NumeralData{TNumeral.value = v2}: | ||
_) -> double $ v1 + v2 | ||
_ -> Nothing | ||
} | ||
|
||
|
||
rules :: [Rule] | ||
rules = | ||
[ ruleNumeral | ||
, ruleTens | ||
, ruleCompositeTens | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.SW_XX (classifiers) where | ||
import Data.String | ||
import Prelude | ||
import qualified Data.HashMap.Strict as HashMap | ||
import Duckling.Ranking.Types | ||
|
||
classifiers :: Classifiers | ||
classifiers = HashMap.fromList [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 GADTs #-} | ||
|
||
|
||
module Duckling.Rules.SW | ||
( defaultRules | ||
, langRules | ||
, localeRules | ||
) where | ||
|
||
import Duckling.Dimensions.Types | ||
import Duckling.Locale | ||
import Duckling.Types | ||
import qualified Duckling.Numeral.SW.Rules as Numeral | ||
|
||
defaultRules :: Some Dimension -> [Rule] | ||
defaultRules = langRules | ||
|
||
localeRules :: Region -> Some Dimension -> [Rule] | ||
localeRules region (This (CustomDimension dim)) = dimLocaleRules region dim | ||
localeRules _ _ = [] | ||
|
||
langRules :: Some Dimension -> [Rule] | ||
langRules (This AmountOfMoney) = [] | ||
langRules (This CreditCardNumber) = [] | ||
langRules (This Distance) = [] | ||
langRules (This Duration) = [] | ||
langRules (This Email) = [] | ||
langRules (This Numeral) = Numeral.rules | ||
langRules (This Ordinal) = [] | ||
langRules (This PhoneNumber) = [] | ||
langRules (This Quantity) = [] | ||
langRules (This RegexMatch) = [] | ||
langRules (This Temperature) = [] | ||
langRules (This Time) = [] | ||
langRules (This TimeGrain) = [] | ||
langRules (This Url) = [] | ||
langRules (This Volume) = [] | ||
langRules (This (CustomDimension dim)) = dimLangRules SW dim |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.