async Task <string> TestMessage(string message, string expectedIntent)
        {
            await m_lock.WaitAsync();

            try
            {
                var response = await ClassificationService.ClassifyAsync(null, ChatConfiguration.MininimConfidenceRatio, message, true, false);

                //if (response?.Length == 0)
                //    return "";

                if (String.IsNullOrEmpty(expectedIntent))
                {
                    Assert.AreEqual(response?.TopResults?.Length, 0, $"Test: {message}");
                    return(null);
                }

                Assert.AreNotEqual(response?.TopResults?.Length, 0, $"Test: {message}");
                Assert.AreEqual(expectedIntent, response.TopResults[0].Intent, $"Test: {message}");

                return(response.TopResults[0].Intent);
            }
            finally
            {
                m_lock.Release();
            }
        }
Пример #2
0
        public async Task <ClassificationResults> ClassifyText(string text, string preFlowName, string preStepId, string postFlowName, string postStepId, bool allowSmsClassifications)
        {
            var setupFlowStep = await externalDataStorageService.GetFlowStep(preFlowName, preStepId, false);

            if (setupFlowStep == null)
            {
                throw new ApplicationException($"Parse: Invalid Setup Flow step for IntentGateway parser. {preFlowName}-{preStepId}");
            }

            var postFlowStep = await externalDataStorageService.GetFlowStep(postFlowName, postStepId, false);

            if (postFlowName == null)
            {
                throw new ApplicationException($"Parse: Invalid Post Flow step for IntentGateway parser. {postFlowName}-{postStepId}");
            }

            var classifierData = await chatScriptManager.ProcessActions(chatModel, setupFlowStep, null, true);

            var intentGatewayConfig = JsonConvert.DeserializeObject <IntentGatewayConfig>(JsonConvert.SerializeObject(classifierData));

            IntentGatewayService intentGatewayService;

            if (String.IsNullOrEmpty(intentGatewayConfig?.Url))
            {
                intentGatewayService = new IntentGatewayService(chatConfiguration.IntentGateway);
            }
            else
            {
                intentGatewayService = new IntentGatewayService(
                    new UrlConfig()
                {
                    Url = intentGatewayConfig.Url,
                    Key = intentGatewayConfig.Key
                });
                classifierData = intentGatewayConfig.Body;
            }

            var classifications = await classificationService.ClassifyAsync(intentGatewayService, 0.0, text, false, classifierData, allowSmsClassifications);

            await PostProcessResults(classifications, postFlowStep);

            return(classifications);
        }
Пример #3
0
        public override async Task <ParseResult> ParseAsync(ChatState chatState, Chat_ParseField chatParseField, ChatMessage message)
        {
            // Strip PII data
            string text        = filterService.FilterUserData(chatState, message.CorrectedUserInput, false);
            string classifiers = chatParseField?.GetProperty("Classifiers") ?? defaultClassifier;

            message.Classifications = await classificationService.ClassifyAsync(classifiers, threshold, text, false, chatState.SessionData.IsSmsChannel);

            chatState.UpdateLastClassification(message.Classifications);

            if (message.Classifications.IsSuccessful)
            {
                // We don't want common chat intent's here.
                if (message.Classifications.GetBestResult().Intent.StartsWith("commonchat-"))
                {
                    return(ParseResult.Failed);
                }

                return(ParseResult.CreateSuccess(message.Classifications.GetBestResult().Intent));
            }

            return(ParseResult.Failed);
        }