Summary: Ordinal dimension for Hebrew.

Reviewed By: niteria

Differential Revision: D4930162

fbshipit-source-id: 02545ae
This commit is contained in:
Julien Odent 2017-04-24 06:27:00 -07:00 committed by Facebook Github Bot
parent bd96d3dd95
commit f5f4889770
7 changed files with 329 additions and 1 deletions

View File

@ -15,4 +15,5 @@ import Duckling.Dimensions.Types
allDimensions :: [Some Dimension]
allDimensions =
[ This Numeral
, This Ordinal
]

View File

@ -0,0 +1,29 @@
-- 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.Ordinal.HE.Corpus
( corpus ) where
import Prelude
import Data.String
import Duckling.Lang
import Duckling.Ordinal.Types
import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {lang = HE}, allExamples)
allExamples :: [Example]
allExamples = concat
[ examples (OrdinalData 4)
[ "ארבעה"
]
]

View File

@ -0,0 +1,270 @@
-- 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.Ordinal.HE.Rules
( rules ) where
import Data.Maybe
import Data.String
import Data.Text (Text)
import Prelude
import qualified Data.Text as Text
import Duckling.Dimensions.Types
import Duckling.Numeral.Helpers (parseInt)
import Duckling.Ordinal.Helpers
import Duckling.Ordinal.Types (OrdinalData (..))
import Duckling.Regex.Types
import Duckling.Types
import qualified Duckling.Ordinal.Types as TOrdinal
ruleOrdinal4 :: Rule
ruleOrdinal4 = Rule
{ name = "ordinal 4"
, pattern =
[ regex "(\x05d0\x05e8\x05d1\x05e2\x05d4|\x05e8\x05d1\x05d9\x05e2\x05d9)"
]
, prod = \_ -> Just $ ordinal 4
}
ruleOrdinal9 :: Rule
ruleOrdinal9 = Rule
{ name = "ordinal 9"
, pattern =
[ regex "(\x05ea\x05e9\x05e2\x05d4|\x05ea\x05e9\x05d9\x05e2\x05d9)"
]
, prod = \_ -> Just $ ordinal 9
}
ruleOrdinal10 :: Rule
ruleOrdinal10 = Rule
{ name = "ordinal 10"
, pattern =
[ regex "(\x05e2\x05e9\x05e8\x05d4|\x05e2\x05e9\x05d9\x05e8\x05d9)"
]
, prod = \_ -> Just $ ordinal 10
}
ruleOrdinal12 :: Rule
ruleOrdinal12 = Rule
{ name = "ordinal 12"
, pattern =
[ regex "(\x05e9\x05e0\x05d9\x05d9\x05dd \x05e2\x05e9\x05e8|\x05ea\x05e8\x05d9 \x05e2\x05e9\x05e8)"
]
, prod = \_ -> Just $ ordinal 12
}
ruleOrdinal17 :: Rule
ruleOrdinal17 = Rule
{ name = "ordinal 17"
, pattern =
[ regex "(\x05e9\x05d1\x05e2(\x05d4)? \x05e2\x05e9\x05e8(\x05d4)?)"
]
, prod = \_ -> Just $ ordinal 17
}
ruleOrdinal18 :: Rule
ruleOrdinal18 = Rule
{ name = "ordinal 18"
, pattern =
[ regex "(\x05e9\x05de\x05d5\x05e0\x05d4 \x05e2\x05e9\x05e8(\x05d4)?)"
]
, prod = \_ -> Just $ ordinal 18
}
ruleOrdinalDigits :: Rule
ruleOrdinalDigits = Rule
{ name = "ordinal (digits)"
, pattern =
[ regex "0*(\\d+) "
]
, prod = \tokens -> case tokens of
(Token RegexMatch (GroupMatch (match:_)):_) -> ordinal <$> parseInt match
_ -> Nothing
}
ruleOrdinal15 :: Rule
ruleOrdinal15 = Rule
{ name = "ordinal 15"
, pattern =
[ regex "(\x05d7\x05de\x05d9\x05e9\x05d4 \x05e2\x05e9\x05e8|\x05d7\x05de\x05e9 \x05e2\x05e9\x05e8\x05d4?)"
]
, prod = \_ -> Just $ ordinal 15
}
ruleOrdinal5 :: Rule
ruleOrdinal5 = Rule
{ name = "ordinal 5"
, pattern =
[ regex "(\x05d7\x05de\x05d9\x05e9\x05d9|\x05d7\x05de\x05d9\x05e9\x05d4)"
]
, prod = \_ -> Just $ ordinal 5
}
ruleOrdinal16 :: Rule
ruleOrdinal16 = Rule
{ name = "ordinal 16"
, pattern =
[ regex "(\x05e9\x05e9(\x05d4)? \x05e2\x05e9\x05e8(\x05d4)?)"
]
, prod = \_ -> Just $ ordinal 16
}
ruleOrdinal14 :: Rule
ruleOrdinal14 = Rule
{ name = "ordinal 14"
, pattern =
[ regex "(\x05d0\x05e8\x05d1\x05e2(\x05d4)? \x05e2\x05e9\x05e8(\x05d4)?)"
]
, prod = \_ -> Just $ ordinal 14
}
ruleOrdinal20 :: Rule
ruleOrdinal20 = Rule
{ name = "ordinal 20..90"
, pattern =
[ regex "(\x05e2\x05e9\x05e8\x05d9\x05dd|\x05e9\x05dc\x05d5\x05e9\x05d9\x05dd|\x05d0\x05e8\x05d1\x05e2\x05d9\x05dd|\x05d7\x05de\x05d9\x05e9\x05d9\x05dd|\x05e9\x05d9\x05e9\x05d9\x05dd|\x05e9\x05d1\x05e2\x05d9\x05dd|\x05e9\x05de\x05d5\x05e0\x05d9\x05dd|\x05ea\x05e9\x05e2\x05d9\x05dd)"
]
, prod = \tokens -> case tokens of
(Token RegexMatch (GroupMatch (match:_)):_) -> case match of
"\x05e2\x05e9\x05e8\x05d9\x05dd" -> Just $ ordinal 20
"\x05e9\x05dc\x05d5\x05e9\x05d9\x05dd" -> Just $ ordinal 30
"\x05d0\x05e8\x05d1\x05e2\x05d9\x05dd" -> Just $ ordinal 40
"\x05d7\x05de\x05d9\x05e9\x05d9\x05dd" -> Just $ ordinal 50
"\x05e9\x05d9\x05e9\x05d9\x05dd" -> Just $ ordinal 60
"\x05e9\x05d1\x05e2\x05d9\x05dd" -> Just $ ordinal 70
"\x05e9\x05de\x05d5\x05e0\x05d9\x05dd" -> Just $ ordinal 80
"\x05ea\x05e9\x05e2\x05d9\x05dd" -> Just $ ordinal 90
_ -> Nothing
_ -> Nothing
}
ruleOrdinal :: Rule
ruleOrdinal = Rule
{ name = "ordinal 1"
, pattern =
[ regex "(\x05d0\x05d7\x05d3|\x05e8\x05d0\x05e9\x05d5\x05df)"
]
, prod = \_ -> Just $ ordinal 1
}
ruleOrdinal13 :: Rule
ruleOrdinal13 = Rule
{ name = "ordinal 13"
, pattern =
[ regex "(\x05e9\x05dc\x05d5\x05e9(\x05d4)? \x05e2\x05e9\x05e8(\x05d4)?)"
]
, prod = \_ -> Just $ ordinal 13
}
ruleOrdinal7 :: Rule
ruleOrdinal7 = Rule
{ name = "ordinal 7"
, pattern =
[ regex "(\x05e9\x05d1\x05e2\x05d4|\x05e9\x05d1\x05d9\x05e2\x05d9)"
]
, prod = \_ -> Just $ ordinal 7
}
ruleOrdinal8 :: Rule
ruleOrdinal8 = Rule
{ name = "ordinal 8"
, pattern =
[ regex "(\x05e9\x05de\x05d5\x05e0\x05d4|\x05e9\x05de\x05d9\x05e0\x05d9)"
]
, prod = \_ -> Just $ ordinal 8
}
ruleOrdinal2 :: Rule
ruleOrdinal2 = Rule
{ name = "ordinal 2"
, pattern =
[ regex "(\x05e9\x05ea\x05d9\x05d9\x05dd|\x05e9\x05e0\x05d9\x05d9\x05dd|\x05e9\x05e0\x05d9)"
]
, prod = \_ -> Just $ ordinal 2
}
ruleOrdinal11 :: Rule
ruleOrdinal11 = Rule
{ name = "ordinal 11"
, pattern =
[ regex "(\x05d0\x05d7\x05d3 \x05e2\x05e9\x05e8(\x05d4)?)"
]
, prod = \_ -> Just $ ordinal 11
}
ruleOrdinal3 :: Rule
ruleOrdinal3 = Rule
{ name = "ordinal 3"
, pattern =
[ regex "(\x05e9\x05dc\x05d5\x05e9\x05d4|\x05e9\x05dc\x05d9\x05e9\x05d9)"
]
, prod = \_ -> Just $ ordinal 3
}
ruleOrdinal6 :: Rule
ruleOrdinal6 = Rule
{ name = "ordinal 6"
, pattern =
[ regex "(\x05e9\x05e9\x05d4|\x05e9\x05d9\x05e9\x05d9)"
]
, prod = \_ -> Just $ ordinal 6
}
ruleOrdinal19 :: Rule
ruleOrdinal19 = Rule
{ name = "ordinal 19"
, pattern =
[ regex "(\x05ea\x05e9\x05e2(\x05d4)? \x05e2\x05e9\x05e8(\x05d4)?)"
]
, prod = \_ -> Just $ ordinal 19
}
ruleCompositeWithAnd :: Rule
ruleCompositeWithAnd = Rule
{ name = "ordinal composition (with and)"
, pattern =
[ dimension Ordinal
, regex "\x05d5"
, dimension Ordinal
]
, prod = \tokens -> case tokens of
(Token Ordinal (OrdinalData {TOrdinal.value = v1}):
_:
Token Ordinal (OrdinalData {TOrdinal.value = v2}):
_) -> Just . ordinal $ v1 + v2
_ -> Nothing
}
rules :: [Rule]
rules =
[ ruleCompositeWithAnd
, ruleOrdinal
, ruleOrdinal10
, ruleOrdinal11
, ruleOrdinal12
, ruleOrdinal13
, ruleOrdinal14
, ruleOrdinal15
, ruleOrdinal16
, ruleOrdinal17
, ruleOrdinal18
, ruleOrdinal19
, ruleOrdinal2
, ruleOrdinal20
, ruleOrdinal3
, ruleOrdinal4
, ruleOrdinal5
, ruleOrdinal6
, ruleOrdinal7
, ruleOrdinal8
, ruleOrdinal9
, ruleOrdinalDigits
]

View File

@ -16,6 +16,7 @@ module Duckling.Rules.HE
import Duckling.Dimensions.Types
import Duckling.Types
import qualified Duckling.Numeral.HE.Rules as Numeral
import qualified Duckling.Ordinal.HE.Rules as Ordinal
rules :: Some Dimension -> [Rule]
rules (This Distance) = []
@ -23,7 +24,7 @@ rules (This Duration) = []
rules (This Numeral) = Numeral.rules
rules (This Email) = []
rules (This AmountOfMoney) = []
rules (This Ordinal) = []
rules (This Ordinal) = Ordinal.rules
rules (This PhoneNumber) = []
rules (This Quantity) = []
rules (This RegexMatch) = []

View File

@ -281,6 +281,8 @@ library
, Duckling.Ordinal.FR.Rules
, Duckling.Ordinal.GA.Corpus
, Duckling.Ordinal.GA.Rules
, Duckling.Ordinal.HE.Corpus
, Duckling.Ordinal.HE.Rules
, Duckling.Ordinal.ID.Corpus
, Duckling.Ordinal.ID.Rules
, Duckling.Ordinal.IT.Corpus
@ -572,6 +574,7 @@ test-suite duckling-test
, Duckling.Ordinal.ET.Tests
, Duckling.Ordinal.FR.Tests
, Duckling.Ordinal.GA.Tests
, Duckling.Ordinal.HE.Tests
, Duckling.Ordinal.ID.Tests
, Duckling.Ordinal.IT.Tests
, Duckling.Ordinal.JA.Tests

View 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.Ordinal.HE.Tests
( tests ) where
import Data.String
import Prelude
import Test.Tasty
import Duckling.Dimensions.Types
import Duckling.Ordinal.HE.Corpus
import Duckling.Testing.Asserts
tests :: TestTree
tests = testGroup "HE Tests"
[ makeCorpusTest [This Ordinal] corpus
]

View File

@ -19,6 +19,7 @@ import qualified Duckling.Ordinal.EN.Tests as EN
import qualified Duckling.Ordinal.ET.Tests as ET
import qualified Duckling.Ordinal.FR.Tests as FR
import qualified Duckling.Ordinal.GA.Tests as GA
import qualified Duckling.Ordinal.HE.Tests as HE
import qualified Duckling.Ordinal.ID.Tests as ID
import qualified Duckling.Ordinal.IT.Tests as IT
import qualified Duckling.Ordinal.JA.Tests as JA
@ -43,6 +44,7 @@ tests = testGroup "Ordinal Tests"
, ET.tests
, FR.tests
, GA.tests
, HE.tests
, ID.tests
, IT.tests
, JA.tests