bluemix-sdk 0.1.0.0 → 0.1.1.0
raw patch · 3 files changed
+36/−14 lines, 3 filesdep +bytestringPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependencies added: bytestring
API changes (from Hackage documentation)
+ Network.Watson.NaturalLanguage: [q_emotion] :: Query -> !Bool
+ Network.Watson.NaturalLanguage: [q_sentiment] :: Query -> !Bool
+ Network.Watson.NaturalLanguage: [r_emotion] :: Response -> !(Maybe Emotion)
+ Network.Watson.NaturalLanguage: [r_sentiment] :: Response -> !(Maybe Sentiment)
- Network.Watson.NaturalLanguage: Query :: !QueryBody -> !(Maybe KeywordOptions) -> !Bool -> !(Maybe ConceptOptions) -> Query
+ Network.Watson.NaturalLanguage: Query :: !QueryBody -> !(Maybe KeywordOptions) -> !Bool -> !(Maybe ConceptOptions) -> !Bool -> !Bool -> Query
- Network.Watson.NaturalLanguage: RBadStatus :: !Status -> Result r
+ Network.Watson.NaturalLanguage: RBadStatus :: !Status -> !ByteString -> Result r
- Network.Watson.NaturalLanguage: Response :: !Language -> !(Vector Keyword) -> !(Vector Concept) -> !(Vector Category) -> Response
+ Network.Watson.NaturalLanguage: Response :: !Language -> !(Vector Keyword) -> !(Vector Concept) -> !(Vector Category) -> !(Maybe Emotion) -> !(Maybe Sentiment) -> Response
Files
- bluemix-sdk.cabal +8/−7
- src/Network/Bluemix/Http.hs +3/−2
- src/Network/Watson/NaturalLanguage.hs +25/−5
bluemix-sdk.cabal view
@@ -1,5 +1,5 @@ name: bluemix-sdk-version: 0.1.0.0+version: 0.1.1.0 synopsis: Bindings to Bluemix APIs description: Bindings to Bluemix APIs homepage: https://github.com/agrafix/bluemix-sdk#readme@@ -18,12 +18,13 @@ exposed-modules: Network.Watson.NaturalLanguage, Network.Bluemix.Auth other-modules: Network.Bluemix.Http- build-depends: base >= 4.7 && < 5,- aeson,- text,- vector,- http-types,- http-client+ build-depends: base >= 4.7 && < 5+ , aeson+ , text+ , vector+ , bytestring+ , http-types+ , http-client default-language: Haskell2010 source-repository head
src/Network/Bluemix/Http.hs view
@@ -11,13 +11,14 @@ import Data.Aeson (eitherDecode, encode, ToJSON, FromJSON) import Network.HTTP.Client import Network.HTTP.Types+import qualified Data.ByteString.Lazy as BSL import qualified Data.Text as T import qualified Data.Text.Encoding as T data Result r = ROkay r | RBadResponse !T.Text- | RBadStatus !Status+ | RBadStatus !Status !BSL.ByteString deriving (Show, Eq) runReq :: (ToJSON req, FromJSON r) => Method -> Auth a -> T.Text -> req -> IO (Result r)@@ -41,4 +42,4 @@ case eitherDecode (responseBody response) of Left errMsg -> pure (RBadResponse $ T.pack errMsg) Right ok -> pure (ROkay ok)- _ -> pure $ RBadStatus rs+ _ -> pure $ RBadStatus rs (responseBody response)
src/Network/Watson/NaturalLanguage.hs view
@@ -21,9 +21,11 @@ import Network.Bluemix.Auth import Network.Bluemix.Http +import Control.Monad import Data.Aeson hiding (Result(..)) import Data.Maybe import qualified Data.Text as T+import qualified Data.Traversable as T import qualified Data.Vector as V data QueryBody@@ -50,6 +52,8 @@ , q_keywords :: !(Maybe KeywordOptions) , q_categories :: !Bool , q_concepts :: !(Maybe ConceptOptions)+ , q_emotion :: !Bool+ , q_sentiment :: !Bool } deriving (Show, Eq) instance ToJSON Query where@@ -75,6 +79,12 @@ [ "limit" .= co_limit cp ] , if q_categories q then (Just $ "categories" .= object []) else Nothing+ , if q_emotion q+ then (Just $ "emotion" .= object ["document" .= True])+ else Nothing+ , if q_sentiment q+ then (Just $ "sentiment" .= object ["document" .= True])+ else Nothing ] in object [body, "features" .= feats] @@ -182,16 +192,26 @@ , r_keywords :: !(V.Vector Keyword) , r_concepts :: !(V.Vector Concept) , r_categories :: !(V.Vector Category)+ , r_emotion :: !(Maybe Emotion)+ , r_sentiment :: !(Maybe Sentiment) } deriving (Show, Eq) instance FromJSON Response where parseJSON = withObject "Response" $ \o ->- Response- <$> o .: "language"- <*> o .:? "keywords" .!= V.empty- <*> o .:? "concepts" .!= V.empty- <*> o .:? "categories" .!= V.empty+ do mEmotion <- o .:? "emotion"+ mDocEmotion <-+ T.mapM (flip (.:) "document" >=> flip (.:) "emotion") mEmotion+ mSentiment <- o .:? "sentiment"+ mDocSentiment <-+ T.mapM (.: "document") mSentiment+ Response+ <$> o .: "language"+ <*> o .:? "keywords" .!= V.empty+ <*> o .:? "concepts" .!= V.empty+ <*> o .:? "categories" .!= V.empty+ <*> pure mDocEmotion+ <*> pure mDocSentiment data NaturalLanguage