Skip to content

Instantly share code, notes, and snippets.

@neeraj9
Last active March 29, 2018 09:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neeraj9/9cecee9462414a933114f734cb3a9807 to your computer and use it in GitHub Desktop.
Save neeraj9/9cecee9462414a933114f734cb3a9807 to your computer and use it in GitHub Desktop.
BeamParticle Intent Analysis via Microsoft Luis
#!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