luis-client 0.0.1 → 0.0.2
raw patch · 3 files changed
+72/−2 lines, 3 files
Files
- README.md +20/−0
- luis-client.cabal +3/−1
- src/NLP/LUIS.hs +49/−1
+ README.md view
@@ -0,0 +1,20 @@+# hs-luis-client++[](https://hackage.haskell.org/package/luis-client)++An unofficial Haskell client for Microsoft's [LUIS](https://www.luis.ai) natural language processing API.++## Examples++```haskell+import Control.Lens+import NLP.LUIS++main = do+ let creds = Credentials "Your-App-Id" "Your-Subscription-Key"+ resp <- queryExc creds "show me news about greenland"++ resp ^? responseIntents . ix 0 . intentType -- Just "FindNews"+ resp ^? responseEntities . ix 0 . entityText -- Just "greenland"++```
luis-client.cabal view
@@ -1,5 +1,5 @@ name: luis-client-version: 0.0.1+version: 0.0.2 cabal-version: >=1.10 build-type: Simple license: BSD3@@ -12,6 +12,8 @@ Please see README.md category: Natural Language Processing, Web author: Micxjo Funkcio <micxjo@fastmail.com>+extra-source-files:+ README.md source-repository head type: git
src/NLP/LUIS.hs view
@@ -24,6 +24,19 @@ , Intent , intentType , intentScore+ , intentActions+ , Action+ , actionName+ , actionTriggered+ , actionParams+ , Param+ , paramName+ , paramRequired+ , paramValues+ , ParamValue+ , paramValueEntity+ , paramValueType+ , paramValueScore -- * Entity Type , Entity , entityType@@ -48,15 +61,50 @@ import Network.HTTP.Client (HttpException) import Network.Wreq hiding (Response) +data ParamValue = ParamValue+ { _paramValueEntity :: !Text+ , _paramValueType :: !Text+ , _paramValueScore :: !Double+ } deriving (Eq, Show, Read, Typeable, Data, Generic)++makeLenses ''ParamValue++instance FromJSON ParamValue where+ parseJSON = withObject "param value" $ \o ->+ ParamValue <$> o .: "entity" <*> o .: "type" <*> o .: "score"++data Param = Param { _paramName :: !Text+ , _paramRequired :: !Bool+ , _paramValues :: !(Maybe (Vector ParamValue))+ } deriving (Eq, Show, Read, Typeable, Data, Generic)++makeLenses ''Param++instance FromJSON Param where+ parseJSON = withObject "param" $ \o ->+ Param <$> o .: "name" <*> o .: "required" <*> o .: "value"++data Action = Action { _actionName :: !Text+ , _actionTriggered :: !Bool+ , _actionParams :: !(Vector Param)+ } deriving (Eq, Show, Read, Typeable, Data, Generic)++makeLenses ''Action++instance FromJSON Action where+ parseJSON = withObject "action" $ \o ->+ Action <$> o .: "name" <*> o .: "triggered" <*> o .: "parameters"+ data Intent = Intent { _intentType :: !Text , _intentScore :: !Double+ , _intentActions :: !(Maybe (Vector Action)) } deriving (Eq, Show, Read, Typeable, Data, Generic) makeLenses ''Intent instance FromJSON Intent where parseJSON = withObject "intent" $ \o ->- Intent <$> o .: "intent" <*> o .: "score"+ Intent <$> o .: "intent" <*> o .: "score" <*> o .: "actions" data Entity = Entity { _entityText :: !Text , _entityType :: !Text