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:
Şeref R.Ayar 2017-06-12 15:00:21 -07:00 committed by Facebook Github Bot
parent c6c1330ed5
commit 8711df5047
3 changed files with 5 additions and 6 deletions

View File

@ -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

View File

@ -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

View File

@ -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