-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Split out analyze methods for supervised and unsupervised models #10562
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
annelo-msft
merged 36 commits into
Azure:master
from
annelo-msft:fr-split-supervised-unsupervised
Mar 20, 2020
Merged
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
cebfd1e
work in progress
annelo-msft fe1ee4f
interim commit
annelo-msft 8f2bef2
update api
annelo-msft fc8e7ea
interim split
annelo-msft 0d75a39
handle multiple receipts
annelo-msft 948520c
api update and bug fix
annelo-msft 0978cbf
api tweaks
annelo-msft b85cce7
update api
annelo-msft 59c3a1e
Merge remote-tracking branch 'upstream/master' into fr-split-supervis…
annelo-msft 09ccbf5
Merge new CodeGen updates.
annelo-msft d66c034
Merge remote-tracking branch 'upstream/master' into fr-split-supervis…
annelo-msft 87bf81d
regen
annelo-msft 9f587c8
api update
annelo-msft 66c81fd
api tweaks
annelo-msft 8e116fa
move to custom namespace
annelo-msft 167e715
client docstrings
annelo-msft a3d105b
README
annelo-msft 1f8e764
README nits
annelo-msft 805b55f
README nits
annelo-msft 432ea3c
README nit
annelo-msft fcdbe1d
README nit
annelo-msft a9f228d
some docstrings
annelo-msft ee7533f
enable docstrings
annelo-msft aca397a
docstrings
annelo-msft 63645db
fix readme
annelo-msft 0cea404
another README fix
annelo-msft 2bc47bf
docstring updates
annelo-msft 875d4d1
UX study updates
annelo-msft 46e08ed
updates from ux study
annelo-msft 1831700
api update
annelo-msft 2fbf2a5
learned form-> page
annelo-msft 70429dd
api updates
annelo-msft dae7f5a
Merge remote-tracking branch 'upstream/master' into fr-split-supervis…
annelo-msft 2998efc
updates for rebase
annelo-msft f099fbf
Merge remote-tracking branch 'upstream/master' into fr-split-supervis…
annelo-msft 6408aa1
pr feedback
annelo-msft File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
sdk/formrecognizer/Azure.AI.FormRecognizer/src/ExtractLabeledFormOperation.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using Azure.Core; | ||
| using Azure.Core.Pipeline; | ||
|
|
||
| namespace Azure.AI.FormRecognizer.Models | ||
| { | ||
| /// <summary> | ||
| /// </summary> | ||
| internal class ExtractLabeledFormOperation : Operation<IReadOnlyList<ExtractedLabeledForm>> | ||
| { | ||
| private Response _response; | ||
| private IReadOnlyList<ExtractedLabeledForm> _value; | ||
| private bool _hasCompleted; | ||
|
|
||
| private readonly string _modelId; | ||
| private readonly ServiceClient _operations; | ||
|
|
||
| public override string Id { get; } | ||
|
|
||
| public override IReadOnlyList<ExtractedLabeledForm> Value => OperationHelpers.GetValue(ref _value); | ||
|
|
||
| public override bool HasCompleted => _hasCompleted; | ||
|
|
||
| public override bool HasValue => _value != null; | ||
|
|
||
| /// <inheritdoc/> | ||
| public override Response GetRawResponse() => _response; | ||
|
|
||
| /// <inheritdoc/> | ||
| public override ValueTask<Response<IReadOnlyList<ExtractedLabeledForm>>> WaitForCompletionAsync(CancellationToken cancellationToken = default) => | ||
| this.DefaultWaitForCompletionAsync(cancellationToken); | ||
|
|
||
| /// <inheritdoc/> | ||
| public override ValueTask<Response<IReadOnlyList<ExtractedLabeledForm>>> WaitForCompletionAsync(TimeSpan pollingInterval, CancellationToken cancellationToken = default) => | ||
| this.DefaultWaitForCompletionAsync(pollingInterval, cancellationToken); | ||
|
|
||
| /// <summary> | ||
| /// </summary> | ||
| /// <param name="operations"></param> | ||
| /// <param name="modelId"></param> | ||
| /// <param name="operationLocation"></param> | ||
| internal ExtractLabeledFormOperation(ServiceClient operations, string modelId, string operationLocation) | ||
| { | ||
| _operations = operations; | ||
| _modelId = modelId; | ||
|
|
||
| // TODO: Add validation here | ||
| // https://github.com/Azure/azure-sdk-for-net/issues/10385 | ||
| Id = operationLocation.Split('/').Last(); | ||
| } | ||
|
|
||
| /// <inheritdoc/> | ||
| public override Response UpdateStatus(CancellationToken cancellationToken = default) => | ||
| UpdateStatusAsync(false, cancellationToken).EnsureCompleted(); | ||
|
|
||
| /// <inheritdoc/> | ||
| public override async ValueTask<Response> UpdateStatusAsync(CancellationToken cancellationToken = default) => | ||
| await UpdateStatusAsync(true, cancellationToken).ConfigureAwait(false); | ||
|
|
||
| private async Task<Response> UpdateStatusAsync(bool async, CancellationToken cancellationToken) | ||
| { | ||
| if (!_hasCompleted) | ||
| { | ||
| Response<AnalyzeOperationResult_internal> update = async | ||
| ? await _operations.GetAnalyzeFormResultAsync(new Guid(_modelId), new Guid(Id), cancellationToken).ConfigureAwait(false) | ||
| : _operations.GetAnalyzeFormResult(new Guid(_modelId), new Guid(Id), cancellationToken); | ||
|
|
||
| // TODO: Handle correctly according to returned status code | ||
| // https://github.com/Azure/azure-sdk-for-net/issues/10386 | ||
| // TODO: Add reasonable null checks. | ||
|
|
||
| if (update.Value.Status == OperationStatus.Succeeded || update.Value.Status == OperationStatus.Failed) | ||
| { | ||
| _hasCompleted = true; | ||
|
|
||
| // TODO: Consider what we'll do when there are multiple DocumentResults | ||
| // https://github.com/Azure/azure-sdk-for-net/issues/10387 | ||
| // Supervised | ||
| _value = ConvertToExtractedLabeledForms(update.Value.AnalyzeResult.DocumentResults, update.Value.AnalyzeResult.PageResults, update.Value.AnalyzeResult.ReadResults); | ||
| } | ||
|
|
||
| _response = update.GetRawResponse(); | ||
| } | ||
|
|
||
| return GetRawResponse(); | ||
| } | ||
|
|
||
| private static IReadOnlyList<ExtractedLabeledForm> ConvertToExtractedLabeledForms(IList<DocumentResult_internal> documentResults, IList<PageResult_internal> pageResults, IList<ReadResult_internal> readResults) | ||
| { | ||
| List<ExtractedLabeledForm> forms = new List<ExtractedLabeledForm>(); | ||
| for (int i = 0; i < documentResults.Count; i++) | ||
| { | ||
| // TODO: How do we know what pages in pageResults map to the pages in documents? | ||
| // Think about this in the morning. | ||
| forms.Add(new ExtractedLabeledForm(documentResults[i], pageResults[i], readResults[i])); | ||
| } | ||
| return forms; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.