{-# 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
ruleOrdinal4 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"ordinal 4"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"(ארבעה|רביעי)"
]
, prod :: Production
prod = \[Token]
_ -> Token -> Maybe Token
forall a. a -> Maybe a
Just (Token -> Maybe Token) -> Token -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Token
ordinal Int
4
}
ruleOrdinal9 :: Rule
ruleOrdinal9 :: Rule
ruleOrdinal9 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"ordinal 9"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"(תשעה|תשיעי)"
]
, prod :: Production
prod = \[Token]
_ -> Token -> Maybe Token
forall a. a -> Maybe a
Just (Token -> Maybe Token) -> Token -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Token
ordinal Int
9
}
ruleOrdinal10 :: Rule
ruleOrdinal10 :: Rule
ruleOrdinal10 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"ordinal 10"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"(עשרה|עשירי)"
]
, prod :: Production
prod = \[Token]
_ -> Token -> Maybe Token
forall a. a -> Maybe a
Just (Token -> Maybe Token) -> Token -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Token
ordinal Int
10
}
ruleOrdinal12 :: Rule
ruleOrdinal12 :: Rule
ruleOrdinal12 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"ordinal 12"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"(שניים עשר|תרי עשר)"
]
, prod :: Production
prod = \[Token]
_ -> Token -> Maybe Token
forall a. a -> Maybe a
Just (Token -> Maybe Token) -> Token -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Token
ordinal Int
12
}
ruleOrdinal17 :: Rule
ruleOrdinal17 :: Rule
ruleOrdinal17 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"ordinal 17"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"(שבע(ה)? עשר(ה)?)"
]
, prod :: Production
prod = \[Token]
_ -> Token -> Maybe Token
forall a. a -> Maybe a
Just (Token -> Maybe Token) -> Token -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Token
ordinal Int
17
}
ruleOrdinal18 :: Rule
ruleOrdinal18 :: Rule
ruleOrdinal18 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"ordinal 18"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"(שמונה עשר(ה)?)"
]
, prod :: Production
prod = \[Token]
_ -> Token -> Maybe Token
forall a. a -> Maybe a
Just (Token -> Maybe Token) -> Token -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Token
ordinal Int
18
}
ruleOrdinalDigits :: Rule
ruleOrdinalDigits :: Rule
ruleOrdinalDigits = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"ordinal (digits)"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"0*(\\d+) "
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(Token Dimension a
RegexMatch (GroupMatch (match:_)):[Token]
_) -> Int -> Token
ordinal (Int -> Token) -> Maybe Int -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> Maybe Int
parseInt Text
match
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleOrdinal15 :: Rule
ruleOrdinal15 :: Rule
ruleOrdinal15 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"ordinal 15"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"(חמישה עשר|חמש עשרה?)"
]
, prod :: Production
prod = \[Token]
_ -> Token -> Maybe Token
forall a. a -> Maybe a
Just (Token -> Maybe Token) -> Token -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Token
ordinal Int
15
}
ruleOrdinal5 :: Rule
ruleOrdinal5 :: Rule
ruleOrdinal5 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"ordinal 5"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"(חמישי|חמישה)"
]
, prod :: Production
prod = \[Token]
_ -> Token -> Maybe Token
forall a. a -> Maybe a
Just (Token -> Maybe Token) -> Token -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Token
ordinal Int
5
}
ruleOrdinal16 :: Rule
ruleOrdinal16 :: Rule
ruleOrdinal16 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"ordinal 16"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"(שש(ה)? עשר(ה)?)"
]
, prod :: Production
prod = \[Token]
_ -> Token -> Maybe Token
forall a. a -> Maybe a
Just (Token -> Maybe Token) -> Token -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Token
ordinal Int
16
}
ruleOrdinal14 :: Rule
ruleOrdinal14 :: Rule
ruleOrdinal14 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"ordinal 14"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"(ארבע(ה)? עשר(ה)?)"
]
, prod :: Production
prod = \[Token]
_ -> Token -> Maybe Token
forall a. a -> Maybe a
Just (Token -> Maybe Token) -> Token -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Token
ordinal Int
14
}
ruleOrdinal20 :: Rule
ruleOrdinal20 :: Rule
ruleOrdinal20 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"ordinal 20..90"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"(עשרים|שלושים|ארבעים|חמישים|שישים|שבעים|שמונים|תשעים)"
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(Token Dimension a
RegexMatch (GroupMatch (match:_)):[Token]
_) -> case Text
match of
Text
"עשרים" -> Token -> Maybe Token
forall a. a -> Maybe a
Just (Token -> Maybe Token) -> Token -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Token
ordinal Int
20
Text
"שלושים" -> Token -> Maybe Token
forall a. a -> Maybe a
Just (Token -> Maybe Token) -> Token -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Token
ordinal Int
30
Text
"ארבעים" -> Token -> Maybe Token
forall a. a -> Maybe a
Just (Token -> Maybe Token) -> Token -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Token
ordinal Int
40
Text
"חמישים" -> Token -> Maybe Token
forall a. a -> Maybe a
Just (Token -> Maybe Token) -> Token -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Token
ordinal Int
50
Text
"שישים" -> Token -> Maybe Token
forall a. a -> Maybe a
Just (Token -> Maybe Token) -> Token -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Token
ordinal Int
60
Text
"שבעים" -> Token -> Maybe Token
forall a. a -> Maybe a
Just (Token -> Maybe Token) -> Token -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Token
ordinal Int
70
Text
"שמונים" -> Token -> Maybe Token
forall a. a -> Maybe a
Just (Token -> Maybe Token) -> Token -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Token
ordinal Int
80
Text
"תשעים" -> Token -> Maybe Token
forall a. a -> Maybe a
Just (Token -> Maybe Token) -> Token -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Token
ordinal Int
90
Text
_ -> Maybe Token
forall a. Maybe a
Nothing
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
ruleOrdinal :: Rule
ruleOrdinal :: Rule
ruleOrdinal = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"ordinal 1"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"(אחד|ראשון)"
]
, prod :: Production
prod = \[Token]
_ -> Token -> Maybe Token
forall a. a -> Maybe a
Just (Token -> Maybe Token) -> Token -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Token
ordinal Int
1
}
ruleOrdinal13 :: Rule
ruleOrdinal13 :: Rule
ruleOrdinal13 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"ordinal 13"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"(שלוש(ה)? עשר(ה)?)"
]
, prod :: Production
prod = \[Token]
_ -> Token -> Maybe Token
forall a. a -> Maybe a
Just (Token -> Maybe Token) -> Token -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Token
ordinal Int
13
}
ruleOrdinal7 :: Rule
ruleOrdinal7 :: Rule
ruleOrdinal7 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"ordinal 7"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"(שבעה|שביעי)"
]
, prod :: Production
prod = \[Token]
_ -> Token -> Maybe Token
forall a. a -> Maybe a
Just (Token -> Maybe Token) -> Token -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Token
ordinal Int
7
}
ruleOrdinal8 :: Rule
ruleOrdinal8 :: Rule
ruleOrdinal8 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"ordinal 8"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"(שמונה|שמיני)"
]
, prod :: Production
prod = \[Token]
_ -> Token -> Maybe Token
forall a. a -> Maybe a
Just (Token -> Maybe Token) -> Token -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Token
ordinal Int
8
}
ruleOrdinal2 :: Rule
ruleOrdinal2 :: Rule
ruleOrdinal2 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"ordinal 2"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"(שתיים|שניים|שני)"
]
, prod :: Production
prod = \[Token]
_ -> Token -> Maybe Token
forall a. a -> Maybe a
Just (Token -> Maybe Token) -> Token -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Token
ordinal Int
2
}
ruleOrdinal11 :: Rule
ruleOrdinal11 :: Rule
ruleOrdinal11 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"ordinal 11"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"(אחד עשר(ה)?)"
]
, prod :: Production
prod = \[Token]
_ -> Token -> Maybe Token
forall a. a -> Maybe a
Just (Token -> Maybe Token) -> Token -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Token
ordinal Int
11
}
ruleOrdinal3 :: Rule
ruleOrdinal3 :: Rule
ruleOrdinal3 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"ordinal 3"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"(שלושה|שלישי)"
]
, prod :: Production
prod = \[Token]
_ -> Token -> Maybe Token
forall a. a -> Maybe a
Just (Token -> Maybe Token) -> Token -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Token
ordinal Int
3
}
ruleOrdinal6 :: Rule
ruleOrdinal6 :: Rule
ruleOrdinal6 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"ordinal 6"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"(ששה|שישי)"
]
, prod :: Production
prod = \[Token]
_ -> Token -> Maybe Token
forall a. a -> Maybe a
Just (Token -> Maybe Token) -> Token -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Token
ordinal Int
6
}
ruleOrdinal19 :: Rule
ruleOrdinal19 :: Rule
ruleOrdinal19 = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"ordinal 19"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"(תשע(ה)? עשר(ה)?)"
]
, prod :: Production
prod = \[Token]
_ -> Token -> Maybe Token
forall a. a -> Maybe a
Just (Token -> Maybe Token) -> Token -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Token
ordinal Int
19
}
ruleCompositeWithAnd :: Rule
ruleCompositeWithAnd :: Rule
ruleCompositeWithAnd = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"ordinal composition (with and)"
, pattern :: Pattern
pattern =
[ Dimension OrdinalData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension OrdinalData
Ordinal
, String -> PatternItem
regex String
"ו"
, Dimension OrdinalData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension OrdinalData
Ordinal
]
, prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
(Token Dimension a
Ordinal OrdinalData{TOrdinal.value = v1}:
Token
_:
Token Dimension a
Ordinal OrdinalData{TOrdinal.value = v2}:
[Token]
_) -> Token -> Maybe Token
forall a. a -> Maybe a
Just (Token -> Maybe Token) -> (Int -> Token) -> Int -> Maybe Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Token
ordinal (Int -> Maybe Token) -> Int -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int
v1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
v2
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
rules :: [Rule]
rules :: [Rule]
rules =
[ Rule
ruleCompositeWithAnd
, Rule
ruleOrdinal
, Rule
ruleOrdinal10
, Rule
ruleOrdinal11
, Rule
ruleOrdinal12
, Rule
ruleOrdinal13
, Rule
ruleOrdinal14
, Rule
ruleOrdinal15
, Rule
ruleOrdinal16
, Rule
ruleOrdinal17
, Rule
ruleOrdinal18
, Rule
ruleOrdinal19
, Rule
ruleOrdinal2
, Rule
ruleOrdinal20
, Rule
ruleOrdinal3
, Rule
ruleOrdinal4
, Rule
ruleOrdinal5
, Rule
ruleOrdinal6
, Rule
ruleOrdinal7
, Rule
ruleOrdinal8
, Rule
ruleOrdinal9
, Rule
ruleOrdinalDigits
]