Skip to content
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

[FR] ConvertPrebuiltOutputToRecognizedForms moved to ClientCommon #17185

Merged
merged 1 commit into from
Nov 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions sdk/formrecognizer/Azure.AI.FormRecognizer/src/ClientCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,15 @@ public static async ValueTask<RequestFailedException> CreateExceptionForFailedOp
? await diagnostics.CreateRequestFailedExceptionAsync(response, errorMessage, errorCode, errorInfo).ConfigureAwait(false)
: diagnostics.CreateRequestFailedException(response, errorMessage, errorCode, errorInfo);
}

public static RecognizedFormCollection ConvertPrebuiltOutputToRecognizedForms(AnalyzeResult analyzeResult)
{
List<RecognizedForm> forms = new List<RecognizedForm>();
for (int i = 0; i < analyzeResult.DocumentResults.Count; i++)
{
forms.Add(new RecognizedForm(analyzeResult.DocumentResults[i], analyzeResult.PageResults, analyzeResult.ReadResults, default));
}
return new RecognizedFormCollection(forms);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ private async ValueTask<Response> UpdateStatusAsync(bool async, CancellationToke
if (update.Value.Status == OperationStatus.Succeeded)
{
// We need to first assign a value and then mark the operation as completed to avoid a race condition with the getter in Value
_value = ConvertToRecognizedForms(update.Value.AnalyzeResult);
_value = ClientCommon.ConvertPrebuiltOutputToRecognizedForms(update.Value.AnalyzeResult);
_hasCompleted = true;
}
else if (update.Value.Status == OperationStatus.Failed)
Expand All @@ -202,15 +202,5 @@ private async ValueTask<Response> UpdateStatusAsync(bool async, CancellationToke

return GetRawResponse();
}

private static RecognizedFormCollection ConvertToRecognizedForms(AnalyzeResult analyzeResult)
{
List<RecognizedForm> businessCards = new List<RecognizedForm>();
for (int i = 0; i < analyzeResult.DocumentResults.Count; i++)
{
businessCards.Add(new RecognizedForm(analyzeResult.DocumentResults[i], analyzeResult.PageResults, analyzeResult.ReadResults, default));
}
return new RecognizedFormCollection(businessCards);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ private async ValueTask<Response> UpdateStatusAsync(bool async, CancellationToke
if (update.Value.Status == OperationStatus.Succeeded)
{
// We need to first assign a value and then mark the operation as completed to avoid a race condition with the getter in Value
_value = ConvertToRecognizedForms(update.Value.AnalyzeResult);
_value = ClientCommon.ConvertPrebuiltOutputToRecognizedForms(update.Value.AnalyzeResult);
_hasCompleted = true;
}
else if (update.Value.Status == OperationStatus.Failed)
Expand All @@ -202,15 +202,5 @@ private async ValueTask<Response> UpdateStatusAsync(bool async, CancellationToke

return GetRawResponse();
}

private static RecognizedFormCollection ConvertToRecognizedForms(AnalyzeResult analyzeResult)
{
List<RecognizedForm> invoices = new List<RecognizedForm>();
for (int i = 0; i < analyzeResult.DocumentResults.Count; i++)
{
invoices.Add(new RecognizedForm(analyzeResult.DocumentResults[i], analyzeResult.PageResults, analyzeResult.ReadResults, default));
}
return new RecognizedFormCollection(invoices);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ private async ValueTask<Response> UpdateStatusAsync(bool async, CancellationToke
if (update.Value.Status == OperationStatus.Succeeded)
{
// We need to first assign a value and then mark the operation as completed to avoid a race condition with the getter in Value
_value = ConvertToRecognizedForms(update.Value.AnalyzeResult);
_value = ClientCommon.ConvertPrebuiltOutputToRecognizedForms(update.Value.AnalyzeResult);
_hasCompleted = true;
}
else if (update.Value.Status == OperationStatus.Failed)
Expand All @@ -202,15 +202,5 @@ private async ValueTask<Response> UpdateStatusAsync(bool async, CancellationToke

return GetRawResponse();
}

private static RecognizedFormCollection ConvertToRecognizedForms(AnalyzeResult analyzeResult)
{
List<RecognizedForm> receipts = new List<RecognizedForm>();
for (int i = 0; i < analyzeResult.DocumentResults.Count; i++)
{
receipts.Add(new RecognizedForm(analyzeResult.DocumentResults[i], analyzeResult.PageResults, analyzeResult.ReadResults, default));
}
return new RecognizedFormCollection(receipts);
}
}
}