Return latent entities

Summary: Add an option to return latent time entities. This can be used when one is pretty certain that the input contains a datetime.

Reviewed By: patapizza

Differential Revision: D7254245

fbshipit-source-id: e9e0503cace2691804056fcebdc18fd9090fb181
This commit is contained in:
Chinmay Deshmukh 2018-03-19 14:34:58 -07:00 committed by Facebook Github Bot
parent 490799fe4a
commit 5ac990bbe2
203 changed files with 414 additions and 340 deletions

View File

@ -21,7 +21,8 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale AR Nothing}, allExamples)
corpus = (testContext {locale = makeLocale AR Nothing},
testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -20,7 +20,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale BG Nothing}, allExamples)
corpus = (testContext {locale = makeLocale BG Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -20,14 +20,14 @@ import Duckling.AmountOfMoney.Types
import Duckling.Testing.Types
negativeCorpus :: NegativeCorpus
negativeCorpus = (testContext, examples)
negativeCorpus = (testContext, testOptions, examples)
where
examples =
[ "exactly dollars"
]
corpus :: Corpus
corpus = (testContext, allExamples)
corpus = (testContext, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -21,7 +21,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale ES Nothing}, allExamples)
corpus = (testContext {locale = makeLocale ES Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -21,7 +21,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale FR Nothing}, allExamples)
corpus = (testContext {locale = makeLocale FR Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -21,7 +21,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale GA Nothing}, allExamples)
corpus = (testContext {locale = makeLocale GA Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -20,7 +20,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale HR Nothing}, allExamples)
corpus = (testContext {locale = makeLocale HR Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -21,7 +21,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale ID Nothing}, allExamples)
corpus = (testContext {locale = makeLocale ID Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -21,7 +21,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale KO Nothing}, allExamples)
corpus = (testContext {locale = makeLocale KO Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -21,7 +21,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale NB Nothing}, allExamples)
corpus = (testContext {locale = makeLocale NB Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -21,7 +21,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale PT Nothing}, allExamples)
corpus = (testContext {locale = makeLocale PT Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -21,7 +21,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale RO Nothing}, allExamples)
corpus = (testContext {locale = makeLocale RO Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -21,7 +21,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale RU Nothing}, allExamples)
corpus = (testContext {locale = makeLocale RU Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -21,7 +21,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale SV Nothing}, allExamples)
corpus = (testContext {locale = makeLocale SV Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -118,19 +118,19 @@ data AmountOfMoneyData = AmountOfMoneyData
instance Resolve AmountOfMoneyData where
type ResolvedValue AmountOfMoneyData = AmountOfMoneyValue
resolve _ AmountOfMoneyData {value = Nothing, minValue = Nothing
resolve _ _ AmountOfMoneyData {value = Nothing, minValue = Nothing
, maxValue = Nothing} = Nothing
resolve _ AmountOfMoneyData {value = Just value, currency} =
Just $ simple currency value
resolve _ AmountOfMoneyData {value = Nothing, currency = c
resolve _ _ AmountOfMoneyData {value = Just value, currency} =
Just (simple currency value, False)
resolve _ _ AmountOfMoneyData {value = Nothing, currency = c
, minValue = Just from, maxValue = Just to} =
Just $ between c (from, to)
resolve _ AmountOfMoneyData {value = Nothing, currency = c
Just (between c (from, to), False)
resolve _ _ AmountOfMoneyData {value = Nothing, currency = c
, minValue = Just v, maxValue = Nothing} =
Just $ above c v
resolve _ AmountOfMoneyData {value = Nothing, currency = c
Just (above c v, False)
resolve _ _ AmountOfMoneyData {value = Nothing, currency = c
, minValue = Nothing, maxValue = Just v} =
Just $ under c v
Just (under c v, False)
data IntervalDirection = Above | Under
deriving (Eq, Generic, Hashable, Ord, Show, NFData)

View File

@ -21,7 +21,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale VI Nothing}, allExamples)
corpus = (testContext {locale = makeLocale VI Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -37,8 +37,9 @@ import Duckling.Rules
import Duckling.Types
-- | Parses `input` and returns a curated list of entities found.
parse :: Text -> Context -> [Some Dimension] -> [Entity]
parse input ctx = map (formatToken input) . analyze input ctx . HashSet.fromList
parse :: Text -> Context -> Options -> [Some Dimension] -> [Entity]
parse input ctx options = map (formatToken input) . analyze input ctx options .
HashSet.fromList
supportedDimensions :: HashMap Lang [Some Dimension]
supportedDimensions =
@ -46,18 +47,19 @@ supportedDimensions =
-- | Returns a curated list of resolved tokens found
-- When `targets` is non-empty, returns only tokens of such dimensions.
analyze :: Text -> Context -> HashSet (Some Dimension) -> [ResolvedToken]
analyze input context@Context{..} targets =
analyze :: Text -> Context -> Options -> HashSet (Some Dimension)
-> [ResolvedToken]
analyze input context@Context{..} options targets =
rank (classifiers locale) targets
. filter (\Resolved{node = Node{token = (Token d _)}} ->
HashSet.null targets || HashSet.member (This d) targets
)
$ parseAndResolve (rulesFor locale targets) input context
$ parseAndResolve (rulesFor locale targets) input context options
-- | Converts the resolved token to the API format
formatToken :: Text -> ResolvedToken -> Entity
formatToken sentence
(Resolved (Range start end) node@Node{token = Token dimension _} value) =
Entity (toName dimension) body value start end node
(Resolved (Range start end) node@Node{token = Token dimension _} value latent)
= Entity (toName dimension) body value start end latent node
where
body = Text.drop start $ Text.take end sentence

View File

@ -12,13 +12,14 @@
module Duckling.Core
( Context(..)
, Region(..)
, Dimension(..)
, Entity(..)
, Node(..)
, Range(..)
, Lang(..)
, Locale
, Node(..)
, Options(..)
, Range(..)
, Region(..)
, Some(..)
, fromName
, makeLocale

View File

@ -13,7 +13,7 @@
module Duckling.Debug
( allParses
, debug
, debugContext
, debugCustom
, fullParses
, ptree
) where
@ -38,7 +38,7 @@ import Duckling.Types
-- API
debug :: Locale -> Text -> [Some Dimension] -> IO [Entity]
debug locale = debugContext testContext {locale = locale}
debug locale = debugCustom testContext {locale = locale} testOptions
allParses :: Locale -> Text -> [Some Dimension] -> IO [Entity]
allParses l sentence targets = debugTokens sentence $ parses l sentence targets
@ -62,12 +62,12 @@ parses l sentence targets = flip filter tokens $
[] -> True
_ -> elem (This d) targets
where
tokens = parseAndResolve rules sentence testContext {locale = l}
tokens = parseAndResolve rules sentence testContext {locale = l} testOptions
rules = rulesFor l $ HashSet.fromList targets
debugContext :: Context -> Text -> [Some Dimension] -> IO [Entity]
debugContext context sentence targets =
debugTokens sentence . analyze sentence context $ HashSet.fromList targets
debugCustom :: Context -> Options -> Text -> [Some Dimension] -> IO [Entity]
debugCustom context options sentence targets = debugTokens sentence .
analyze sentence context options $ HashSet.fromList targets
debugTokens :: Text -> [ResolvedToken] -> IO [Entity]
debugTokens sentence tokens = do

View File

@ -21,7 +21,7 @@ import Duckling.Distance.Types
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale BG Nothing}, allExamples)
corpus = (testContext {locale = makeLocale BG Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -21,7 +21,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale CS Nothing}, allExamples)
corpus = (testContext {locale = makeLocale CS Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -18,7 +18,7 @@ import Duckling.Distance.Types
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext, allExamples)
corpus = (testContext, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -21,7 +21,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale ES Nothing}, allExamples)
corpus = (testContext {locale = makeLocale ES Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -20,7 +20,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale FR Nothing}, allExamples)
corpus = (testContext {locale = makeLocale FR Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -20,7 +20,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale GA Nothing}, allExamples)
corpus = (testContext {locale = makeLocale GA Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -19,7 +19,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale HR Nothing}, allExamples)
corpus = (testContext {locale = makeLocale HR Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -20,7 +20,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale KO Nothing}, allExamples)
corpus = (testContext {locale = makeLocale KO Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -20,7 +20,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale NL Nothing}, allExamples)
corpus = (testContext {locale = makeLocale NL Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -20,7 +20,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale PT Nothing}, allExamples)
corpus = (testContext {locale = makeLocale PT Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -20,7 +20,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale RO Nothing}, allExamples)
corpus = (testContext {locale = makeLocale RO Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -21,7 +21,7 @@ import Duckling.Distance.Types
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale RU Nothing}, allExamples)
corpus = (testContext {locale = makeLocale RU Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -20,7 +20,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale TR Nothing}, allExamples)
corpus = (testContext {locale = makeLocale TR Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -51,18 +51,18 @@ data DistanceData = DistanceData
instance Resolve DistanceData where
type ResolvedValue DistanceData = DistanceValue
resolve _ DistanceData {unit = Just unit, value = Just val} =
Just $ simple unit val
resolve _ DistanceData {unit = Just unit, value = Nothing
resolve _ _ DistanceData {unit = Just unit, value = Just val} =
Just (simple unit val, False)
resolve _ _ DistanceData {unit = Just unit, value = Nothing
, minValue = Just from, maxValue = Just to} =
Just $ between unit (from, to)
resolve _ DistanceData {unit = Just unit, value = Nothing
Just (between unit (from, to), False)
resolve _ _ DistanceData {unit = Just unit, value = Nothing
, minValue = Just from, maxValue = Nothing} =
Just $ above unit from
resolve _ DistanceData {unit = Just unit, value = Nothing
Just (above unit from, False)
resolve _ _ DistanceData {unit = Just unit, value = Nothing
, minValue = Nothing, maxValue = Just to} =
Just $ under unit to
resolve _ _ = Nothing
Just (under unit to, False)
resolve _ _ _ = Nothing
data IntervalDirection = Above | Under
deriving (Eq, Generic, Hashable, Ord, Show, NFData)

View File

@ -22,7 +22,7 @@ import Duckling.Testing.Types
import Duckling.TimeGrain.Types (Grain(..))
corpus :: Corpus
corpus = (testContext {locale = makeLocale AR Nothing}, allExamples)
corpus = (testContext {locale = makeLocale AR Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -26,10 +26,10 @@ context :: Context
context = testContext {locale = makeLocale EL Nothing}
corpus :: Corpus
corpus = (context, allExamples)
corpus = (context, testOptions, allExamples)
negativeCorpus :: NegativeCorpus
negativeCorpus = (context, examples)
negativeCorpus = (context, testOptions, examples)
where
examples =
[ "για μήνες"

View File

@ -21,10 +21,10 @@ import Duckling.Testing.Types
import Duckling.TimeGrain.Types (Grain(..))
corpus :: Corpus
corpus = (testContext, allExamples)
corpus = (testContext, testOptions, allExamples)
negativeCorpus :: NegativeCorpus
negativeCorpus = (testContext, examples)
negativeCorpus = (testContext, testOptions, examples)
where
examples =
[ "for months"

View File

@ -23,10 +23,10 @@ import Duckling.Testing.Types
import Duckling.TimeGrain.Types (Grain(..))
corpus :: Corpus
corpus = (testContext {locale = makeLocale FR Nothing}, allExamples)
corpus = (testContext {locale = makeLocale FR Nothing}, testOptions, allExamples)
negativeCorpus :: NegativeCorpus
negativeCorpus = (testContext {locale = makeLocale FR Nothing}, examples)
negativeCorpus = (testContext {locale = makeLocale FR Nothing}, testOptions, examples)
where
examples =
[ "les jours"

View File

@ -22,7 +22,7 @@ import Duckling.Testing.Types
import Duckling.TimeGrain.Types (Grain(..))
corpus :: Corpus
corpus = (testContext {locale = makeLocale GA Nothing}, allExamples)
corpus = (testContext {locale = makeLocale GA Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -20,7 +20,7 @@ import Duckling.Testing.Types
import Duckling.TimeGrain.Types (Grain(..))
corpus :: Corpus
corpus = (testContext {locale = makeLocale HU Nothing}, allExamples)
corpus = (testContext {locale = makeLocale HU Nothing}, testOptions, allExamples)
allExamples :: [Example]

View File

@ -22,7 +22,7 @@ import Duckling.Testing.Types
import Duckling.TimeGrain.Types (Grain(..))
corpus :: Corpus
corpus = (testContext {locale = makeLocale JA Nothing}, allExamples)
corpus = (testContext {locale = makeLocale JA Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -22,7 +22,7 @@ import Duckling.Testing.Types
import Duckling.TimeGrain.Types (Grain(..))
corpus :: Corpus
corpus = (testContext {locale = makeLocale KO Nothing}, allExamples)
corpus = (testContext {locale = makeLocale KO Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -22,7 +22,7 @@ import Duckling.Testing.Types
import Duckling.TimeGrain.Types (Grain(..))
corpus :: Corpus
corpus = (testContext {locale = makeLocale NB Nothing}, allExamples)
corpus = (testContext {locale = makeLocale NB Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -23,10 +23,10 @@ import Duckling.Testing.Types
import Duckling.TimeGrain.Types (Grain(..))
corpus :: Corpus
corpus = (testContext {locale = makeLocale NL Nothing}, allExamples)
corpus = (testContext {locale = makeLocale NL Nothing}, testOptions, allExamples)
negativeCorpus :: NegativeCorpus
negativeCorpus = (testContext {locale = makeLocale NL Nothing}, examples)
negativeCorpus = (testContext {locale = makeLocale NL Nothing}, testOptions, examples)
where
examples =
[ "voor maanden"

View File

@ -22,7 +22,7 @@ import Duckling.Testing.Types
import Duckling.TimeGrain.Types (Grain(..))
corpus :: Corpus
corpus = (testContext {locale = makeLocale PL Nothing}, allExamples)
corpus = (testContext {locale = makeLocale PL Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -22,7 +22,7 @@ import Duckling.Testing.Types
import Duckling.TimeGrain.Types (Grain(..))
corpus :: Corpus
corpus = (testContext {locale = makeLocale PT Nothing}, allExamples)
corpus = (testContext {locale = makeLocale PT Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -22,7 +22,7 @@ import Duckling.Testing.Types
import Duckling.TimeGrain.Types (Grain(..))
corpus :: Corpus
corpus = (testContext {locale = makeLocale RO Nothing}, allExamples)
corpus = (testContext {locale = makeLocale RO Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -22,7 +22,7 @@ import Duckling.Testing.Types
import Duckling.TimeGrain.Types (Grain(..))
corpus :: Corpus
corpus = (testContext {locale = makeLocale RU Nothing}, allExamples)
corpus = (testContext {locale = makeLocale RU Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -22,7 +22,7 @@ import Duckling.Testing.Types
import Duckling.TimeGrain.Types (Grain(..))
corpus :: Corpus
corpus = (testContext {locale = makeLocale SV Nothing}, allExamples)
corpus = (testContext {locale = makeLocale SV Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -22,7 +22,7 @@ import Duckling.Testing.Types
import Duckling.TimeGrain.Types (Grain (..))
corpus :: Corpus
corpus = (testContext {locale = makeLocale TR Nothing}, allExamples)
corpus = (testContext {locale = makeLocale TR Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -34,7 +34,7 @@ data DurationData = DurationData
instance Resolve DurationData where
type ResolvedValue DurationData = DurationData
resolve _ x = Just x
resolve _ _ x = Just (x, False)
instance ToJSON DurationData where
toJSON DurationData {value, grain} = object

View File

@ -22,7 +22,7 @@ import Duckling.Testing.Types
import Duckling.TimeGrain.Types (Grain(..))
corpus :: Corpus
corpus = (testContext {locale = makeLocale ZH Nothing}, allExamples)
corpus = (testContext {locale = makeLocale ZH Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -20,10 +20,10 @@ import Duckling.Email.Types
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext, allExamples)
corpus = (testContext, testOptions, allExamples)
negativeCorpus :: NegativeCorpus
negativeCorpus = (testContext, examples)
negativeCorpus = (testContext, testOptions, examples)
where
examples =
[ "hey@6"

View File

@ -21,7 +21,7 @@ import Duckling.Email.Types
import Duckling.Testing.Types
negativeCorpus :: NegativeCorpus
negativeCorpus = (testContext, examples)
negativeCorpus = (testContext, testOptions, examples)
where
examples =
[ "fitness at 6.40"
@ -35,7 +35,7 @@ negativeCorpus = (testContext, examples)
]
corpus :: Corpus
corpus = (testContext, allExamples)
corpus = (testContext, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -21,7 +21,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale FR Nothing}, allExamples)
corpus = (testContext {locale = makeLocale FR Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -21,7 +21,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale IT Nothing}, allExamples)
corpus = (testContext {locale = makeLocale IT Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -29,7 +29,7 @@ newtype EmailData = EmailData { value :: Text }
instance Resolve EmailData where
type ResolvedValue EmailData = EmailData
resolve _ x = Just x
resolve _ _ x = Just (x, False)
instance ToJSON EmailData where
toJSON EmailData {value} = object [ "value" .= value ]

View File

@ -48,10 +48,10 @@ type Duckling a = Identity a
runDuckling :: Duckling a -> a
runDuckling ma = runIdentity ma
parseAndResolve :: [Rule] -> Text -> Context -> [ResolvedToken]
parseAndResolve rules input context = mapMaybe (resolveNode context) .
force $ Stash.toPosOrderedList $ runDuckling $
parseString rules (Document.fromText input)
parseAndResolve :: [Rule] -> Text -> Context -> Options -> [ResolvedToken]
parseAndResolve rules input context options =
mapMaybe (resolveNode context options) . force $ Stash.toPosOrderedList $
runDuckling $ parseString rules (Document.fromText input)
produce :: Match -> Maybe Node
produce (_, _, []) = Nothing
@ -218,11 +218,13 @@ parseString rules sentence = do
headPredicateRules =
[ rule | rule@Rule{pattern = (Predicate _ : _)} <- rules ]
resolveNode :: Context -> Node -> Maybe ResolvedToken
resolveNode context n@Node{token = (Token _ dd), nodeRange = nodeRange} = do
val <- resolve context dd
resolveNode :: Context -> Options -> Node -> Maybe ResolvedToken
resolveNode context options n@Node{token = (Token _ dd), nodeRange = nodeRange}
= do
(val, latent) <- resolve context options dd
Just Resolved
{ range = nodeRange
, node = n
, jsonValue = toJSON val
, isLatent = latent
}

View File

@ -21,7 +21,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale AR Nothing}, allExamples)
corpus = (testContext {locale = makeLocale AR Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -20,7 +20,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale BG Nothing}, allExamples)
corpus = (testContext {locale = makeLocale BG Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -20,7 +20,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale CS Nothing}, allExamples)
corpus = (testContext {locale = makeLocale CS Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -20,7 +20,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale DA Nothing}, allExamples)
corpus = (testContext {locale = makeLocale DA Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -21,7 +21,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale DE Nothing}, allExamples)
corpus = (testContext {locale = makeLocale DE Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -20,7 +20,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale EL Nothing}, allExamples)
corpus = (testContext {locale = makeLocale EL Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -18,7 +18,7 @@ import Duckling.Numeral.Types
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext, allExamples)
corpus = (testContext, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -20,7 +20,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale ES Nothing}, allExamples)
corpus = (testContext {locale = makeLocale ES Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -20,7 +20,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale ET Nothing}, allExamples)
corpus = (testContext {locale = makeLocale ET Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -21,7 +21,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale FR Nothing}, allExamples)
corpus = (testContext {locale = makeLocale FR Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -21,7 +21,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale GA Nothing}, allExamples)
corpus = (testContext {locale = makeLocale GA Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -19,7 +19,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale HE Nothing}, allExamples)
corpus = (testContext {locale = makeLocale HE Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -21,7 +21,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale HI Nothing}, allExamples)
corpus = (testContext {locale = makeLocale HI Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -19,7 +19,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale HR Nothing}, allExamples)
corpus = (testContext {locale = makeLocale HR Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -20,7 +20,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale HU Nothing}, allExamples)
corpus = (testContext {locale = makeLocale HU Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -20,7 +20,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale ID Nothing}, allExamples)
corpus = (testContext {locale = makeLocale ID Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -20,7 +20,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale IT Nothing}, allExamples)
corpus = (testContext {locale = makeLocale IT Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -20,7 +20,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale JA Nothing}, allExamples)
corpus = (testContext {locale = makeLocale JA Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -20,7 +20,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale KA Nothing}, allExamples)
corpus = (testContext {locale = makeLocale KA Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -20,7 +20,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale KO Nothing}, allExamples)
corpus = (testContext {locale = makeLocale KO Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -20,7 +20,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale MY Nothing}, allExamples)
corpus = (testContext {locale = makeLocale MY Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -20,7 +20,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale NB Nothing}, allExamples)
corpus = (testContext {locale = makeLocale NB Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -21,7 +21,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale NE Nothing}, allExamples)
corpus = (testContext {locale = makeLocale NE Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -21,7 +21,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale NL Nothing}, allExamples)
corpus = (testContext {locale = makeLocale NL Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -20,7 +20,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale PL Nothing}, allExamples)
corpus = (testContext {locale = makeLocale PL Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -21,7 +21,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale PT Nothing}, allExamples)
corpus = (testContext {locale = makeLocale PT Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -20,7 +20,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale RO Nothing}, allExamples)
corpus = (testContext {locale = makeLocale RO Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -20,7 +20,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale RU Nothing}, allExamples)
corpus = (testContext {locale = makeLocale RU Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -20,7 +20,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale SV Nothing}, allExamples)
corpus = (testContext {locale = makeLocale SV Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -20,7 +20,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale TR Nothing}, allExamples)
corpus = (testContext {locale = makeLocale TR Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -39,7 +39,7 @@ data NumeralData = NumeralData
instance Resolve NumeralData where
type ResolvedValue NumeralData = NumeralValue
resolve _ NumeralData {value} = Just NumeralValue {vValue = value}
resolve _ _ NumeralData {value} = Just (NumeralValue {vValue = value}, False)
newtype NumeralValue = NumeralValue { vValue :: Double }
deriving (Eq, Show)

View File

@ -20,7 +20,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale UK Nothing}, allExamples)
corpus = (testContext {locale = makeLocale UK Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -20,7 +20,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale VI Nothing}, allExamples)
corpus = (testContext {locale = makeLocale VI Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -20,7 +20,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale ZH Nothing}, allExamples)
corpus = (testContext {locale = makeLocale ZH Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -21,7 +21,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale AR Nothing}, allExamples)
corpus = (testContext {locale = makeLocale AR Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -20,7 +20,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale DA Nothing}, allExamples)
corpus = (testContext {locale = makeLocale DA Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples =

View File

@ -22,10 +22,10 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale DE Nothing}, allExamples)
corpus = (testContext {locale = makeLocale DE Nothing}, testOptions, allExamples)
negativeCorpus :: NegativeCorpus
negativeCorpus = (testContext {locale = makeLocale DE Nothing}, examples)
negativeCorpus = (testContext {locale = makeLocale DE Nothing}, testOptions, examples)
where
examples =
[ "1.1"

View File

@ -20,7 +20,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale EL Nothing}, allExamples)
corpus = (testContext {locale = makeLocale EL Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -18,7 +18,7 @@ import Duckling.Ordinal.Types
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext, allExamples)
corpus = (testContext, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -20,7 +20,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale ES Nothing}, allExamples)
corpus = (testContext {locale = makeLocale ES Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -20,7 +20,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale ET Nothing}, allExamples)
corpus = (testContext {locale = makeLocale ET Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples =

View File

@ -20,7 +20,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale FR Nothing}, allExamples)
corpus = (testContext {locale = makeLocale FR Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

View File

@ -20,7 +20,7 @@ import Duckling.Resolve
import Duckling.Testing.Types
corpus :: Corpus
corpus = (testContext {locale = makeLocale GA Nothing}, allExamples)
corpus = (testContext {locale = makeLocale GA Nothing}, testOptions, allExamples)
allExamples :: [Example]
allExamples = concat

Some files were not shown because too many files have changed in this diff Show More