-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Form recognizer API's to return List over IterableStream #11310
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
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
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 |
|---|---|---|
|
|
@@ -22,7 +22,6 @@ | |
| import com.azure.core.http.HttpPipeline; | ||
| import com.azure.core.http.rest.SimpleResponse; | ||
| import com.azure.core.util.CoreUtils; | ||
| import com.azure.core.util.IterableStream; | ||
| import com.azure.core.util.logging.ClientLogger; | ||
| import com.azure.core.util.polling.LongRunningOperationStatus; | ||
| import com.azure.core.util.polling.PollResponse; | ||
|
|
@@ -74,15 +73,6 @@ public final class FormRecognizerAsyncClient { | |
| this.serviceVersion = serviceVersion; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the service version the client is using. | ||
| * | ||
| * @return the service version the client is using. | ||
| */ | ||
| public FormRecognizerServiceVersion getServiceVersion() { | ||
| return serviceVersion; | ||
| } | ||
|
|
||
| /** | ||
| * Recognizes and extracts form data from documents using optical character recognition (OCR) and a custom trained | ||
| * model. | ||
|
|
@@ -96,10 +86,10 @@ public FormRecognizerServiceVersion getServiceVersion() { | |
| * @param modelId The UUID string format custom trained model Id to be used. | ||
| * | ||
| * @return A {@link PollerFlux} that polls the extract custom form operation until it has completed, has failed, | ||
| * or has been cancelled. | ||
| * or has been cancelled. The completed operation returns a List of {@link RecognizedForm}. | ||
| */ | ||
| @ServiceMethod(returns = ReturnType.COLLECTION) | ||
| public PollerFlux<OperationResult, IterableStream<RecognizedForm>> | ||
| public PollerFlux<OperationResult, List<RecognizedForm>> | ||
| beginRecognizeCustomFormsFromUrl(String fileSourceUrl, String modelId) { | ||
| return beginRecognizeCustomFormsFromUrl(fileSourceUrl, modelId, false, null); | ||
| } | ||
|
|
@@ -120,14 +110,14 @@ public FormRecognizerServiceVersion getServiceVersion() { | |
| * 5 seconds is used. | ||
| * | ||
| * @return A {@link PollerFlux} that polls the extract custom form operation until it has completed, has failed, | ||
| * or has been cancelled. | ||
| * or has been cancelled. The completed operation returns a List of {@code RecognizedForm}. | ||
| */ | ||
| @ServiceMethod(returns = ReturnType.COLLECTION) | ||
| public PollerFlux<OperationResult, IterableStream<RecognizedForm>> | ||
| public PollerFlux<OperationResult, List<RecognizedForm>> | ||
| beginRecognizeCustomFormsFromUrl(String fileSourceUrl, String modelId, boolean includeTextDetails, | ||
| Duration pollInterval) { | ||
| final Duration interval = pollInterval != null ? pollInterval : DEFAULT_DURATION; | ||
| return new PollerFlux<OperationResult, IterableStream<RecognizedForm>>( | ||
| return new PollerFlux<OperationResult, List<RecognizedForm>>( | ||
| interval, | ||
| analyzeFormActivationOperation(fileSourceUrl, modelId, includeTextDetails), | ||
| createAnalyzeFormPollOperation(modelId), | ||
|
|
@@ -153,10 +143,10 @@ public FormRecognizerServiceVersion getServiceVersion() { | |
| * @param formContentType Supported Media types including .pdf, .jpg, .png or .tiff type file stream. | ||
| * | ||
| * @return A {@link PollerFlux} that polls the extract receipt operation until it has completed, has failed, or has | ||
| * been cancelled. | ||
| * been cancelled. The completed operation returns a List of {@code RecognizedForm}. | ||
| */ | ||
| @ServiceMethod(returns = ReturnType.COLLECTION) | ||
| public PollerFlux<OperationResult, IterableStream<RecognizedForm>> | ||
| public PollerFlux<OperationResult, List<RecognizedForm>> | ||
| beginRecognizeCustomForms(Flux<ByteBuffer> data, String modelId, long length, FormContentType formContentType) { | ||
| return beginRecognizeCustomForms(data, modelId, length, formContentType, false, null); | ||
| } | ||
|
|
@@ -182,14 +172,14 @@ public FormRecognizerServiceVersion getServiceVersion() { | |
| * 5 seconds is used. | ||
| * | ||
| * @return A {@link PollerFlux} that polls the extract receipt operation until it has completed, has failed, or has | ||
| * been cancelled. | ||
| * been cancelled. The completed operation returns a List of {@code RecognizedForm}. | ||
| */ | ||
| @ServiceMethod(returns = ReturnType.COLLECTION) | ||
| public PollerFlux<OperationResult, IterableStream<RecognizedForm>> | ||
| public PollerFlux<OperationResult, List<RecognizedForm>> | ||
| beginRecognizeCustomForms(Flux<ByteBuffer> data, String modelId, long length, FormContentType formContentType, | ||
| boolean includeTextDetails, Duration pollInterval) { | ||
| final Duration interval = pollInterval != null ? pollInterval : DEFAULT_DURATION; | ||
| return new PollerFlux<OperationResult, IterableStream<RecognizedForm>>( | ||
| return new PollerFlux<OperationResult, List<RecognizedForm>>( | ||
| interval, | ||
| analyzeFormStreamActivationOperation(data, modelId, length, formContentType, includeTextDetails), | ||
| createAnalyzeFormPollOperation(modelId), | ||
|
|
@@ -209,10 +199,10 @@ public FormRecognizerServiceVersion getServiceVersion() { | |
| * @param fileSourceUrl The source URL to the input document. Size of the file must be less than 50 MB. | ||
| * | ||
| * @return A {@link PollerFlux} that polls the extract custom form operation until it has completed, has failed, | ||
| * or has been cancelled. | ||
| * or has been cancelled. The completed operation returns a List of {@link FormPage}. | ||
| */ | ||
| @ServiceMethod(returns = ReturnType.COLLECTION) | ||
| public PollerFlux<OperationResult, IterableStream<FormPage>> beginRecognizeContentFromUrl(String fileSourceUrl) { | ||
| public PollerFlux<OperationResult, List<FormPage>> beginRecognizeContentFromUrl(String fileSourceUrl) { | ||
| return beginRecognizeContentFromUrl(fileSourceUrl, null); | ||
| } | ||
|
|
||
|
|
@@ -230,13 +220,13 @@ public PollerFlux<OperationResult, IterableStream<FormPage>> beginRecognizeConte | |
| * 5 seconds is used. | ||
| * | ||
| * @return A {@link PollerFlux} that polls the extract receipt operation until it has completed, has failed, or has | ||
| * been cancelled. | ||
| * been cancelled. The completed operation returns a List of {@code FormPage}. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use @link since FormPage is the first occurance in this javadoc section |
||
| */ | ||
| @ServiceMethod(returns = ReturnType.COLLECTION) | ||
| public PollerFlux<OperationResult, IterableStream<FormPage>> | ||
| public PollerFlux<OperationResult, List<FormPage>> | ||
| beginRecognizeContentFromUrl(String sourceUrl, Duration pollInterval) { | ||
| final Duration interval = pollInterval != null ? pollInterval : DEFAULT_DURATION; | ||
| return new PollerFlux<OperationResult, IterableStream<FormPage>>(interval, | ||
| return new PollerFlux<OperationResult, List<FormPage>>(interval, | ||
| contentAnalyzeActivationOperation(sourceUrl), | ||
| extractContentPollOperation(), | ||
| (activationResponse, context) -> monoError(logger, | ||
|
|
@@ -261,10 +251,10 @@ public PollerFlux<OperationResult, IterableStream<FormPage>> beginRecognizeConte | |
| * @param formContentType Supported Media types including .pdf, .jpg, .png or .tiff type file stream. | ||
| * | ||
| * @return A {@link PollerFlux} that polls the extract receipt operation until it has completed, has failed, or has | ||
| * been cancelled. | ||
| * been cancelled. The completed operation returns a List of {@code FormPage}. | ||
| */ | ||
| @ServiceMethod(returns = ReturnType.COLLECTION) | ||
| public PollerFlux<OperationResult, IterableStream<FormPage>> beginRecognizeContent( | ||
| public PollerFlux<OperationResult, List<FormPage>> beginRecognizeContent( | ||
| Flux<ByteBuffer> data, long length, FormContentType formContentType) { | ||
| return beginRecognizeContent(data, length, formContentType, null); | ||
| } | ||
|
|
@@ -288,10 +278,10 @@ public PollerFlux<OperationResult, IterableStream<FormPage>> beginRecognizeConte | |
| * 5 seconds is used. | ||
| * | ||
| * @return A {@link PollerFlux} that polls the extract receipt operation until it has completed, has failed, or has | ||
| * been cancelled. | ||
| * been cancelled. The completed operation returns a List of {@code FormPage}. | ||
| */ | ||
| @ServiceMethod(returns = ReturnType.COLLECTION) | ||
| public PollerFlux<OperationResult, IterableStream<FormPage>> beginRecognizeContent( | ||
| public PollerFlux<OperationResult, List<FormPage>> beginRecognizeContent( | ||
| Flux<ByteBuffer> data, long length, FormContentType formContentType, Duration pollInterval) { | ||
| return new PollerFlux<>( | ||
| pollInterval != null ? pollInterval : DEFAULT_DURATION, | ||
|
|
@@ -314,10 +304,10 @@ public PollerFlux<OperationResult, IterableStream<FormPage>> beginRecognizeConte | |
| * @param sourceUrl The source URL to the input document. Size of the file must be less than 50 MB. | ||
| * | ||
| * @return A {@link PollerFlux} that polls the extract receipt operation until it has completed, has failed, or has | ||
| * been cancelled. | ||
| * been cancelled. The completed operation returns a List of {@link RecognizedReceipt}. | ||
| */ | ||
| @ServiceMethod(returns = ReturnType.COLLECTION) | ||
| public PollerFlux<OperationResult, IterableStream<RecognizedReceipt>> | ||
| public PollerFlux<OperationResult, List<RecognizedReceipt>> | ||
| beginRecognizeReceiptsFromUrl(String sourceUrl) { | ||
| return beginRecognizeReceiptsFromUrl(sourceUrl, false, null); | ||
| } | ||
|
|
@@ -337,13 +327,13 @@ public PollerFlux<OperationResult, IterableStream<FormPage>> beginRecognizeConte | |
| * 5 seconds is used. | ||
| * | ||
| * @return A {@link PollerFlux} that polls the extract receipt operation until it has completed, has failed, or has | ||
| * been cancelled. | ||
| * been cancelled. The completed operation returns a List of {@code RecognizedReceipt}. | ||
| */ | ||
| @ServiceMethod(returns = ReturnType.COLLECTION) | ||
| public PollerFlux<OperationResult, IterableStream<RecognizedReceipt>> | ||
| public PollerFlux<OperationResult, List<RecognizedReceipt>> | ||
| beginRecognizeReceiptsFromUrl(String sourceUrl, boolean includeTextDetails, Duration pollInterval) { | ||
| final Duration interval = pollInterval != null ? pollInterval : DEFAULT_DURATION; | ||
| return new PollerFlux<OperationResult, IterableStream<RecognizedReceipt>>(interval, | ||
| return new PollerFlux<OperationResult, List<RecognizedReceipt>>(interval, | ||
| receiptAnalyzeActivationOperation(sourceUrl, includeTextDetails), | ||
| extractReceiptPollOperation(), | ||
| (activationResponse, context) -> monoError(logger, | ||
|
|
@@ -368,10 +358,10 @@ public PollerFlux<OperationResult, IterableStream<FormPage>> beginRecognizeConte | |
| * @param formContentType Supported Media types including .pdf, .jpg, .png or .tiff type file stream. | ||
| * | ||
| * @return A {@link PollerFlux} that polls the extract receipt operation until it has completed, has failed, or has | ||
| * been cancelled. | ||
| * been cancelled. The completed operation returns a List of {@code RecognizedReceipt}. | ||
| */ | ||
| @ServiceMethod(returns = ReturnType.COLLECTION) | ||
| public PollerFlux<OperationResult, IterableStream<RecognizedReceipt>> beginRecognizeReceipts( | ||
| public PollerFlux<OperationResult, List<RecognizedReceipt>> beginRecognizeReceipts( | ||
| Flux<ByteBuffer> data, long length, FormContentType formContentType) { | ||
| return beginRecognizeReceipts(data, length, formContentType, false, null); | ||
| } | ||
|
|
@@ -396,10 +386,10 @@ public PollerFlux<OperationResult, IterableStream<RecognizedReceipt>> beginRecog | |
| * 5 seconds is used. | ||
| * | ||
| * @return A {@link PollerFlux} that polls the extract receipt operation until it has completed, has failed, or has | ||
| * been cancelled. | ||
| * been cancelled. The completed operation returns a List of {@code RecognizedReceipt}. | ||
| */ | ||
| @ServiceMethod(returns = ReturnType.COLLECTION) | ||
| public PollerFlux<OperationResult, IterableStream<RecognizedReceipt>> beginRecognizeReceipts( | ||
| public PollerFlux<OperationResult, List<RecognizedReceipt>> beginRecognizeReceipts( | ||
| Flux<ByteBuffer> data, long length, FormContentType formContentType, boolean includeTextDetails, | ||
| Duration pollInterval) { | ||
|
|
||
|
|
@@ -466,16 +456,15 @@ private Function<PollingContext<OperationResult>, Mono<OperationResult>> receipt | |
| }; | ||
| } | ||
|
|
||
| private Function<PollingContext<OperationResult>, Mono<IterableStream<RecognizedReceipt>>> | ||
| private Function<PollingContext<OperationResult>, Mono<List<RecognizedReceipt>>> | ||
| fetchExtractReceiptResult(boolean includeTextDetails) { | ||
| return (pollingContext) -> { | ||
| try { | ||
| final UUID resultUid = UUID.fromString(pollingContext.getLatestResponse().getValue().getResultId()); | ||
| return service.getAnalyzeReceiptResultWithResponseAsync(resultUid) | ||
| .map(modelSimpleResponse -> { | ||
| throwIfAnalyzeStatusInvalid(modelSimpleResponse); | ||
| return toReceipt(modelSimpleResponse.getValue().getAnalyzeResult(), | ||
| includeTextDetails); | ||
| return toReceipt(modelSimpleResponse.getValue().getAnalyzeResult(), includeTextDetails); | ||
| }); | ||
| } catch (RuntimeException ex) { | ||
| return monoError(logger, ex); | ||
|
|
@@ -536,24 +525,23 @@ private Function<PollingContext<OperationResult>, Mono<OperationResult>> content | |
| }; | ||
| } | ||
|
|
||
| private Function<PollingContext<OperationResult>, Mono<IterableStream<FormPage>>> | ||
| private Function<PollingContext<OperationResult>, Mono<List<FormPage>>> | ||
| fetchExtractContentResult() { | ||
| return (pollingContext) -> { | ||
| try { | ||
| final UUID resultUid = UUID.fromString(pollingContext.getLatestResponse().getValue().getResultId()); | ||
| return service.getAnalyzeLayoutResultWithResponseAsync(resultUid) | ||
| .map(modelSimpleResponse -> { | ||
| throwIfAnalyzeStatusInvalid(modelSimpleResponse); | ||
| return new IterableStream<>( | ||
| toRecognizedLayout(modelSimpleResponse.getValue().getAnalyzeResult(), true)); | ||
| return toRecognizedLayout(modelSimpleResponse.getValue().getAnalyzeResult(), true); | ||
| }); | ||
| } catch (RuntimeException ex) { | ||
| return monoError(logger, ex); | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| private Function<PollingContext<OperationResult>, Mono<IterableStream<RecognizedForm>>> | ||
| private Function<PollingContext<OperationResult>, Mono<List<RecognizedForm>>> | ||
| fetchAnalyzeFormResultOperation(String modelId, boolean includeTextDetails) { | ||
| return (pollingContext) -> { | ||
| try { | ||
|
|
@@ -563,8 +551,7 @@ private Function<PollingContext<OperationResult>, Mono<OperationResult>> content | |
| return service.getAnalyzeFormResultWithResponseAsync(modelUid, resultUid) | ||
| .map(modelSimpleResponse -> { | ||
| throwIfAnalyzeStatusInvalid(modelSimpleResponse); | ||
| return new IterableStream<>(toRecognizedForm(modelSimpleResponse.getValue().getAnalyzeResult(), | ||
| includeTextDetails)); | ||
| return toRecognizedForm(modelSimpleResponse.getValue().getAnalyzeResult(), includeTextDetails); | ||
| }); | ||
| } catch (RuntimeException ex) { | ||
| return monoError(logger, ex); | ||
|
|
||
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.