public async Task StartRecognizeCustomFormsWithLabelsCanParseBlankPage() { var client = CreateInstrumentedFormRecognizerClient(); var options = new RecognizeOptions() { IncludeTextContent = true }; RecognizeCustomFormsOperation operation; await using var trainedModel = await CreateDisposableTrainedModelAsync(useTrainingLabels : true); using var stream = FormRecognizerTestEnvironment.CreateStream(TestFile.Blank); using (Recording.DisableRequestBodyRecording()) { operation = await client.StartRecognizeCustomFormsAsync(trainedModel.ModelId, stream, options); } RecognizedFormCollection recognizedForms = await operation.WaitForCompletionAsync(); var recognizedForm = recognizedForms.Single(); ValidateRecognizedForm(recognizedForm, includeTextContent: true, expectedFirstPageNumber: 1, expectedLastPageNumber: 1); var blankPage = recognizedForm.Pages.Single(); Assert.AreEqual(0, blankPage.Lines.Count); Assert.AreEqual(0, blankPage.Tables.Count); }
public SpeechRecognitionEvent Recognize(FileStream audio, RecognizeOptions options) { if (audio == null) { throw new ArgumentNullException("The audio file is null or does not exist"); } if (options == null) { throw new ArgumentNullException("The options is null or does not exist"); } SpeechRecognitionEvent result = null; try { double fileSize = audio.Length / Math.Pow(1024, 2); if (fileSize > 100.0) { throw new Exception("The audio file is greater than 100MB."); } string contentType = audio.GetMediaTypeFromFile(); if (string.IsNullOrEmpty(contentType)) { throw new Exception("The audio format cannot be recognized"); } StreamContent content = new StreamContent(audio); content.Headers.Add("Content-Type", contentType); string path = string.Empty; if (options != null && !string.IsNullOrEmpty(options.SessionId)) { path = string.Format(PATH_SESSION_RECOGNIZE, options.SessionId); } result = this.Client.WithAuthentication(this.UserName, this.Password) .PostAsync(RELATIVE_PATH + PATH_RECOGNIZE) .WithArguments(options.GetArguments()) .WithBodyContent(content) .As <SpeechRecognitionEvent>() .Result; } catch (AggregateException ae) { throw ae.Flatten(); } return(result); }
public virtual RecognizeContentOperation StartRecognizeContent(Stream form, RecognizeOptions recognizeOptions = default, CancellationToken cancellationToken = default) { Argument.AssertNotNull(form, nameof(form)); recognizeOptions ??= new RecognizeOptions(); FormContentType contentType = recognizeOptions.ContentType ?? DetectContentType(form, nameof(form)); ResponseWithHeaders <ServiceAnalyzeLayoutAsyncHeaders> response = ServiceClient.AnalyzeLayoutAsync(contentType, form, cancellationToken); return(new RecognizeContentOperation(ServiceClient, response.Headers.OperationLocation)); }
public void StartRecognizeCustomFormsValidatesTheModelIdFormat() { var client = CreateClient(); using var stream = new MemoryStream(Array.Empty <byte>()); var options = new RecognizeOptions { ContentType = FormContentType.Jpeg }; Assert.ThrowsAsync <ArgumentException>(async() => await client.StartRecognizeCustomFormsAsync("1975-04-04", stream, options)); }
public virtual RecognizeContentOperation StartRecognizeContent(Stream form, RecognizeOptions recognizeOptions = default, CancellationToken cancellationToken = default) { Argument.AssertNotNull(form, nameof(form)); recognizeOptions ??= new RecognizeOptions(); FormContentType contentType = recognizeOptions.ContentType ?? DetectContentType(form, nameof(form)); Response response = ServiceClient.AnalyzeLayoutAsync(contentType, form, cancellationToken); string location = ClientCommon.GetResponseHeader(response.Headers, Constants.OperationLocationHeader); return(new RecognizeContentOperation(ServiceClient, Diagnostics, location)); }
public async Task StartRecognizeCustomFormsWithoutLabelsCanParseMultipageFormWithBlankPage() { var client = CreateInstrumentedFormRecognizerClient(); var options = new RecognizeOptions() { IncludeTextContent = true }; RecognizeCustomFormsOperation operation; await using var trainedModel = await CreateDisposableTrainedModelAsync(useTrainingLabels : false); using var stream = FormRecognizerTestEnvironment.CreateStream(TestFile.InvoiceMultipageBlank); using (Recording.DisableRequestBodyRecording()) { operation = await client.StartRecognizeCustomFormsAsync(trainedModel.ModelId, stream, options); } RecognizedFormCollection recognizedForms = await operation.WaitForCompletionAsync(); Assert.AreEqual(3, recognizedForms.Count); for (int formIndex = 0; formIndex < recognizedForms.Count; formIndex++) { var recognizedForm = recognizedForms[formIndex]; var expectedPageNumber = formIndex + 1; ValidateRecognizedForm(recognizedForm, includeTextContent: true, expectedFirstPageNumber: expectedPageNumber, expectedLastPageNumber: expectedPageNumber); // Basic sanity test to make sure pages are ordered correctly. if (formIndex == 0 || formIndex == 2) { var sampleField = recognizedForm.Fields["field-0"]; var expectedValueText = formIndex == 0 ? "300.00" : "3000.00"; Assert.IsNotNull(sampleField.LabelText); Assert.AreEqual("Subtotal:", sampleField.LabelText.Text); Assert.IsNotNull(sampleField.ValueText); Assert.AreEqual(expectedValueText, sampleField.ValueText.Text); } } var blankForm = recognizedForms[1]; Assert.AreEqual(0, blankForm.Fields.Count); var blankPage = blankForm.Pages.Single(); Assert.AreEqual(0, blankPage.Lines.Count); Assert.AreEqual(0, blankPage.Tables.Count); }
public void StartRecognizeCustomFormsRespectsTheCancellationToken() { var client = CreateInstrumentedClient(); var options = new RecognizeOptions { ContentType = FormContentType.Pdf }; using var stream = new MemoryStream(Array.Empty <byte>()); using var cancellationSource = new CancellationTokenSource(); cancellationSource.Cancel(); Assert.ThrowsAsync <TaskCanceledException>(async() => await client.StartRecognizeCustomFormsAsync("00000000-0000-0000-0000-000000000000", stream, recognizeOptions: options, cancellationToken: cancellationSource.Token)); }
public void StartRecognizeContentRespectsTheCancellationToken() { var client = CreateInstrumentedClient(); var options = new RecognizeOptions { ContentType = FormContentType.Pdf }; using var stream = new MemoryStream(Array.Empty <byte>()); using var cancellationSource = new CancellationTokenSource(); cancellationSource.Cancel(); Assert.ThrowsAsync(Is.InstanceOf <OperationCanceledException>(), async() => await client.StartRecognizeContentAsync(stream, options, cancellationSource.Token)); }
public async Task StartRecognizeReceiptsCanParseMultipageFormWithBlankPage() { var client = CreateInstrumentedFormRecognizerClient(); var options = new RecognizeOptions() { IncludeTextContent = true }; RecognizeReceiptsOperation operation; using var stream = FormRecognizerTestEnvironment.CreateStream(TestFile.InvoiceMultipageBlank); using (Recording.DisableRequestBodyRecording()) { operation = await client.StartRecognizeReceiptsAsync(stream, options); } RecognizedReceiptCollection recognizedReceipts = await operation.WaitForCompletionAsync(); Assert.AreEqual(3, recognizedReceipts.Count); for (int receiptIndex = 0; receiptIndex < recognizedReceipts.Count; receiptIndex++) { var recognizedReceipt = recognizedReceipts[receiptIndex]; var expectedPageNumber = receiptIndex + 1; Assert.AreEqual("en-US", recognizedReceipt.ReceiptLocale); Assert.NotNull(recognizedReceipt.RecognizedForm); ValidateRecognizedForm(recognizedReceipt.RecognizedForm, includeTextContent: true, expectedFirstPageNumber: expectedPageNumber, expectedLastPageNumber: expectedPageNumber); // Basic sanity test to make sure pages are ordered correctly. if (receiptIndex == 0 || receiptIndex == 2) { var sampleField = recognizedReceipt.RecognizedForm.Fields["MerchantName"]; var expectedValueText = receiptIndex == 0 ? "Bilbo Baggins" : "Frodo Baggins"; Assert.IsNotNull(sampleField.ValueText); Assert.AreEqual(expectedValueText, sampleField.ValueText.Text); } } var blankForm = recognizedReceipts[1].RecognizedForm; Assert.AreEqual(0, blankForm.Fields.Count); var blankPage = blankForm.Pages.Single(); Assert.AreEqual(0, blankPage.Lines.Count); Assert.AreEqual(0, blankPage.Tables.Count); }
public void StartRecognizeCustomFormsRequiresTheModelId(string modelId) { var client = CreateInstrumentedClient(); var expectedType = modelId == null ? typeof(ArgumentNullException) : typeof(ArgumentException); using var stream = new MemoryStream(Array.Empty <byte>()); var options = new RecognizeOptions { ContentType = FormContentType.Jpeg }; Assert.ThrowsAsync(expectedType, async() => await client.StartRecognizeCustomFormsAsync(modelId, stream, options)); }
public async Task StartRecognizeCustomFormsWithoutLabelsCanParseMultipageForms(bool useStream, bool includeTextContent) { var client = CreateInstrumentedFormRecognizerClient(); var options = new RecognizeOptions() { IncludeTextContent = includeTextContent }; RecognizeCustomFormsOperation operation; await using var trainedModel = await CreateDisposableTrainedModelAsync(useTrainingLabels : false); if (useStream) { using var stream = new FileStream(FormRecognizerTestEnvironment.MultipageFormPath, FileMode.Open); using (Recording.DisableRequestBodyRecording()) { operation = await client.StartRecognizeCustomFormsAsync(trainedModel.ModelId, stream, options); } } else { var uri = new Uri(FormRecognizerTestEnvironment.MultipageFormUri); operation = await client.StartRecognizeCustomFormsFromUriAsync(trainedModel.ModelId, uri, options); } RecognizedFormCollection recognizedForms = await operation.WaitForCompletionAsync(); Assert.AreEqual(2, recognizedForms.Count); for (int formIndex = 0; formIndex < recognizedForms.Count; formIndex++) { var recognizedForm = recognizedForms[formIndex]; var expectedPageNumber = formIndex + 1; ValidateRecognizedForm(recognizedForm, includeTextContent, expectedFirstPageNumber: expectedPageNumber, expectedLastPageNumber: expectedPageNumber); // Basic sanity test to make sure pages are ordered correctly. var sampleField = recognizedForm.Fields["field-0"]; var expectedValueText = formIndex == 0 ? "300.00" : "3000.00"; Assert.IsNotNull(sampleField.LabelText); Assert.AreEqual("Subtotal:", sampleField.LabelText.Text); Assert.IsNotNull(sampleField.ValueText); Assert.AreEqual(expectedValueText, sampleField.ValueText.Text); } }
public async Task StartRecognizeReceiptsCanParseMultipageForm(bool useStream, bool includeTextContent) { var client = CreateInstrumentedFormRecognizerClient(); var options = new RecognizeOptions() { IncludeTextContent = includeTextContent }; RecognizeReceiptsOperation operation; if (useStream) { using var stream = new FileStream(FormRecognizerTestEnvironment.MultipageFormPath, FileMode.Open); using (Recording.DisableRequestBodyRecording()) { operation = await client.StartRecognizeReceiptsAsync(stream, options); } } else { var uri = new Uri(FormRecognizerTestEnvironment.MultipageFormUri); operation = await client.StartRecognizeReceiptsFromUriAsync(uri, options); } RecognizedReceiptCollection recognizedReceipts = await operation.WaitForCompletionAsync(); Assert.AreEqual(2, recognizedReceipts.Count); for (int receiptIndex = 0; receiptIndex < recognizedReceipts.Count; receiptIndex++) { var recognizedReceipt = recognizedReceipts[receiptIndex]; var expectedPageNumber = receiptIndex + 1; Assert.AreEqual("en-US", recognizedReceipt.ReceiptLocale); Assert.NotNull(recognizedReceipt.RecognizedForm); ValidateRecognizedForm(recognizedReceipt.RecognizedForm, includeTextContent, expectedFirstPageNumber: expectedPageNumber, expectedLastPageNumber: expectedPageNumber); // Basic sanity test to make sure pages are ordered correctly. var sampleField = recognizedReceipt.RecognizedForm.Fields["MerchantName"]; var expectedValueText = receiptIndex == 0 ? "Bilbo Baggins" : "Frodo Baggins"; Assert.IsNotNull(sampleField.ValueText); Assert.AreEqual(expectedValueText, sampleField.ValueText.Text); } }
public async Task StartRecognizeCustomFormsWithLabelsCanParseMultipageForm(bool useStream) { var client = CreateInstrumentedFormRecognizerClient(); var options = new RecognizeOptions() { IncludeTextContent = true }; RecognizeCustomFormsOperation operation; await using var trainedModel = await CreateDisposableTrainedModelAsync(useTrainingLabels : true); if (useStream) { using var stream = FormRecognizerTestEnvironment.CreateStream(TestFile.InvoiceMultipage); using (Recording.DisableRequestBodyRecording()) { operation = await client.StartRecognizeCustomFormsAsync(trainedModel.ModelId, stream, options); } } else { var uri = FormRecognizerTestEnvironment.CreateUri(TestFile.InvoiceMultipage); operation = await client.StartRecognizeCustomFormsFromUriAsync(trainedModel.ModelId, uri, options); } RecognizedFormCollection recognizedForms = await operation.WaitForCompletionAsync(); var recognizedForm = recognizedForms.Single(); ValidateRecognizedForm(recognizedForm, includeTextContent: true, expectedFirstPageNumber: 1, expectedLastPageNumber: 2); // Add fields assertions when https://github.com/Azure/azure-sdk-for-net/issues/12139 // is solved. // Basic sanity test to make sure pages are ordered correctly. for (int pageIndex = 0; pageIndex < recognizedForm.Pages.Count; pageIndex++) { var formPage = recognizedForm.Pages[pageIndex]; var sampleLine = formPage.Lines[3]; var expectedText = pageIndex == 0 ? "Bilbo Baggins" : "Frodo Baggins"; Assert.AreEqual(expectedText, sampleLine.Text); } }
public async Task StartRecognizeCustomFormsWithLabelsCanParseMultipageFormWithBlankPage() { var client = CreateInstrumentedFormRecognizerClient(); var options = new RecognizeOptions() { IncludeTextContent = true }; RecognizeCustomFormsOperation operation; await using var trainedModel = await CreateDisposableTrainedModelAsync(useTrainingLabels : true); using var stream = FormRecognizerTestEnvironment.CreateStream(TestFile.InvoiceMultipageBlank); using (Recording.DisableRequestBodyRecording()) { operation = await client.StartRecognizeCustomFormsAsync(trainedModel.ModelId, stream, options); } RecognizedFormCollection recognizedForms = await operation.WaitForCompletionAsync(); var recognizedForm = recognizedForms.Single(); ValidateRecognizedForm(recognizedForm, includeTextContent: true, expectedFirstPageNumber: 1, expectedLastPageNumber: 3); for (int pageIndex = 0; pageIndex < recognizedForm.Pages.Count; pageIndex++) { if (pageIndex == 0 || pageIndex == 2) { var formPage = recognizedForm.Pages[pageIndex]; var sampleLine = formPage.Lines[3]; var expectedText = pageIndex == 0 ? "Bilbo Baggins" : "Frodo Baggins"; Assert.AreEqual(expectedText, sampleLine.Text); } } var blankPage = recognizedForm.Pages[1]; Assert.AreEqual(0, blankPage.Lines.Count); Assert.AreEqual(0, blankPage.Tables.Count); }
public async Task StartRecognizeCustomFormsWithLabelsCanParseMultipageForms(bool useStream, bool includeTextContent) { var client = CreateInstrumentedFormRecognizerClient(); var options = new RecognizeOptions() { IncludeTextContent = includeTextContent }; RecognizeCustomFormsOperation operation; await using var trainedModel = await CreateDisposableTrainedModelAsync(useTrainingLabels : true); if (useStream) { using var stream = new FileStream(FormRecognizerTestEnvironment.MultipageFormPath, FileMode.Open); using (Recording.DisableRequestBodyRecording()) { operation = await client.StartRecognizeCustomFormsAsync(trainedModel.ModelId, stream, options); } } else { var uri = new Uri(FormRecognizerTestEnvironment.MultipageFormUri); operation = await client.StartRecognizeCustomFormsFromUriAsync(trainedModel.ModelId, uri, options); } RecognizedFormCollection recognizedForms = await operation.WaitForCompletionAsync(); var recognizedForm = recognizedForms.Single(); ValidateRecognizedForm(recognizedForm, includeTextContent, expectedFirstPageNumber: 1, expectedLastPageNumber: 2); for (int formIndex = 0; formIndex < recognizedForms.Count; formIndex++) { // Basic sanity test to make sure pages are ordered correctly. // TODO: implement sanity check once #11821 is solved. } }
public async Task StartRecognizeContentSendsUserSpecifiedContentType() { var mockResponse = new MockResponse(202); mockResponse.AddHeader(new HttpHeader(Constants.OperationLocationHeader, "host/layout/analyzeResults/00000000000000000000000000000000")); var mockTransport = new MockTransport(new[] { mockResponse, mockResponse }); var options = new FormRecognizerClientOptions() { Transport = mockTransport }; var client = CreateInstrumentedClient(options); using var stream = FormRecognizerTestEnvironment.CreateStream(TestFile.InvoiceLeTiff); var recognizeOptions = new RecognizeOptions { ContentType = FormContentType.Jpeg }; await client.StartRecognizeContentAsync(stream, recognizeOptions); var request = mockTransport.Requests.Single(); Assert.True(request.Headers.TryGetValue("Content-Type", out var contentType)); Assert.AreEqual("image/jpeg", contentType); }
/// <summary> /// Recognizes layout elements from one or more passed-in forms. /// </summary> /// <param name="form">The stream containing one or more forms to recognize elements from.</param> /// <param name="recognizeOptions">A set of options available for configuring the recognize request.</param> /// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param> /// <returns>A <see cref="RecognizeContentOperation"/> to wait on this long-running operation. Its <see cref="RecognizeContentOperation.Value"/> upon successful /// completion will contain layout elements extracted from the form.</returns> public virtual RecognizeContentOperation StartRecognizeContent(Stream form, RecognizeOptions recognizeOptions = default, CancellationToken cancellationToken = default) { Argument.AssertNotNull(form, nameof(form)); recognizeOptions ??= new RecognizeOptions(); using DiagnosticScope scope = Diagnostics.CreateScope($"{nameof(FormRecognizerClient)}.{nameof(StartRecognizeContent)}"); scope.Start(); try { FormContentType contentType = recognizeOptions.ContentType ?? DetectContentType(form, nameof(form)); Response response = ServiceClient.AnalyzeLayoutAsync(contentType, form, cancellationToken); string location = ClientCommon.GetResponseHeader(response.Headers, Constants.OperationLocationHeader); return(new RecognizeContentOperation(ServiceClient, Diagnostics, location)); } catch (Exception e) { scope.Failed(e); throw; } }
public virtual RecognizeReceiptsOperation StartRecognizeReceipts(Stream receiptFileStream, RecognizeOptions recognizeOptions = default, CancellationToken cancellationToken = default) { Argument.AssertNotNull(receiptFileStream, nameof(receiptFileStream)); recognizeOptions ??= new RecognizeOptions(); ContentType contentType = recognizeOptions.ContentType ?? DetectContentType(receiptFileStream, nameof(receiptFileStream)); ResponseWithHeaders <ServiceAnalyzeReceiptAsyncHeaders> response = ServiceClient.RestClient.AnalyzeReceiptAsync(contentType, receiptFileStream, includeTextDetails: recognizeOptions.IncludeTextContent, cancellationToken); return(new RecognizeReceiptsOperation(ServiceClient, response.Headers.OperationLocation)); }
public virtual RecognizeContentOperation StartRecognizeContentFromUri(Uri formFileUri, RecognizeOptions recognizeOptions = default, CancellationToken cancellationToken = default) { Argument.AssertNotNull(formFileUri, nameof(formFileUri)); SourcePath_internal sourcePath = new SourcePath_internal(formFileUri.AbsoluteUri); ResponseWithHeaders <ServiceAnalyzeLayoutAsyncHeaders> response = ServiceClient.AnalyzeLayoutAsync(sourcePath, cancellationToken); return(new RecognizeContentOperation(ServiceClient, response.Headers.OperationLocation)); }
public virtual RecognizeReceiptsOperation StartRecognizeReceipts(Stream receipt, RecognizeOptions recognizeOptions = default, CancellationToken cancellationToken = default) { Argument.AssertNotNull(receipt, nameof(receipt)); recognizeOptions ??= new RecognizeOptions(); FormContentType contentType = recognizeOptions.ContentType ?? DetectContentType(receipt, nameof(receipt)); Response response = ServiceClient.AnalyzeReceiptAsync(contentType, receipt, includeTextDetails: recognizeOptions.IncludeTextContent, cancellationToken); string location = ClientCommon.GetResponseHeader(response.Headers, Constants.OperationLocationHeader); return(new RecognizeReceiptsOperation(ServiceClient, Diagnostics, location)); }
public virtual async Task <RecognizeContentOperation> StartRecognizeContentFromUriAsync(Uri formUrl, RecognizeOptions recognizeOptions = default, CancellationToken cancellationToken = default) { Argument.AssertNotNull(formUrl, nameof(formUrl)); SourcePath_internal sourcePath = new SourcePath_internal(formUrl.AbsoluteUri); Response response = await ServiceClient.AnalyzeLayoutAsyncAsync(sourcePath, cancellationToken).ConfigureAwait(false); string location = ClientCommon.GetResponseHeader(response.Headers, Constants.OperationLocationHeader); return(new RecognizeContentOperation(ServiceClient, Diagnostics, location)); }
public virtual RecognizeCustomFormsOperation StartRecognizeCustomForms(string modelId, Stream formFileStream, RecognizeOptions recognizeOptions = default, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(modelId, nameof(modelId)); Argument.AssertNotNull(formFileStream, nameof(formFileStream)); Guid guid = ClientCommon.ValidateModelId(modelId, nameof(modelId)); recognizeOptions ??= new RecognizeOptions(); FormContentType contentType = recognizeOptions.ContentType ?? DetectContentType(formFileStream, nameof(formFileStream)); Response response = ServiceClient.AnalyzeWithCustomModel(guid, contentType, formFileStream, includeTextDetails: recognizeOptions.IncludeTextContent, cancellationToken); string location = ClientCommon.GetResponseHeader(response.Headers, Constants.OperationLocationHeader); return(new RecognizeCustomFormsOperation(ServiceClient, Diagnostics, location)); }
public virtual RecognizeReceiptsOperation StartRecognizeReceiptsFromUri(Uri receiptUrl, RecognizeOptions recognizeOptions = default, CancellationToken cancellationToken = default) { Argument.AssertNotNull(receiptUrl, nameof(receiptUrl)); recognizeOptions ??= new RecognizeOptions(); SourcePath_internal sourcePath = new SourcePath_internal(receiptUrl.AbsoluteUri); Response response = ServiceClient.AnalyzeReceiptAsync(includeTextDetails: recognizeOptions.IncludeTextContent, sourcePath, cancellationToken); string location = ClientCommon.GetResponseHeader(response.Headers, Constants.OperationLocationHeader); return(new RecognizeReceiptsOperation(ServiceClient, Diagnostics, location)); }
public virtual async Task <RecognizeCustomFormsOperation> StartRecognizeCustomFormsFromUriAsync(string modelId, Uri formFileUri, RecognizeOptions recognizeOptions = default, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(modelId, nameof(modelId)); Argument.AssertNotNull(formFileUri, nameof(formFileUri)); Guid guid = ClientCommon.ValidateModelId(modelId, nameof(modelId)); recognizeOptions ??= new RecognizeOptions(); SourcePath_internal sourcePath = new SourcePath_internal(formFileUri.ToString()); ResponseWithHeaders <ServiceAnalyzeWithCustomModelHeaders> response = await ServiceClient.RestClient.AnalyzeWithCustomModelAsync(guid, includeTextDetails : recognizeOptions.IncludeTextContent, sourcePath, cancellationToken).ConfigureAwait(false); return(new RecognizeCustomFormsOperation(ServiceClient, Diagnostics, response.Headers.OperationLocation)); }
public virtual RecognizeCustomFormsOperation StartRecognizeCustomFormsFromUri(string modelId, Uri formFileUri, RecognizeOptions recognizeOptions = default, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(modelId, nameof(modelId)); Argument.AssertNotNull(formFileUri, nameof(formFileUri)); Guid guid = ClientCommon.ValidateModelId(modelId, nameof(modelId)); recognizeOptions ??= new RecognizeOptions(); SourcePath_internal sourcePath = new SourcePath_internal(formFileUri.AbsoluteUri); Response response = ServiceClient.AnalyzeWithCustomModel(guid, includeTextDetails: recognizeOptions.IncludeTextContent, sourcePath, cancellationToken); string location = ClientCommon.GetResponseHeader(response.Headers, Constants.OperationLocationHeader); return(new RecognizeCustomFormsOperation(ServiceClient, Diagnostics, location)); }
public virtual async Task <RecognizeCustomFormsOperation> StartRecognizeCustomFormsAsync(string modelId, Stream formFileStream, RecognizeOptions recognizeOptions = default, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(modelId, nameof(modelId)); Argument.AssertNotNull(formFileStream, nameof(formFileStream)); Guid guid = ClientCommon.ValidateModelId(modelId, nameof(modelId)); recognizeOptions ??= new RecognizeOptions(); ContentType contentType = recognizeOptions.ContentType ?? DetectContentType(formFileStream, nameof(formFileStream)); ResponseWithHeaders <ServiceAnalyzeWithCustomModelHeaders> response = await ServiceClient.RestClient.AnalyzeWithCustomModelAsync(guid, contentType, formFileStream, includeTextDetails : recognizeOptions.IncludeTextContent, cancellationToken).ConfigureAwait(false); return(new RecognizeCustomFormsOperation(ServiceClient, Diagnostics, response.Headers.OperationLocation)); }
public virtual RecognizeReceiptsOperation StartRecognizeReceiptsFromUri(Uri receiptFileUri, RecognizeOptions recognizeOptions = default, CancellationToken cancellationToken = default) { Argument.AssertNotNull(receiptFileUri, nameof(receiptFileUri)); recognizeOptions ??= new RecognizeOptions(); SourcePath_internal sourcePath = new SourcePath_internal(receiptFileUri.ToString()); ResponseWithHeaders <ServiceAnalyzeReceiptAsyncHeaders> response = ServiceClient.RestClient.AnalyzeReceiptAsync(includeTextDetails: recognizeOptions.IncludeTextContent, sourcePath, cancellationToken); return(new RecognizeReceiptsOperation(ServiceClient, response.Headers.OperationLocation)); }
public virtual async Task <RecognizeReceiptsOperation> StartRecognizeReceiptsFromUriAsync(Uri receiptFileUri, RecognizeOptions recognizeOptions = default, CancellationToken cancellationToken = default) { Argument.AssertNotNull(receiptFileUri, nameof(receiptFileUri)); recognizeOptions ??= new RecognizeOptions(); SourcePath_internal sourcePath = new SourcePath_internal(receiptFileUri.AbsoluteUri); ResponseWithHeaders <ServiceAnalyzeReceiptAsyncHeaders> response = await ServiceClient.AnalyzeReceiptAsyncAsync(includeTextDetails : recognizeOptions.IncludeTextContent, sourcePath, cancellationToken).ConfigureAwait(false); return(new RecognizeReceiptsOperation(ServiceClient, response.Headers.OperationLocation)); }
public virtual async Task <RecognizeContentOperation> StartRecognizeContentFromUriAsync(Uri formFileUri, RecognizeOptions recognizeOptions = default, CancellationToken cancellationToken = default) { Argument.AssertNotNull(formFileUri, nameof(formFileUri)); SourcePath_internal sourcePath = new SourcePath_internal(formFileUri.ToString()); ResponseWithHeaders <ServiceAnalyzeLayoutAsyncHeaders> response = await ServiceClient.RestClient.AnalyzeLayoutAsyncAsync(sourcePath, cancellationToken).ConfigureAwait(false); return(new RecognizeContentOperation(ServiceClient, response.Headers.OperationLocation)); }
public virtual async Task <RecognizeContentOperation> StartRecognizeContentAsync(Stream formFileStream, RecognizeOptions recognizeOptions = default, CancellationToken cancellationToken = default) { Argument.AssertNotNull(formFileStream, nameof(formFileStream)); recognizeOptions ??= new RecognizeOptions(); ContentType contentType = recognizeOptions.ContentType ?? DetectContentType(formFileStream, nameof(formFileStream)); ResponseWithHeaders <ServiceAnalyzeLayoutAsyncHeaders> response = await ServiceClient.RestClient.AnalyzeLayoutAsyncAsync(contentType, formFileStream, cancellationToken).ConfigureAwait(false); return(new RecognizeContentOperation(ServiceClient, response.Headers.OperationLocation)); }