示例#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 AddressParseService(ChatConfiguration chatConfiguration)
        {
            Dictionary <string, string> headers = null;

            if (!String.IsNullOrEmpty(chatConfiguration.AddressParse.Key))
            {
                headers = new Dictionary <string, string>()
                {
                    { "x-api-key", chatConfiguration.AddressParse.Key }
                };
            }

            restApiService = new RestApiService(chatConfiguration.AddressParse.Url, null, headers);
        }
 public TextParserService(ChatConfiguration chatConfiguration)
 {
     restApiService = new RestApiService(chatConfiguration.TextParser);
 }
 public IntentGatewayService(UrlConfig urlConfig)
 {
     this.restApiIntentGateway = new RestApiService(urlConfig);
 }
示例#5
0
 public SpellcheckService(UrlConfig urlConfig)
 {
     ApiService = new RestApiService(urlConfig, null, 0);
 }
示例#6
0
 public FuzzyMatchService(ChatConfiguration chatConfiguration)
 {
     restApiService = new RestApiService(chatConfiguration.FuzzyMatch);
 }