-
Notifications
You must be signed in to change notification settings - Fork 728
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: - Setup Hungarian (HU) language - Added Numeral Dimension Closes #79 Reviewed By: blandinw Differential Revision: D5595812 Pulled By: patapizza fbshipit-source-id: 5959938
- Loading branch information
1 parent
5d03b45
commit 24d3f19
Showing
13 changed files
with
379 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.HU | ||
( 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 |
---|---|---|
|
@@ -34,6 +34,7 @@ data Lang | |
| GA | ||
| HE | ||
| HR | ||
| HU | ||
| ID | ||
| IT | ||
| JA | ||
|
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,98 @@ | ||
-- 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.HU.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 = HU}, allExamples) | ||
|
||
allExamples :: [Example] | ||
allExamples = concat | ||
[ examples (NumeralValue 0) | ||
[ "0" | ||
, "nulla" | ||
, "zéró" | ||
] | ||
, examples (NumeralValue 1) | ||
[ "1" | ||
, "egy" | ||
] | ||
, examples (NumeralValue 2) | ||
[ "kettő" | ||
] | ||
, examples (NumeralValue 3) | ||
[ "három" | ||
] | ||
, examples (NumeralValue 4) | ||
[ "négy" | ||
] | ||
, examples (NumeralValue 5) | ||
[ "öt" | ||
] | ||
, examples (NumeralValue 6) | ||
[ "hat" | ||
] | ||
, examples (NumeralValue 7) | ||
[ "hét" | ||
] | ||
, examples (NumeralValue 8) | ||
[ "nyolc" | ||
] | ||
, examples (NumeralValue 9) | ||
[ "kilenc" | ||
] | ||
, examples (NumeralValue 11) | ||
[ "tizenegy" | ||
] | ||
, examples (NumeralValue 15) | ||
[ "tizenöt" | ||
] | ||
, examples (NumeralValue 17) | ||
[ "tizenhét" | ||
] | ||
, examples (NumeralValue 20) | ||
[ "20" | ||
, "húsz" | ||
] | ||
, examples (NumeralValue 22) | ||
[ "huszonkettő" | ||
] | ||
, examples (NumeralValue 24) | ||
[ "24" | ||
, "huszonnégy" | ||
] | ||
, examples (NumeralValue 26) | ||
[ "huszonhat" | ||
] | ||
, examples (NumeralValue 28) | ||
[ "huszonnyolc" | ||
] | ||
, examples (NumeralValue 10) | ||
[ "tíz" | ||
] | ||
, examples (NumeralValue 20) | ||
[ "húsz" | ||
] | ||
, examples (NumeralValue 50) | ||
[ "ötven" | ||
] | ||
, examples (NumeralValue 34) | ||
[ "harmincnégy" | ||
] | ||
] |
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,169 @@ | ||
-- 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.HU.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 | ||
[ ( "nulla", 0 ) | ||
, ( "z\x00E9r\x00F3", 0 ) | ||
, ( "egy", 1 ) | ||
, ( "kett\x0151", 2 ) | ||
, ( "h\x00E1rom", 3 ) | ||
, ( "n\x00E9gy", 4 ) | ||
, ( "\x00F6t", 5) | ||
, ( "hat", 6) | ||
, ( "h\x00E9t", 7) | ||
, ( "nyolc", 8) | ||
, ( "kilenc", 9) | ||
, ( "t\x00EDz", 10) | ||
] | ||
|
||
ruleNumeral :: Rule | ||
ruleNumeral = Rule | ||
{ name = "number (0..10)" | ||
, pattern = | ||
[ regex "(nulla|z\x00E9r\x00F3|egy|kett\x0151|h\x00E1rom|n\x00E9gy|\x00F6t|hat|h\x00E9t|nyolc|kilenc|t\x00EDz)" | ||
] | ||
, prod = \tokens -> case tokens of | ||
(Token RegexMatch (GroupMatch (match:_)):_) -> | ||
HashMap.lookup (Text.toLower match) ruleNumeralMap >>= integer | ||
_ -> Nothing | ||
} | ||
|
||
elevenToNineteenMap :: HashMap Text Integer | ||
elevenToNineteenMap = HashMap.fromList | ||
[ ( "tizenegy", 11 ) | ||
, ( "tizenkett\x0151", 12 ) | ||
, ( "tizenh\x00E1rom", 13 ) | ||
, ( "tizenn\x00E9gy", 14 ) | ||
, ( "tizen\x00F6t", 15 ) | ||
, ( "tizenhat", 16 ) | ||
, ( "tizenh\x00E9t", 17 ) | ||
, ( "tizennyolc", 18 ) | ||
, ( "tizenkilenc", 19 ) | ||
] | ||
|
||
ruleElevenToNineteen :: Rule | ||
ruleElevenToNineteen = Rule | ||
{ name = "number (11..19)" | ||
, pattern = | ||
[ regex "(tizenegy|tizenkett\x0151|tizenh\x00E1rom|tizenn\x00E9gy|tizen\x00F6t|tizenhat|tizenh\x00E9t|tizennyolc|tizenkilenc)" | ||
] | ||
, prod = \tokens -> case tokens of | ||
(Token RegexMatch (GroupMatch (match:_)):_) -> | ||
HashMap.lookup (Text.toLower match) elevenToNineteenMap >>= integer | ||
_ -> Nothing | ||
} | ||
|
||
twentyoneToTwentynineMap :: HashMap Text Integer | ||
twentyoneToTwentynineMap = HashMap.fromList | ||
[ ( "huszonegy", 21 ) | ||
, ( "huszonkett\x0151", 22 ) | ||
, ( "huszonh\x00E1rom", 23 ) | ||
, ( "huszonn\x00E9gy", 24 ) | ||
, ( "huszon\x00F6t", 25 ) | ||
, ( "huszonhat", 26 ) | ||
, ( "huszonh\x00E9t", 27 ) | ||
, ( "huszonnyolc", 28 ) | ||
, ( "huszonkilenc", 29 ) | ||
] | ||
|
||
ruleTwentyoneToTwentynine :: Rule | ||
ruleTwentyoneToTwentynine = Rule | ||
{ name = "number (21..29)" | ||
, pattern = | ||
[ regex "(huszonegy|huszonkett\x0151|huszonh\x00E1rom|huszonn\x00E9gy|huszon\x00F6t|huszonhat|huszonh\x00E9t|huszonnyolc|huszonkilenc)" | ||
] | ||
, prod = \tokens -> case tokens of | ||
(Token RegexMatch (GroupMatch (match:_)):_) -> | ||
HashMap.lookup (Text.toLower match) twentyoneToTwentynineMap >>= integer | ||
_ -> Nothing | ||
} | ||
|
||
dozensMap :: HashMap Text Integer | ||
dozensMap = HashMap.fromList | ||
[ ( "h\x00FAsz", 20 ) | ||
, ( "harminc", 30 ) | ||
, ( "negyven", 40 ) | ||
, ( "\x00F6tven", 50 ) | ||
, ( "hatvan", 60 ) | ||
, ( "hetven", 70 ) | ||
, ( "nyolcvan", 80 ) | ||
, ( "kilencven", 90 ) | ||
] | ||
|
||
ruleTens :: Rule | ||
ruleTens = Rule | ||
{ name = "integer (20,30..90)" | ||
, pattern = | ||
[ regex "(h\x00FAsz|harminc|negyven|\x00f6tven|hatvan|hetven|nyolcvan|kilencven)" | ||
] | ||
, prod = \tokens -> case tokens of | ||
(Token RegexMatch (GroupMatch (match:_)):_) -> | ||
HashMap.lookup (Text.toLower match) dozensMap >>= integer | ||
_ -> Nothing | ||
} | ||
|
||
ruleCompositeTens :: Rule | ||
ruleCompositeTens = Rule | ||
{ name = "integer ([3-9][1-9])" | ||
, pattern = | ||
[ regex "(harminc|negyven|\x00F6tven|hatvan|hetven|nyolcvan|kilencven)(egy|kett\x0151|h\x00E1rom|n\x00E9gy|\x00F6t|hat|h\x00E9t|nyolc|kilenc)" | ||
] | ||
, prod = \tokens -> case tokens of | ||
(Token RegexMatch (GroupMatch (m1:m2:_)):_) -> do | ||
v1 <- HashMap.lookup (Text.toLower m1) dozensMap | ||
v2 <- HashMap.lookup (Text.toLower m2) ruleNumeralMap | ||
integer $ v1 + v2 | ||
_ -> Nothing | ||
} | ||
|
||
rules :: [Rule] | ||
rules = | ||
[ ruleIntegerNumeric | ||
, ruleNumeral | ||
, ruleElevenToNineteen | ||
, ruleTwentyoneToTwentynine | ||
, 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.HU (classifiers) where | ||
import Prelude | ||
import Duckling.Ranking.Types | ||
import qualified Data.HashMap.Strict as HashMap | ||
import Data.String | ||
|
||
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.