mirror of
https://github.com/facebook/duckling.git
synced 2025-01-08 15:00:59 +03:00
change json response #12
Summary: not sure about this. Maybe I need some guidance. Closes https://github.com/facebookincubator/duckling/pull/42 Reviewed By: blandinw Differential Revision: D5228520 Pulled By: patapizza fbshipit-source-id: 4f99cc5
This commit is contained in:
parent
c6c1330ed5
commit
8711df5047
@ -55,8 +55,7 @@ analyze input context@Context{..} targets =
|
|||||||
|
|
||||||
-- | Converts the resolved token to the API format
|
-- | Converts the resolved token to the API format
|
||||||
formatToken :: Text -> ResolvedToken -> Entity
|
formatToken :: Text -> ResolvedToken -> Entity
|
||||||
formatToken sentence (Resolved (Range start end) (Node{token=Token dimension _}) jsonValue) =
|
formatToken sentence (Resolved (Range start end) (Node{token=Token dimension _}) value) =
|
||||||
Entity (toName dimension) body val start end
|
Entity (toName dimension) body value start end
|
||||||
where
|
where
|
||||||
body = Text.drop start $ Text.take end sentence
|
body = Text.drop start $ Text.take end sentence
|
||||||
val = toJText jsonValue
|
|
||||||
|
@ -129,7 +129,7 @@ instance Show Rule where
|
|||||||
data Entity = Entity
|
data Entity = Entity
|
||||||
{ dim :: Text
|
{ dim :: Text
|
||||||
, body :: Text
|
, body :: Text
|
||||||
, value :: Text
|
, value :: Value
|
||||||
, start :: Int
|
, start :: Int
|
||||||
, end :: Int
|
, end :: Int
|
||||||
} deriving (Eq, Generic, Show, NFData)
|
} deriving (Eq, Generic, Show, NFData)
|
||||||
@ -138,7 +138,7 @@ instance ToJSON Entity where
|
|||||||
toEncoding = genericToEncoding defaultOptions
|
toEncoding = genericToEncoding defaultOptions
|
||||||
|
|
||||||
toJText :: ToJSON x => x -> Text
|
toJText :: ToJSON x => x -> Text
|
||||||
toJText j = Text.decodeUtf8 $ LB.toStrict $ encode j
|
toJText = Text.decodeUtf8 . LB.toStrict . encode
|
||||||
|
|
||||||
-- -----------------------------------------------------------------
|
-- -----------------------------------------------------------------
|
||||||
-- Predicates helpers
|
-- Predicates helpers
|
||||||
|
@ -43,7 +43,7 @@ parseTest = testCase "Parse Test" $
|
|||||||
(Entity dim body value start end:_) -> do
|
(Entity dim body value start end:_) -> do
|
||||||
assertEqual "dim" "number" dim
|
assertEqual "dim" "number" dim
|
||||||
assertEqual "body" "42" body
|
assertEqual "body" "42" body
|
||||||
assertEqual "value" val value
|
assertEqual "value" val (toJText value)
|
||||||
assertEqual "start" 4 start
|
assertEqual "start" 4 start
|
||||||
assertEqual "end" 6 end
|
assertEqual "end" 6 end
|
||||||
where
|
where
|
||||||
|
Loading…
Reference in New Issue
Block a user