Example #1
0
        private IPrompt <T> NextClarifyPrompt(T state, FieldStepState stepState, IRecognize <T> recognizer, out Ambiguous clarify)
        {
            IPrompt <T> prompter = null;

            clarify = null;
            foreach (var clarification in stepState.Clarifications)
            {
                if (clarification.Values.Length > 1)
                {
                    clarify = clarification;
                    break;
                }
            }
            if (clarify != null)
            {
                var field = new Field <T>("__clarify__", FieldRole.Value);
                field.Form = _field.Form;
                var template     = _field.Template(TemplateUsage.Clarify);
                var helpTemplate = _field.Template(template.AllowNumbers ? TemplateUsage.EnumOneNumberHelp : TemplateUsage.EnumManyNumberHelp);
                field.SetPrompt(new PromptAttribute(template));
                field.ReplaceTemplate(_field.Template(TemplateUsage.Clarify));
                field.ReplaceTemplate(helpTemplate);
                foreach (var value in clarify.Values)
                {
                    field.AddDescription(value, recognizer.ValueDescription(value));
                    field.AddTerms(value, recognizer.ValidInputs(value).ToArray());
                }
                var choiceRecognizer = new RecognizeEnumeration <T>(field);
                prompter = new Prompter <T>(template, _field.Form, choiceRecognizer);
            }
            return(prompter);
        }
Example #2
0
        private FormPrompt ClarifyPrompt(FieldStepState stepState, IRecognize <T> recognizer, T state)
        {
            var        clarify = NeedsClarification(stepState);
            FormPrompt prompt  = null;

            if (clarify != null)
            {
                var field    = ClarifyField(clarify, recognizer);
                var prompter = new Prompter <T>(field.Template(TemplateUsage.Clarify), field.Form, new RecognizeEnumeration <T>(field));
                prompt = prompter.Prompt(state, field, clarify.Response);
            }
            return(prompt);
        }
Example #3
0
        private Ambiguous NeedsClarification(FieldStepState stepState)
        {
            Ambiguous clarify = null;

            foreach (var clarification in stepState.Clarifications)
            {
                if (clarification.Values.Length > 1)
                {
                    clarify = clarification;
                    break;
                }
            }
            return(clarify);
        }
Example #4
0
        private IRecognize <T> ClarifyRecognizer(FieldStepState stepState, IRecognize <T> recognizer)
        {
            var clarify = NeedsClarification(stepState);

            return(clarify != null ? new RecognizeEnumeration <T>(ClarifyField(clarify, recognizer)) : null);
        }