{-# LANGUAGE GADTs #-}
{-# LANGUAGE OverloadedStrings #-}
module Duckling.Email.EN.Rules
( rules ) where
import Data.String
import Prelude
import qualified Data.Text as Text
import Duckling.Dimensions.Types
import Duckling.Email.Types (EmailData (..))
import Duckling.Regex.Types
import Duckling.Types
import qualified Duckling.Email.Types as TEmail
ruleEmailSpelledOut :: Rule
ruleEmailSpelledOut :: Rule
ruleEmailSpelledOut = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"email spelled out"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"([\\w_+-]+(?:(?: dot |\\.)[\\w_+-]+){0,10})(?: at |@)([a-zA-Z]+(?:(?:\\.| dot )[\\w_-]+){1,10})"
]
, prod :: Production
prod = \[Token]
xs -> case [Token]
xs of
(Token Dimension a
RegexMatch (GroupMatch (m1:m2:_)):[Token]
_) ->
Token -> Maybe Token
forall a. a -> Maybe a
Just (Token -> Maybe Token) -> Token -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Dimension EmailData -> EmailData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension EmailData
Email EmailData :: Text -> EmailData
EmailData
{ value :: Text
TEmail.value = [Text] -> Text
Text.concat [Text -> Text
replaceDots Text
m1, Text
"@", Text -> Text
replaceDots Text
m2] }
where replaceDots :: Text -> Text
replaceDots = Text -> Text -> Text -> Text
Text.replace Text
" dot " Text
"."
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
rules :: [Rule]
rules :: [Rule]
rules =
[ Rule
ruleEmailSpelledOut
]