示例#1
0
        public static async Task <AskQuestionResponse> AnswerQuestion(AskQuestionRequest request, ICollector <SessionTableEntity> sessionTable)
        {
            // Get unique identifier
            string   id           = Guid.NewGuid().ToString();
            DateTime timestampUtc = DateTime.UtcNow;

            // Run keyphrases extraction
            request.Topics = await ServicesUtility.GetTopics(request.Question, request.Topics);

            // Run search services
            string queryWithTopics = request.Topics?.Count() > 0 ? string.Join(" ", request.Topics).Trim() : request.Question;

            // Process results
            AskQuestionResponse response = new AskQuestionResponse()
            {
                Id      = id,
                Results = new AskQuestionResult[0]
            };

            double confidenceScoreThreshold = 20;

            // Get results from QnA maker
            QnAMakerSearchResult qnaResult =
                await ServicesUtility.QnAMaker.GenerateAnswerAsync(queryWithTopics, SettingsUtility.QnAMakerWhoTaskKnowledgebaseId);

            if (qnaResult.Answers?.Where(a => a.Score >= confidenceScoreThreshold).Count() > 0)
            {
                response.Results = ServicesUtility.GetAskQuestionResults(qnaResult, confidenceScoreThreshold, true);
            }
            else
            {
                // Create Bing Search tasks
                BingWebSearchResult bingWebSearchResult =
                    await ServicesUtility.BingSearch.SearchWebAsync(query : request.Question, count : SettingsUtility.MaxResultsCount);

                // Process Bing search results
                if (bingWebSearchResult.WebPagesResult?.Values?.Count() > 0)
                {
                    response.Results = ServicesUtility.GetAskQuestionResults(bingWebSearchResult);
                }
            }

            // Write to session table
            sessionTable.Add(new SessionTableEntity(id, timestampUtc, "Who", request, response));

            // Return response
            return(response);
        }
            public static async Task <AskQuestionResponse> AnswerQuestion(AskQuestionRequest request, ICollector <SessionTableEntity> sessionTable)
            {
                // Get unique identifier
                string   id           = Guid.NewGuid().ToString();
                DateTime timestampUtc = DateTime.UtcNow;

                // Get key phrases extraction
                request.Topics = await ServicesUtility.GetTopics(request.Question, request.Topics);

                string queryWithTopics = request.Topics?.Count() > 0 ? string.Join(" ", request.Topics).Trim() : request.Question;

                // Create video indexer task
                VideoIndexerSearchResult videoIndexerResult = await ServicesUtility.VideoIndexer.SearchAsync(query : queryWithTopics);


                // Process results
                AskQuestionResponse response = new AskQuestionResponse()
                {
                    Id      = id,
                    Results = new AskQuestionResult[0]
                };

                if (videoIndexerResult.Results?.Count() > 0)
                {
                    response.Results = ServicesUtility.GetAskQuestionResults(videoIndexerResult);
                }
                else
                {
                    // Create Bing Search tasks
                    BingWebSearchResult bingWebSearchResult =
                        await ServicesUtility.BingSearch.SearchWebAsync(query : request.Question, count : SettingsUtility.MaxResultsCount);

                    // Process Bing search results
                    if (bingWebSearchResult.WebPagesResult?.Values?.Count() > 0)
                    {
                        response.Results = ServicesUtility.GetAskQuestionResults(bingWebSearchResult);
                    }
                }

                // Write to session table
                sessionTable.Add(new SessionTableEntity(id, timestampUtc, "LearnMore", request, response));

                // Return response
                return(response);
            }
示例#3
0
        public static async Task <AskQuestionResponse> AnswerQuestion(AskQuestionRequest request, ICollector <SessionTableEntity> sessionTable)
        {
            // Get unique identifier
            string   id           = Guid.NewGuid().ToString();
            DateTime timestampUtc = DateTime.UtcNow;

            // Run keyphrases extraction
            request.Topics = await ServicesUtility.GetTopics(request.Question, request.Topics);

            // Run search services
            string queryWithTopics = request.Topics?.Count() > 0 ? string.Join(" ", request.Topics).Trim() : request.Question;

            // Create Bing Search task
            BingWebSearchResult bingWebSearchResult =
                await ServicesUtility.BingSearch.SearchWebAsync(query : request.Question, count : SettingsUtility.MaxResultsCount);

            // Process results
            AskQuestionResponse response = new AskQuestionResponse()
            {
                Id      = id,
                Results = new AskQuestionResult[0]
            };

            // Process Bing search results
            if (bingWebSearchResult.WebPagesResult?.Values?.Count() > 0)
            {
                response.Results = ServicesUtility.GetAskQuestionResults(bingWebSearchResult);
            }

            // Upload search document to dashboard
            await ServicesUtility.UploadDocumentToSearchService(SettingsUtility.AzureSearchIndexName, new SessionSearchDocument(id, timestampUtc, "AskQuestion", request, response));

            // Write to session table
            sessionTable.Add(new SessionTableEntity(id, timestampUtc, "Question", request, response));

            // Return response
            return(response);
        }