Last active
March 29, 2018 09:34
-
-
Save neeraj9/9cecee9462414a933114f734cb3a9807 to your computer and use it in GitHub Desktop.
BeamParticle Intent Analysis via Microsoft Luis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!erlang | |
%% @doc Intent Analysis via Microsoft Luis | |
%% | |
%% run nlp_microsoft_luis(<<"I want to travel to Europe. Can you give me possible locations?">>) | |
%% | |
fun(Msg) -> | |
%% The json configuration must be set for this function (TBD) | |
Config = beamparticle_dynamic:get_config(), | |
Endpoint = erlang:binary_to_list(maps:get(<<"endpoint">>, Config)), | |
Key = erlang:binary_to_list(maps:get(<<"key">>, Config)), | |
BaseUrl = "https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/" ++ | |
Endpoint ++ | |
"?subscription-key=" ++ | |
Key ++ | |
"&spellCheck=true&verbose=true&timezoneOffset=5.5&q=", | |
EscapedUrl = BaseUrl ++ beamparticle_urlutils:escape_uri(Msg), | |
case httpc:request(get, {EscapedUrl, []}, [], [{body_format, binary}]) of | |
{ok, {{_, 200, _}, _Headers, Body}} -> | |
{proplists, [{<<"json">>, jiffy:decode(Body, [return_maps])}]}; | |
Resp -> | |
{error, Resp} | |
end | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment