{"action":"created","comment":{"url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/pulls/comments/171714382","pull_request_review_id":100617847,"id":171714382,"diff_hunk":"@@ -0,0 +1,217 @@\n+﻿// Copyright (c) Microsoft Corporation. All rights reserved.\n+// Licensed under the MIT License.\n+\n+using System.Collections.Generic;\n+using System.Linq;\n+using System.Threading;\n+using System.Threading.Tasks;\n+using Microsoft.Cognitive.LUIS;\n+using Microsoft.Cognitive.LUIS.Models;\n+using Newtonsoft.Json.Linq;\n+using System.Text.RegularExpressions;\n+\n+namespace Microsoft.Bot.Builder.LUIS\n+{\n+    /// <inheritdoc />\n+    /// <summary>\n+    /// A Luis based implementation of IRecognizer\n+    /// </summary>\n+    public class LuisRecognizer : IRecognizer\n+    {\n+        private readonly LuisService _luisService;\n+        private readonly ILuisOptions _luisOptions;\n+        private readonly ILuisRecognizerOptions _luisRecognizerOptions;\n+\n+        public LuisRecognizer(ILuisModel luisModel, ILuisRecognizerOptions luisRecognizerOptions = null, ILuisOptions options = null)\n+        {\n+            _luisService = new LuisService(luisModel);\n+            _luisOptions = options;\n+            _luisRecognizerOptions = luisRecognizerOptions;\n+        }\n+\n+        /// <inheritdoc />\n+        public Task<RecognizerResult> Recognize(string utterance, CancellationToken ct)\n+        {\n+            var luisRequest = new LuisRequest(utterance);\n+            _luisOptions?.Apply(luisRequest);\n+            return Recognize(luisRequest, ct, _luisRecognizerOptions?.Verbose ?? true);\n+        }\n+\n+        private async Task<RecognizerResult> Recognize(LuisRequest request, CancellationToken ct, bool verbose)\n+        {\n+            var luisResult = await _luisService.QueryAsync(request, ct);\n+\n+            var recognizerResult = new RecognizerResult\n+            {\n+                Text = request.Query,\n+                Intents = GetIntents(luisResult),\n+                Entities = GetEntitiesAndMetadata(luisResult.Entities, luisResult.CompositeEntities, verbose)\n+            };\n+\n+            return recognizerResult;\n+        }\n+\n+        private static JObject GetIntents(LuisResult luisResult)\n+        {\n+            return luisResult.Intents != null ?\n+                JObject.FromObject(luisResult.Intents.ToDictionary(i => i.Intent, i => i.Score ?? 0)) :\n+                new JObject { [luisResult.TopScoringIntent.Intent] = luisResult.TopScoringIntent.Score ?? 0 };\n+        }\n+\n+        private static JObject GetEntitiesAndMetadata(IList<EntityRecommendation> entities, IList<CompositeEntity> compositeEntities, bool verbose)\n+        {\n+            var entitiesAndMetadata = new JObject();\n+            if (verbose)\n+            {\n+                entitiesAndMetadata[\"$instance\"] = new JObject();\n+            }\n+            var compositeEntityTypes = new HashSet<string>();","path":"libraries/Microsoft.Bot.Builder.LUIS/LuisRecognizer.cs","position":75,"original_position":68,"commit_id":"955612eed03e1ffae669e4750618616060ca8716","original_commit_id":"26397e721dd63d14e6d55ceb6cf0c24f7b9f22e4","user":{"login":"emadelwany","id":1061017,"avatar_url":"https://avatars2.githubusercontent.com/u/1061017?v=4","gravatar_id":"","url":"https://api.github.com/users/emadelwany","html_url":"https://github.com/emadelwany","followers_url":"https://api.github.com/users/emadelwany/followers","following_url":"https://api.github.com/users/emadelwany/following{/other_user}","gists_url":"https://api.github.com/users/emadelwany/gists{/gist_id}","starred_url":"https://api.github.com/users/emadelwany/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/emadelwany/subscriptions","organizations_url":"https://api.github.com/users/emadelwany/orgs","repos_url":"https://api.github.com/users/emadelwany/repos","events_url":"https://api.github.com/users/emadelwany/events{/privacy}","received_events_url":"https://api.github.com/users/emadelwany/received_events","type":"User","site_admin":false},"body":"HashSet to make look ups fast (O(1)), some LUIS models have hundreds of entities. ","created_at":"2018-03-01T22:28:06Z","updated_at":"2018-03-01T22:28:06Z","html_url":"https://github.com/Microsoft/botbuilder-dotnet/pull/228#discussion_r171714382","pull_request_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/pulls/228","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/pulls/comments/171714382"},"html":{"href":"https://github.com/Microsoft/botbuilder-dotnet/pull/228#discussion_r171714382"},"pull_request":{"href":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/pulls/228"}},"in_reply_to_id":171698161},"pull_request":{"url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/pulls/228","id":172352849,"html_url":"https://github.com/Microsoft/botbuilder-dotnet/pull/228","diff_url":"https://github.com/Microsoft/botbuilder-dotnet/pull/228.diff","patch_url":"https://github.com/Microsoft/botbuilder-dotnet/pull/228.patch","issue_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/issues/228","number":228,"state":"open","locked":false,"title":"New Luis Recognizer","user":{"login":"emadelwany","id":1061017,"avatar_url":"https://avatars2.githubusercontent.com/u/1061017?v=4","gravatar_id":"","url":"https://api.github.com/users/emadelwany","html_url":"https://github.com/emadelwany","followers_url":"https://api.github.com/users/emadelwany/followers","following_url":"https://api.github.com/users/emadelwany/following{/other_user}","gists_url":"https://api.github.com/users/emadelwany/gists{/gist_id}","starred_url":"https://api.github.com/users/emadelwany/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/emadelwany/subscriptions","organizations_url":"https://api.github.com/users/emadelwany/orgs","repos_url":"https://api.github.com/users/emadelwany/repos","events_url":"https://api.github.com/users/emadelwany/events{/privacy}","received_events_url":"https://api.github.com/users/emadelwany/received_events","type":"User","site_admin":false},"body":"DO NOT MERGE => Need to publish the Microsoft.Cognitive.LUIS v3.0.0 package to nuget first","created_at":"2018-03-01T21:02:52Z","updated_at":"2018-03-01T22:28:06Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f9903d0c1d7213f6ab0e948f7934a07a382bd7f6","assignee":null,"assignees":[],"requested_reviewers":[{"login":"chrimc62","id":17637681,"avatar_url":"https://avatars0.githubusercontent.com/u/17637681?v=4","gravatar_id":"","url":"https://api.github.com/users/chrimc62","html_url":"https://github.com/chrimc62","followers_url":"https://api.github.com/users/chrimc62/followers","following_url":"https://api.github.com/users/chrimc62/following{/other_user}","gists_url":"https://api.github.com/users/chrimc62/gists{/gist_id}","starred_url":"https://api.github.com/users/chrimc62/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chrimc62/subscriptions","organizations_url":"https://api.github.com/users/chrimc62/orgs","repos_url":"https://api.github.com/users/chrimc62/repos","events_url":"https://api.github.com/users/chrimc62/events{/privacy}","received_events_url":"https://api.github.com/users/chrimc62/received_events","type":"User","site_admin":false},{"login":"tomlm","id":17789481,"avatar_url":"https://avatars0.githubusercontent.com/u/17789481?v=4","gravatar_id":"","url":"https://api.github.com/users/tomlm","html_url":"https://github.com/tomlm","followers_url":"https://api.github.com/users/tomlm/followers","following_url":"https://api.github.com/users/tomlm/following{/other_user}","gists_url":"https://api.github.com/users/tomlm/gists{/gist_id}","starred_url":"https://api.github.com/users/tomlm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tomlm/subscriptions","organizations_url":"https://api.github.com/users/tomlm/orgs","repos_url":"https://api.github.com/users/tomlm/repos","events_url":"https://api.github.com/users/tomlm/events{/privacy}","received_events_url":"https://api.github.com/users/tomlm/received_events","type":"User","site_admin":false}],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/pulls/228/commits","review_comments_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/pulls/228/comments","review_comment_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/issues/228/comments","statuses_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/statuses/955612eed03e1ffae669e4750618616060ca8716","head":{"label":"Microsoft:emadelw","ref":"emadelw","sha":"955612eed03e1ffae669e4750618616060ca8716","user":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars2.githubusercontent.com/u/6154722?v=4","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"repo":{"id":117021670,"name":"botbuilder-dotnet","full_name":"Microsoft/botbuilder-dotnet","owner":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars2.githubusercontent.com/u/6154722?v=4","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Microsoft/botbuilder-dotnet","description":".NET SDK used to build chat bots for the Microsoft Bot Framework.","fork":false,"url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet","forks_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/forks","keys_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/teams","hooks_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/hooks","issue_events_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/issues/events{/number}","events_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/events","assignees_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/assignees{/user}","branches_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/branches{/branch}","tags_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/tags","blobs_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/git/refs{/sha}","trees_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/statuses/{sha}","languages_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/languages","stargazers_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/stargazers","contributors_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/contributors","subscribers_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/subscribers","subscription_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/subscription","commits_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/commits{/sha}","git_commits_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/git/commits{/sha}","comments_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/comments{/number}","issue_comment_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/issues/comments{/number}","contents_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/contents/{+path}","compare_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/merges","archive_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/downloads","issues_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/issues{/number}","pulls_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/pulls{/number}","milestones_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/milestones{/number}","notifications_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/labels{/name}","releases_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/releases{/id}","deployments_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/deployments","created_at":"2018-01-10T23:03:16Z","updated_at":"2018-03-01T21:22:34Z","pushed_at":"2018-03-01T22:26:59Z","git_url":"git://github.com/Microsoft/botbuilder-dotnet.git","ssh_url":"git@github.com:Microsoft/botbuilder-dotnet.git","clone_url":"https://github.com/Microsoft/botbuilder-dotnet.git","svn_url":"https://github.com/Microsoft/botbuilder-dotnet","homepage":null,"size":1283,"stargazers_count":44,"watchers_count":44,"language":"C#","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":22,"mirror_url":null,"archived":false,"open_issues_count":40,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":22,"open_issues":40,"watchers":44,"default_branch":"master"}},"base":{"label":"Microsoft:master","ref":"master","sha":"d28d218f78a735f6b43399844b04b3bc654fda23","user":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars2.githubusercontent.com/u/6154722?v=4","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"repo":{"id":117021670,"name":"botbuilder-dotnet","full_name":"Microsoft/botbuilder-dotnet","owner":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars2.githubusercontent.com/u/6154722?v=4","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Microsoft/botbuilder-dotnet","description":".NET SDK used to build chat bots for the Microsoft Bot Framework.","fork":false,"url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet","forks_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/forks","keys_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/teams","hooks_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/hooks","issue_events_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/issues/events{/number}","events_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/events","assignees_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/assignees{/user}","branches_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/branches{/branch}","tags_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/tags","blobs_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/git/refs{/sha}","trees_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/statuses/{sha}","languages_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/languages","stargazers_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/stargazers","contributors_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/contributors","subscribers_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/subscribers","subscription_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/subscription","commits_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/commits{/sha}","git_commits_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/git/commits{/sha}","comments_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/comments{/number}","issue_comment_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/issues/comments{/number}","contents_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/contents/{+path}","compare_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/merges","archive_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/downloads","issues_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/issues{/number}","pulls_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/pulls{/number}","milestones_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/milestones{/number}","notifications_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/labels{/name}","releases_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/releases{/id}","deployments_url":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/deployments","created_at":"2018-01-10T23:03:16Z","updated_at":"2018-03-01T21:22:34Z","pushed_at":"2018-03-01T22:26:59Z","git_url":"git://github.com/Microsoft/botbuilder-dotnet.git","ssh_url":"git@github.com:Microsoft/botbuilder-dotnet.git","clone_url":"https://github.com/Microsoft/botbuilder-dotnet.git","svn_url":"https://github.com/Microsoft/botbuilder-dotnet","homepage":null,"size":1283,"stargazers_count":44,"watchers_count":44,"language":"C#","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":22,"mirror_url":null,"archived":false,"open_issues_count":40,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":22,"open_issues":40,"watchers":44,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/pulls/228"},"html":{"href":"https://github.com/Microsoft/botbuilder-dotnet/pull/228"},"issue":{"href":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/issues/228"},"comments":{"href":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/issues/228/comments"},"review_comments":{"href":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/pulls/228/comments"},"review_comment":{"href":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/pulls/228/commits"},"statuses":{"href":"https://api.github.com/repos/Microsoft/botbuilder-dotnet/statuses/955612eed03e1ffae669e4750618616060ca8716"}},"author_association":"NONE"}}
{"actor":{"display_login":"emadelwany"}}