Esempio n. 1
0
        public IEnumerable <TermMatch> Match(IDialogContext context, T state, FormState form, string input)
        {
            IEnumerable <TermMatch> matches = null;

            Debug.Assert(form.Phase() == StepPhase.Responding);
            var stepState = (FieldStepState)form.StepState;

            if (stepState.State == FieldStepStates.SentPrompt)
            {
                matches = _field.Prompt.Recognizer.Matches(input, _field.GetValue(state));
            }
            else if (stepState.State == FieldStepStates.SentClarify)
            {
                var       fieldState = (FieldStepState)form.StepState;
                var       iprompt    = _field.Prompt;
                Ambiguous clarify;
                var       iChoicePrompt = NextClarifyPrompt(state, fieldState, iprompt.Recognizer, out clarify);
                matches = MatchAnalyzer.Coalesce(MatchAnalyzer.HighestConfidence(iChoicePrompt.Recognizer.Matches(input)), input).ToArray();
                if (matches.Count() > 1)
                {
                    matches = new TermMatch[0];
                }
            }
#if DEBUG
            if (FormDialog.DebugRecognizers)
            {
                MatchAnalyzer.PrintMatches(matches, 2);
            }
#endif
            return(matches);
        }
Esempio n. 2
0
        public IEnumerable <TermMatch> Match(IDialogContext context, T state, FormState form, IMessageActivity input)
        {
            IEnumerable <TermMatch> matches = null;

            Debug.Assert(form.Phase() == StepPhase.Responding);
            var stepState = (FieldStepState)form.StepState;

            if (stepState.State == FieldStepStates.SentPrompt)
            {
                matches = _field.Prompt.Recognizer.Matches(input, _field.GetValue(state));
            }
            else if (stepState.State == FieldStepStates.SentClarify)
            {
                var fieldState       = (FieldStepState)form.StepState;
                var iprompt          = _field.Prompt;
                var choiceRecognizer = ClarifyRecognizer(fieldState, iprompt.Recognizer);
                matches = MatchAnalyzer.Coalesce(MatchAnalyzer.HighestConfidence(choiceRecognizer.Matches(input)), MessageActivityHelper.GetSanitizedTextInput(input)).ToArray();
                if (matches.Count() > 1)
                {
                    matches = new TermMatch[0];
                }
            }
#if DEBUG
            if (FormDialog.DebugRecognizers)
            {
                MatchAnalyzer.PrintMatches(matches, 2);
            }
#endif
            return(matches);
        }
Esempio n. 3
0
        public override IEnumerable <TermMatch> Matches(IMessageActivity input, object defaultValue = null)
        {
            var result = new List <TermMatch>();

            // get awaitable attachment default or custom type
            var awaitableAttachmentType = this.GetAttachmentTypeFromField();

            if (string.IsNullOrWhiteSpace(input.Text))
            {
                input.Text = string.Empty;
            }

            // create attachment list
            var attachments = Activator.CreateInstance(typeof(List <>).MakeGenericType(awaitableAttachmentType)) as IList;

            foreach (var attachment in input.Attachments)
            {
                var awaitableAttachment = Activator.CreateInstance(awaitableAttachmentType, attachment) as AwaitableAttachment;
                attachments.Add(awaitableAttachment);
            }

            // build result
            if (attachments.Count > 0)
            {
                result.Add(new TermMatch(0, input.Text.Length, 1.0, this.multipleAttachments ? attachments : attachments[0]));
            }
            else if (_field.Optional)
            {
                var commandRecognizer = _field.Form.BuildCommandRecognizer();
                var commands          = (input.Text == null || input.Text.Trim().StartsWith("\""))
                    ? new TermMatch[0]
                    : MatchAnalyzer.Coalesce(commandRecognizer.Prompt.Recognizer.Matches(input), input.Text);

                // if optional and no result at all then assign defaultValue
                if (!commands.Any())
                {
                    result.Add(new TermMatch(0, input.Text.Length, 1.0, defaultValue));
                }
            }

            return(result);
        }