-- 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.


{-# LANGUAGE GADTs #-}
{-# LANGUAGE OverloadedStrings #-}

module Duckling.Ordinal.PL.Rules
  ( rules ) where

import Prelude
import Data.String

import Duckling.Dimensions.Types
import Duckling.Numeral.Helpers (parseInt)
import Duckling.Ordinal.Helpers
import Duckling.Ordinal.Types (OrdinalData (..))
import qualified Duckling.Ordinal.Types as TOrdinal
import Duckling.Regex.Types
import Duckling.Types

ruleThOrdinalNoSpace :: Rule
ruleThOrdinalNoSpace :: Rule
ruleThOrdinalNoSpace = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"24th ordinal no space"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"dwudziest(ym|y|ego|emu|(a|ą)|ej)czwart(y|ego|emu|ym|(a|ą)|ej)"
    ]
  , 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
24
  }

ruleThOrdinal16 :: Rule
ruleThOrdinal16 :: Rule
ruleThOrdinal16 = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"31-39th ordinal"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"trzydziest(ym|y|ego|emu|(a|ą)|ej)( |-)?"
    , Dimension OrdinalData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension OrdinalData
Ordinal
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Ordinal OrdinalData{TOrdinal.value = v}:[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
30 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
v
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleThOrdinal3 :: Rule
ruleThOrdinal3 :: Rule
ruleThOrdinal3 = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"10th ordinal"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"dziesi(a|ą)t(ym|y|ego|emu|(a|ą)|ej)"
    ]
  , 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
  }

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+)( |-)?(szy|sza|szym|ego|go|szego|gi(ego|ej)?|st(a|y|ej)|t(ej|y|ego)|ci(ego)?)"
    ]
  , 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
  }

ruleThOrdinal8 :: Rule
ruleThOrdinal8 :: Rule
ruleThOrdinal8 = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"15th ordinal"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"pi(e|ę)tnast(ym|y|ego|emu|(a|ą)|ej)"
    ]
  , 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
  }

ruleThOrdinal13 :: Rule
ruleThOrdinal13 :: Rule
ruleThOrdinal13 = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"20th ordinal"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"dwudziest(ym|y|ego|emu|(a|ą)|ej)"
    ]
  , 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
20
  }

ruleThOrdinal4 :: Rule
ruleThOrdinal4 :: Rule
ruleThOrdinal4 = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"11th ordinal"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"jedenast(ym|y|ego|emu|(a|ą)|ej)"
    ]
  , 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
  }

ruleFifthOrdinal :: Rule
ruleFifthOrdinal :: Rule
ruleFifthOrdinal = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"fifth ordinal"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"pi(a|ą)t(y|ego|emu|m|(a|ą)|ej)"
    ]
  , 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
  }

ruleThOrdinal11 :: Rule
ruleThOrdinal11 :: Rule
ruleThOrdinal11 = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"18th ordinal"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"osiemnast(ym|y|ego|emu|(a|ą)|ej)"
    ]
  , 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
  }

ruleSecondOrdinal :: Rule
ruleSecondOrdinal :: Rule
ruleSecondOrdinal = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"second ordinal"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"drugi?(ego|emu|m|(a|ą)|ej)?"
    ]
  , 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
  }

ruleNdOrdinalNoSpace :: Rule
ruleNdOrdinalNoSpace :: Rule
ruleNdOrdinalNoSpace = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"22nd ordinal no space"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"dwudziest(ym|y|ego|emu|(a|ą)|ej)drugi?(ego|emu|m|(a|ą)|ej)?"
    ]
  , 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
22
  }

ruleSeventhOrdinal :: Rule
ruleSeventhOrdinal :: Rule
ruleSeventhOrdinal = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"seventh ordinal"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"si(o|ó)dm(y|ego|emu|m|(a|ą)|ej)"
    ]
  , 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
  }

ruleStOrdinalNoSpace :: Rule
ruleStOrdinalNoSpace :: Rule
ruleStOrdinalNoSpace = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"21st ordinal no space"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"dwudziest(ym|y|ego|emu|(a|ą)|ej)pierw?sz(y|ego|emu|m|(a|ą)|ej)"
    ]
  , 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
21
  }

ruleThOrdinal7 :: Rule
ruleThOrdinal7 :: Rule
ruleThOrdinal7 = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"14th ordinal"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"czternast(ym|y|ego|emu|(a|ą)|ej)"
    ]
  , 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
  }

ruleThOrdinal2 :: Rule
ruleThOrdinal2 :: Rule
ruleThOrdinal2 = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"9th ordinal"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"dziewi(a|ą)t(ym|y|ego|em|emu|(a|ą)|ej)"
    ]
  , 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
  }

ruleThOrdinal9 :: Rule
ruleThOrdinal9 :: Rule
ruleThOrdinal9 = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"16th ordinal"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"szesnast(ym|y|ego|emu|(a|ą)|ej)"
    ]
  , 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
  }

ruleThOrdinal :: Rule
ruleThOrdinal :: Rule
ruleThOrdinal = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"8th ordinal"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"(o|ó|Ó)sm(y|ego|emu|m|(a|ą)|ej)"
    ]
  , 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
  }

ruleThOrdinal14 :: Rule
ruleThOrdinal14 :: Rule
ruleThOrdinal14 = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"21-29th ordinal"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"dwudziest(ym|y|ego|emu|(a|ą)|ej)( |-)?"
    , Dimension OrdinalData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension OrdinalData
Ordinal
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Ordinal OrdinalData{TOrdinal.value = v}:[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
20 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
v
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleThOrdinal10 :: Rule
ruleThOrdinal10 :: Rule
ruleThOrdinal10 = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"17th ordinal"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"siedemnast(ym|y|ego|emu|(a|ą)|ej)"
    ]
  , 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
  }

ruleRdOrdinalNoSpace :: Rule
ruleRdOrdinalNoSpace :: Rule
ruleRdOrdinalNoSpace = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"23rd ordinal no space"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"dwudziest(ym|y|ego|emu|(a|ą)|ej)trzeci(ego|ch|emu|m|mi|ej|(a|ą))?"
    ]
  , 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
23
  }

ruleThOrdinal5 :: Rule
ruleThOrdinal5 :: Rule
ruleThOrdinal5 = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"12th ordinal"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"dwunast(ym|y|ego|emu|(a|ą)|ej)"
    ]
  , 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
  }

ruleThOrdinal6 :: Rule
ruleThOrdinal6 :: Rule
ruleThOrdinal6 = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"13th ordinal"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"trzynast(ym|y|ego|emu|(a|ą)|ej)"
    ]
  , 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
  }

ruleFirstOrdinal :: Rule
ruleFirstOrdinal :: Rule
ruleFirstOrdinal = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"first ordinal"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"pierw?sz(y|ego|emu|m|(a|ą)|ej)"
    ]
  , 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
  }

ruleSixthOrdinal :: Rule
ruleSixthOrdinal :: Rule
ruleSixthOrdinal = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"sixth ordinal"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"sz(o|ó)st(y|ego|emu|m|(a|ą)|ej)"
    ]
  , 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
  }

ruleFourthOrdinal :: Rule
ruleFourthOrdinal :: Rule
ruleFourthOrdinal = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"fourth ordinal"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"czwart(y|ego|emu|ym|(a|ą)|ej)"
    ]
  , 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
  }

ruleThOrdinal15 :: Rule
ruleThOrdinal15 :: Rule
ruleThOrdinal15 = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"30th ordinal"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"trzydziest(ym|y|ego|emu|(a|ą)|ej)"
    ]
  , 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
30
  }

ruleThOrdinal12 :: Rule
ruleThOrdinal12 :: Rule
ruleThOrdinal12 = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"19th ordinal"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"dziewi(ę|e)tnast(ym|y|ego|emu|(a|ą)|ej)"
    ]
  , 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
  }

ruleThirdOrdinal :: Rule
ruleThirdOrdinal :: Rule
ruleThirdOrdinal = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"third ordinal"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"trzeci(ego|ch|emu|m|mi|ej|(a|ą))?"
    ]
  , 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
  }

rules :: [Rule]
rules :: [Rule]
rules =
  [ Rule
ruleFifthOrdinal
  , Rule
ruleFirstOrdinal
  , Rule
ruleFourthOrdinal
  , Rule
ruleNdOrdinalNoSpace
  , Rule
ruleOrdinalDigits
  , Rule
ruleRdOrdinalNoSpace
  , Rule
ruleSecondOrdinal
  , Rule
ruleSeventhOrdinal
  , Rule
ruleSixthOrdinal
  , Rule
ruleStOrdinalNoSpace
  , Rule
ruleThOrdinal
  , Rule
ruleThOrdinal10
  , Rule
ruleThOrdinal11
  , Rule
ruleThOrdinal12
  , Rule
ruleThOrdinal13
  , Rule
ruleThOrdinal14
  , Rule
ruleThOrdinal15
  , Rule
ruleThOrdinal16
  , Rule
ruleThOrdinal2
  , Rule
ruleThOrdinal3
  , Rule
ruleThOrdinal4
  , Rule
ruleThOrdinal5
  , Rule
ruleThOrdinal6
  , Rule
ruleThOrdinal7
  , Rule
ruleThOrdinal8
  , Rule
ruleThOrdinal9
  , Rule
ruleThOrdinalNoSpace
  , Rule
ruleThirdOrdinal
  ]