mirror of
https://github.com/facebook/duckling.git
synced 2025-01-07 14:29:37 +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
|
||||
formatToken :: Text -> ResolvedToken -> Entity
|
||||
formatToken sentence (Resolved (Range start end) (Node{token=Token dimension _}) jsonValue) =
|
||||
Entity (toName dimension) body val start end
|
||||
formatToken sentence (Resolved (Range start end) (Node{token=Token dimension _}) value) =
|
||||
Entity (toName dimension) body value start end
|
||||
where
|
||||
body = Text.drop start $ Text.take end sentence
|
||||
val = toJText jsonValue
|
||||
|
@ -129,7 +129,7 @@ instance Show Rule where
|
||||
data Entity = Entity
|
||||
{ dim :: Text
|
||||
, body :: Text
|
||||
, value :: Text
|
||||
, value :: Value
|
||||
, start :: Int
|
||||
, end :: Int
|
||||
} deriving (Eq, Generic, Show, NFData)
|
||||
@ -138,7 +138,7 @@ instance ToJSON Entity where
|
||||
toEncoding = genericToEncoding defaultOptions
|
||||
|
||||
toJText :: ToJSON x => x -> Text
|
||||
toJText j = Text.decodeUtf8 $ LB.toStrict $ encode j
|
||||
toJText = Text.decodeUtf8 . LB.toStrict . encode
|
||||
|
||||
-- -----------------------------------------------------------------
|
||||
-- Predicates helpers
|
||||
|
@ -43,7 +43,7 @@ parseTest = testCase "Parse Test" $
|
||||
(Entity dim body value start end:_) -> do
|
||||
assertEqual "dim" "number" dim
|
||||
assertEqual "body" "42" body
|
||||
assertEqual "value" val value
|
||||
assertEqual "value" val (toJText value)
|
||||
assertEqual "start" 4 start
|
||||
assertEqual "end" 6 end
|
||||
where
|
||||
|
Loading…
Reference in New Issue
Block a user