Added German+Icelandic spelled out Email

Summary: Pull Request resolved: https://github.com/facebook/duckling/pull/272

Reviewed By: chinmay87

Differential Revision: D12955290

Pulled By: patapizza

fbshipit-source-id: 671ee50c92c031762aa147dc6bd98f374693ba6b
This commit is contained in:
Kumar Shridhar 2018-11-07 09:02:42 -08:00 committed by Facebook Github Bot
parent 3374f4ea50
commit 975489fed6
13 changed files with 254 additions and 8 deletions

View File

@ -0,0 +1,65 @@
-- 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.Email.DE.Corpus
( corpus
, negativeCorpus
) where
import Data.String
import Prelude
import qualified Data.Text as Text
import Duckling.Email.Types
import Duckling.Locale
import Duckling.Resolve
import Duckling.Testing.Types
context :: Context
context = testContext {locale = makeLocale DE Nothing}
negativeCorpus :: NegativeCorpus
negativeCorpus = (context, testOptions, examples)
where
examples =
[ "fitness at 6.40"
, "class at 12.00"
, "tonight at 9.15"
, " dot 2@abci"
, "x@ dot x"
, "x@ x dot "
, "abc@x dot "
, Text.replicate 10000 "a at a"
]
corpus :: Corpus
corpus = (context, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat
[ examples (EmailData "alice@exAmple.io")
[ "alice at exAmple.io"
]
, examples (EmailData "yo+yo@blah.org")
[ "yo+yo at blah.org"
]
, examples (EmailData "1234+abc@x.net")
[ "1234+abc at x.net"
]
, examples (EmailData "jean-jacques@stuff.co.uk")
[ "jean-jacques at stuff.co.uk"
]
, examples (EmailData "asdf+ab.c@gmail.com")
[ "asdf+ab punkt c at gmail punkt com"
]
, examples (EmailData "asdf.k@fb.com")
[ "asdf punkt k@fb punkt com"
]
]

View File

@ -0,0 +1,42 @@
-- 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.Email.DE.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
{ name = "email spelled out"
, pattern =
[ regex "([\\w_+-]+(?:(?: punkt |\\.)[\\w_+-]+){0,10})(?: at |@)([a-zA-Z]+(?:(?:\\.| punkt )[\\w_-]+){1,10})"
]
, prod = \xs -> case xs of
(Token RegexMatch (GroupMatch (m1:m2:_)):_) ->
Just $ Token Email EmailData
{ TEmail.value = Text.concat [replaceDots m1, "@", replaceDots m2] }
where replaceDots = Text.replace " punkt " "."
_ -> Nothing
}
rules :: [Rule]
rules =
[ ruleEmailSpelledOut
]

View File

@ -0,0 +1,40 @@
-- 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.Email.IS.Corpus
( corpus
) where
import Data.String
import Prelude
import Duckling.Email.Types
import Duckling.Locale
import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale IS Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat
[ examples (EmailData "alice@exAmple.io")
[ "alice ingi exAmple.io"
]
, examples (EmailData "yo+yo@blah.org")
[ "yo+yo ingi blah.org"
]
, examples (EmailData "1234+abc@x.net")
[ "1234+abc ingi x.net"
]
, examples (EmailData "jean-jacques@stuff.co.uk")
[ "jean-jacques ingi stuff.co.uk"
]
]

View File

@ -0,0 +1,40 @@
-- 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.Email.IS.Rules
( rules ) where
import Data.String
import qualified Data.Text as Text
import Prelude
import Duckling.Dimensions.Types
import Duckling.Email.Types (EmailData (..))
import qualified Duckling.Email.Types as TEmail
import Duckling.Regex.Types
import Duckling.Types
ruleEmailSpelledOut :: Rule
ruleEmailSpelledOut = Rule
{ name = "email spelled out"
, pattern =
[ regex "([\\w\\._+-]+) ingi ([\\w_-]+(\\.[\\w_-]+)+)"
]
, prod = \xs -> case xs of
(Token RegexMatch (GroupMatch (m1:m2:_)):_) ->
Just $ Token Email EmailData {TEmail.value = Text.concat [m1, "@", m2]}
_ -> Nothing
}
rules :: [Rule]
rules =
[ ruleEmailSpelledOut
]

View File

@ -19,6 +19,7 @@ import Duckling.Dimensions.Types
import Duckling.Locale
import Duckling.Types
import qualified Duckling.Duration.DE.Rules as Duration
import qualified Duckling.Email.DE.Rules as Email
import qualified Duckling.Ordinal.DE.Rules as Ordinal
import qualified Duckling.Numeral.DE.Rules as Numeral
import qualified Duckling.Time.DE.Rules as Time
@ -35,7 +36,7 @@ langRules :: Some Dimension -> [Rule]
langRules (This AmountOfMoney) = []
langRules (This Distance) = []
langRules (This Duration) = Duration.rules
langRules (This Email) = []
langRules (This Email) = Email.rules
langRules (This Numeral) = Numeral.rules
langRules (This Ordinal) = Ordinal.rules
langRules (This PhoneNumber) = []

View File

@ -17,6 +17,7 @@ module Duckling.Rules.IS
import Duckling.Dimensions.Types
import Duckling.Locale
import Duckling.Types
import qualified Duckling.Email.IS.Rules as Email
import qualified Duckling.Numeral.IS.Rules as Numeral
defaultRules :: Some Dimension -> [Rule]
@ -30,7 +31,7 @@ langRules :: Some Dimension -> [Rule]
langRules (This Distance) = []
langRules (This Duration) = []
langRules (This Numeral) = Numeral.rules
langRules (This Email) = []
langRules (This Email) = Email.rules
langRules (This AmountOfMoney) = []
langRules (This Ordinal) = []
langRules (This PhoneNumber) = []

View File

@ -342,10 +342,14 @@ library
, Duckling.Duration.Types
-- Email
, Duckling.Email.DE.Corpus
, Duckling.Email.DE.Rules
, Duckling.Email.EN.Corpus
, Duckling.Email.EN.Rules
, Duckling.Email.FR.Corpus
, Duckling.Email.FR.Rules
, Duckling.Email.IS.Corpus
, Duckling.Email.IS.Rules
, Duckling.Email.IT.Corpus
, Duckling.Email.IT.Rules
, Duckling.Email.Corpus

View File

@ -0,0 +1,24 @@
-- 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.Email.DE.Tests
( tests
) where
import Data.String
import Test.Tasty
import Duckling.Dimensions.Types
import Duckling.Email.DE.Corpus
import Duckling.Testing.Asserts
tests :: TestTree
tests = testGroup "DE Tests"
[ makeCorpusTest [This Email] corpus
, makeNegativeCorpusTest [This Email] negativeCorpus
]

View File

@ -18,7 +18,7 @@ import Duckling.Email.EN.Corpus
import Duckling.Testing.Asserts
tests :: TestTree
tests = testGroup "Email Tests"
tests = testGroup "EN Tests"
[ makeCorpusTest [This Email] corpus
, makeNegativeCorpusTest [This Email] negativeCorpus
]

View File

@ -18,6 +18,6 @@ import Duckling.Email.FR.Corpus
import Duckling.Testing.Asserts
tests :: TestTree
tests = testGroup "Email Tests"
tests = testGroup "FR Tests"
[ makeCorpusTest [This Email] corpus
]

View File

@ -0,0 +1,23 @@
-- 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.Email.IS.Tests
( tests
) where
import Data.String
import Test.Tasty
import Duckling.Dimensions.Types
import Duckling.Email.IS.Corpus
import Duckling.Testing.Asserts
tests :: TestTree
tests = testGroup "IS Tests"
[ makeCorpusTest [This Email] corpus
]

View File

@ -18,6 +18,6 @@ import Duckling.Email.IT.Corpus
import Duckling.Testing.Asserts
tests :: TestTree
tests = testGroup "Email Tests"
tests = testGroup "IT Tests"
[ makeCorpusTest [This Email] corpus
]

View File

@ -6,24 +6,30 @@
-- of patent rights can be found in the PATENTS file in the same directory.
module Duckling.Email.Tests (tests) where
module Duckling.Email.Tests
( tests
) where
import Prelude
import Data.String
import Prelude
import Test.Tasty
import Duckling.Dimensions.Types
import Duckling.Email.Corpus
import Duckling.Testing.Asserts
import qualified Duckling.Email.DE.Tests as DE
import qualified Duckling.Email.EN.Tests as EN
import qualified Duckling.Email.FR.Tests as FR
import qualified Duckling.Email.IS.Tests as IS
import qualified Duckling.Email.IT.Tests as IT
import Duckling.Testing.Asserts
tests :: TestTree
tests = testGroup "Email Tests"
[ makeCorpusTest [This Email] corpus
, makeNegativeCorpusTest [This Email] negativeCorpus
, DE.tests
, EN.tests
, FR.tests
, IS.tests
, IT.tests
]