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.
Hindi Language Numeral Dimension(minimalistic model). Tests passed.
Summary: Closes facebook#119 Reviewed By: JonCoens Differential Revision: D6597628 Pulled By: patapizza fbshipit-source-id: 8bac0f686d6cecc38d9998e37042fe48f73530dc
- Loading branch information
1 parent
15b3988
commit c133bad
Showing
14 changed files
with
381 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.stack-work/ | ||
log/ | ||
.idea/ |
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.HI | ||
( 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 |
---|---|---|
|
@@ -43,6 +43,7 @@ data Lang | |
| FR | ||
| GA | ||
| HE | ||
| HI | ||
| HR | ||
| HU | ||
| ID | ||
|
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.HI.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 HI Nothing}, allExamples) | ||
|
||
allExamples :: [Example] | ||
allExamples = concat | ||
[ examples (NumeralValue 0) | ||
[ "शून्य" | ||
, "०" | ||
] | ||
, examples (NumeralValue 1) | ||
[ "एक" | ||
] | ||
, examples (NumeralValue 2) | ||
[ "दो" | ||
] | ||
, examples (NumeralValue 3) | ||
[ "तीन" | ||
] | ||
, examples (NumeralValue 4) | ||
[ "चार" | ||
] | ||
, examples (NumeralValue 5) | ||
[ "पाँच" | ||
] | ||
, examples (NumeralValue 6) | ||
[ "छह" | ||
] | ||
, examples (NumeralValue 7) | ||
[ "सात" | ||
] | ||
, examples (NumeralValue 8) | ||
[ "आठ" | ||
] | ||
, examples (NumeralValue 9) | ||
[ "नौ" | ||
] | ||
, examples (NumeralValue 10) | ||
[ "दस" | ||
] | ||
, examples (NumeralValue 15) | ||
[ "पन्द्रह" | ||
] | ||
, examples (NumeralValue 17) | ||
[ "सत्रह" | ||
] | ||
, examples (NumeralValue 20) | ||
[ "बीस" | ||
] | ||
, examples (NumeralValue 22) | ||
[ "बाईस" | ||
] | ||
, examples (NumeralValue 24) | ||
[ "चौबीस" | ||
] | ||
, examples (NumeralValue 26) | ||
[ "छब्बीस" | ||
] | ||
, examples (NumeralValue 28) | ||
[ "अट्ठाईस" | ||
] | ||
, examples (NumeralValue 50) | ||
[ "५०" | ||
, "पचास" | ||
] | ||
] |
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,170 @@ | ||
-- 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.HI.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 | ||
|
||
devanagariMap :: HashMap Char Char | ||
devanagariMap = HashMap.fromList | ||
[ ( '०', '0' ) | ||
, ( '१', '1' ) | ||
, ( '२', '2' ) | ||
, ( '३', '3' ) | ||
, ( '४', '4' ) | ||
, ( '५', '5' ) | ||
, ( '६', '6' ) | ||
, ( '७', '7' ) | ||
, ( '८', '8' ) | ||
, ( '९', '9' ) | ||
] | ||
|
||
devanagariToArab :: Char -> Char | ||
devanagariToArab c = HashMap.lookupDefault c c devanagariMap | ||
|
||
ruleDevanagari :: Rule | ||
ruleDevanagari = Rule | ||
{ name = "devanagari forms" | ||
, pattern = | ||
[ regex "([०१२३४५६७८९]{1,18})" | ||
] | ||
, prod = \tokens -> case tokens of | ||
(Token RegexMatch (GroupMatch (match:_)):_) -> | ||
toInteger <$> parseInt (Text.map devanagariToArab match) >>= integer | ||
_ -> 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 match ruleNumeralMap >>= integer | ||
_ -> Nothing | ||
} | ||
|
||
elevenToNineteenMap :: HashMap Text Integer | ||
elevenToNineteenMap = HashMap.fromList | ||
[ ( "ग्यारह", 11 ) | ||
, ( "बारह", 12 ) | ||
, ( "तेरह", 13 ) | ||
, ( "चौदह", 14 ) | ||
, ( "पन्द्रह", 15 ) | ||
, ( "सोलह", 16 ) | ||
, ( "सत्रह", 17 ) | ||
, ( "अठारह", 18 ) | ||
, ( "उन्नीस", 19 ) | ||
] | ||
|
||
ruleElevenToNineteen :: Rule | ||
ruleElevenToNineteen = Rule | ||
{ name = "number (11..19)" | ||
, pattern = | ||
[ regex "(ग्यारह|बारह|तेरह|चौदह|पन्द्रह|सोलह|सत्रह|अठारह|उन्नीस)" | ||
] | ||
, prod = \tokens -> case tokens of | ||
(Token RegexMatch (GroupMatch (match:_)):_) -> | ||
HashMap.lookup match elevenToNineteenMap >>= integer | ||
_ -> Nothing | ||
} | ||
|
||
twentyoneToTwentynineMap :: HashMap Text Integer | ||
twentyoneToTwentynineMap = HashMap.fromList | ||
[ ( "इक्कीस", 21 ) | ||
, ( "बाईस", 22 ) | ||
, ( "तेईस", 23 ) | ||
, ( "चौबीस", 24 ) | ||
, ( "पच्चीस", 25 ) | ||
, ( "छब्बीस", 26 ) | ||
, ( "सत्ताईस", 27 ) | ||
, ( "अट्ठाईस", 28 ) | ||
, ( "उनतीस", 29 ) | ||
] | ||
|
||
ruleTwentyoneToTwentynine :: Rule | ||
ruleTwentyoneToTwentynine = Rule | ||
{ name = "number (21..29)" | ||
, pattern = | ||
[ regex "(इक्कीस|बाईस|तेईस|चौबीस|पच्चीस|छब्बीस|सत्ताईस|अट्ठाईस|उनतीस)" | ||
] | ||
, prod = \tokens -> case tokens of | ||
(Token RegexMatch (GroupMatch (match:_)):_) -> | ||
HashMap.lookup match twentyoneToTwentynineMap >>= integer | ||
_ -> Nothing | ||
} | ||
|
||
tensMap :: HashMap Text Integer | ||
tensMap = HashMap.fromList | ||
[ ( "बीस", 20 ) | ||
, ( "तीस", 30 ) | ||
, ( "चालीस", 40 ) | ||
, ( "पचास", 50 ) | ||
, ( "साठ", 60 ) | ||
, ( "सत्तर", 70 ) | ||
, ( "अस्सी", 80 ) | ||
, ( "नब्बे", 90 ) | ||
] | ||
|
||
ruleTens :: Rule | ||
ruleTens = Rule | ||
{ name = "integer (20,30..90)" | ||
, pattern = | ||
[ regex "(बीस|तीस|चालीस|पचास|साठ|सत्तर|अस्सी|नब्बे)" | ||
] | ||
, prod = \tokens -> case tokens of | ||
(Token RegexMatch (GroupMatch (match:_)):_) -> | ||
HashMap.lookup match tensMap >>= integer | ||
_ -> Nothing | ||
} | ||
|
||
|
||
rules :: [Rule] | ||
rules = | ||
[ ruleDevanagari | ||
, ruleNumeral | ||
, ruleElevenToNineteen | ||
, ruleTwentyoneToTwentynine | ||
, ruleTens | ||
] |
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.HI_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
Oops, something went wrong.