/// <summary>
 /// Describe an image in natural language
 /// </summary>
 /// Generate an English language text description of the image as a sentence.
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='imageFile'>
 /// Image file to perform the operation on.  Common file formats such as PNG,
 /// JPEG are supported.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <DescribeOKResponse> DescribeAsync(this IRecognize operations, System.IO.Stream imageFile, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.DescribeWithHttpMessagesAsync(imageFile, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
コード例 #2
0
 /// <summary>
 /// Construct a prompter.
 /// </summary>
 /// <param name="annotation">Annotation describing the \ref patterns and formatting for prompt.</param>
 /// <param name="form">Current form.</param>
 /// <param name="recognizer">Recognizer if any.</param>
 public Prompter(TemplateBaseAttribute annotation, IForm <T> form, IRecognize <T> recognizer)
 {
     annotation.ApplyDefaults(form.Configuration.DefaultPrompt);
     _annotation = annotation;
     _form       = form;
     _recognizer = recognizer;
 }
コード例 #3
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);
        }
コード例 #4
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);
        }
コード例 #5
0
        public bool Equals(IRecognize other)
        {
            if (other == null)
            {
                return(false);
            }

            if (!(other is RecognizeFirstBytes fb))
            {
                return(false);
            }

            if (!this.bytes.SequenceEqual(fb.bytes))
            {
                return(false);
            }

            return(true);
        }
コード例 #6
0
        private IField <T> ClarifyField(Ambiguous clarify, IRecognize <T> recognizer)
        {
            var field = new FieldClarify(_field);

            foreach (var value in clarify.Values)
            {
                var choice = value as Choice;
                if (choice != null)
                {
                    field.AddDescription(choice.Value,
                                         choice.Description.Description,
                                         choice.Description.Image,
                                         choice.Description.Message);
                    field.AddTerms(choice.Value, choice.Terms.Alternatives);
                }
                else
                {
                    var desc = recognizer.ValueDescription(value);
                    field.AddDescription(value, desc.Description, desc.Image);
                    field.AddTerms(value, recognizer.ValidInputs(value).ToArray());
                }
            }
            return(field);
        }
コード例 #7
0
 /// <summary> Sets the recognizer for the field. </summary>
 /// <param name="recognizer">   The recognizer for the field. </param>
 /// <returns>   A <see cref="Field{T}"/>. </returns>
 /// <remarks>
 /// This should only be called when you are dynamically defining a field using a <see cref="DefineAsyncDelegate{T}"/> because
 /// recognizers usually require the field and often change if the localization changes.
 /// </remarks>
 public Field <T> SetRecognizer(IRecognize <T> recognizer)
 {
     _recognizer = recognizer;
     return(this);
 }
コード例 #8
0
 /// <summary> Sets the recognizer for the field. </summary>
 /// <param name="recognizer">   The recognizer for the field. </param>
 /// <returns>   A <see cref="Field{T}"/>. </returns>
 /// <remarks>
 /// This should only be called when you are dynamically defining a field using a <see cref="DefineAsyncDelegate{T}"/> because
 /// recognizers usually require the field and often change if the localization changes.
 /// </remarks>
 public Field <T> SetRecognizer(IRecognize <T> recognizer)
 {
     _recognizer   = recognizer;
     _buildPrompts = true;
     return(this);
 }
コード例 #9
0
        private IRecognize <T> ClarifyRecognizer(FieldStepState stepState, IRecognize <T> recognizer)
        {
            var clarify = NeedsClarification(stepState);

            return(clarify != null ? new RecognizeEnumeration <T>(ClarifyField(clarify, recognizer)) : null);
        }
コード例 #10
0
        private IPrompt <T> Template(TemplateUsage usage, IRecognize <T> recognizer = null)
        {
            var template = _field.Template(usage);

            return(new Prompter <T>(template, _field.Form, recognizer == null ? _field.Prompt.Recognizer : recognizer));
        }
 /// <summary>
 /// Describe an image in natural language
 /// </summary>
 /// Generate an English language text description of the image as a sentence.
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='imageFile'>
 /// Image file to perform the operation on.  Common file formats such as PNG,
 /// JPEG are supported.
 /// </param>
 public static DescribeOKResponse Describe(this IRecognize operations, System.IO.Stream imageFile)
 {
     return(Task.Factory.StartNew(s => ((IRecognize)s).DescribeAsync(imageFile), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }
コード例 #12
0
 /// <summary> Sets the recognizer for the field. </summary>
 /// <param name="recognizer">   The recognizer for the field. </param>
 /// <returns>   A Field&lt;T&gt; </returns>
 public Field <T> SetRecognizer(IRecognize <T> recognizer)
 {
     UpdateAnnotations();
     _recognizer = recognizer;
     return(this);
 }