示例#1
0
        async Task <ClassificationResponse[]> CallClassifier(ClassifierConfigSection info, string message)
        {
            var scoreRequest = new
            {
                Inputs = new Dictionary <string, StringTable>()
                {
                    {
                        "input1",
                        new StringTable()
                        {
                            ColumnNames = new string[] { "category", "text" },
                            Values      = new string[, ] {
                                { "value", message }
                            }
                        }
                    },
                },
                GlobalParameters = new Dictionary <string, string>()
                {
                }
            };

            RestApiService restApiService = new RestApiService(info.Url, info.Key);
            string         result         = await restApiService.CallRestApi(null, JsonConvert.SerializeObject(scoreRequest), "application/json");

            if (result == null)
            {
                logger.ErrorFormat("Network: Failed to call classifier service. {0}", info.Url);

                return(new ClassificationResponse[] { });
            }

            var answer = JsonConvert.DeserializeObject <dynamic>(result);

            Dictionary <string, object>   results         = ConvertTableToDictionary(answer.Results.output1.value);
            List <ClassificationResponse> classifications = new List <ClassificationResponse>();

            foreach (var key in results.Keys)
            {
                var match = Regex.Match(key, "Scored Probabilities for Class \"(.*)\"");
                if (match.Success)
                {
                    double probability = (double)results[key];
                    classifications.Add(new ClassificationResponse
                    {
                        Intent = match.Groups[1].Value,
                        Result = new Dictionary <string, object> {
                            { "intent", match.Groups[1].Value }, { "selected_system", info.Id }, { "score", probability }
                        },
                        Probability = probability,
                        Source      = "azureml",
                        SourceData  = info.Id,
                        RawResponse = result //answer
                    });
                }
            }

            return(classifications.OrderByDescending(c => c.Probability).Take(2).ToArray());
        }
示例#2
0
        public async Task <FuzzyMatchResponse> Match(string message, string[] candidates)
        {
            var requestNew = new FuzzyMatchRequest {
                Text = message, Candidates = candidates
            };

            return(await restApiService.CallRestApi <FuzzyMatchResponse>("", requestNew));
        }
        public async Task <ClassificationResponse[]> Classify(object classifierData)
        {
            List <ClassificationResponse> results = new List <ClassificationResponse>();

            logger.DebugFormat("Network: IntentGateway calling '{0}' with '{1}'", restApiIntentGateway.BaseUrl, JsonConvert.SerializeObject(classifierData));
            var response = await restApiIntentGateway.CallRestApi(null, classifierData);

            if (response != null)
            {
                results.Add(new ClassificationResponse()
                {
                    Intent      = "",
                    Probability = 1.0,
                    SourceData  = JsonConvert.SerializeObject(classifierData),
                    Source      = "intentgateway",
                    RawResponse = response
                });
            }

            return(results.ToArray());
        }
示例#4
0
        public async Task <string> SpellcheckAsync(string message)
        {
            if (String.IsNullOrEmpty(message))
            {
                return(String.Empty);
            }

            var request = new SpellcheckServiceRequest()
            {
                Text = message
            };

            var response = await ApiService.CallRestApi <SpellcheckServiceResponse>("", request, ChatConfiguration.SpellCheckTimeout);

            if (response == null)
            {
                return(message);
            }

            return(response.Output.Words);
        }
示例#5
0
        public async Task <ParseAddressDTO> Parse(string chatId, ChatState chatState, string text)
        {
            var request = new AddressParseRequest()
            {
                sessionId     = chatId,
                interactionId = System.Diagnostics.Trace.CorrelationManager.ActivityId.ToString(),
                addressText   = text,
                partner       = chatState.GlobalAnswers.GetFieldAnswer(ChatStandardField.Partner)?.ToLower(),
                context       = chatState.GlobalAnswers.GetFieldAnswer(ChatStandardField.Context)?.ToLower()
            };

            var response = await restApiService.CallRestApi <AddressParseResponse>(null, request, Timeout);

            if ((response?.parseAddressDTO?.response == "0") && (response?.parseAddressDTO?.addresses?.Length > 0))
            {
                return(response.parseAddressDTO);
            }

            logger.InfoFormat("Parse: AddressParseService did not parse any address.");

            return(null);
        }
 public async Task <TextParserResponse> Parse(string message)
 {
     return(await restApiService.CallRestApi <TextParserResponse>("", message, "plain/text"));
 }