Skip to content

Commit

Permalink
update to list
Browse files Browse the repository at this point in the history
  • Loading branch information
samvaity committed May 28, 2020
1 parent 5de58f4 commit 33b146f
Show file tree
Hide file tree
Showing 27 changed files with 391 additions and 379 deletions.
12 changes: 6 additions & 6 deletions sdk/formrecognizer/azure-ai-formrecognizer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@ so they're tailored to your forms. You should only recognize forms of the same f
```java
String analyzeFilePath = "{file_source_url}";
String modelId = "{custom_trained_model_id}";
SyncPoller<OperationResult, IterableStream<RecognizedForm>> recognizeFormPoller =
SyncPoller<OperationResult, List<RecognizedForm>> recognizeFormPoller =
formRecognizerClient.beginRecognizeCustomFormsFromUrl(analyzeFilePath, modelId);

IterableStream<RecognizedForm> recognizedForms = recognizeFormPoller.getFinalResult();
List<RecognizedForm> recognizedForms = recognizeFormPoller.getFinalResult();

recognizedForms.forEach(form -> {
System.out.println("----------- Recognized Form -----------");
Expand All @@ -169,10 +169,10 @@ Recognize text and table structures, along with their bounding box coordinates,
<!-- embedme ./src/samples/java/com/azure/ai/formrecognizer/ReadmeSamples.java#L79-L99 -->
```java
String analyzeFilePath = "{file_source_url}";
SyncPoller<OperationResult, IterableStream<FormPage>> recognizeLayoutPoller =
SyncPoller<OperationResult, List<FormPage>> recognizeLayoutPoller =
formRecognizerClient.beginRecognizeContentFromUrl(analyzeFilePath);

IterableStream<FormPage> layoutPageResults = recognizeLayoutPoller.getFinalResult();
List<FormPage> layoutPageResults = recognizeLayoutPoller.getFinalResult();

layoutPageResults.forEach(formPage -> {
// Table information
Expand All @@ -197,9 +197,9 @@ Recognize data from a USA sales receipts using a prebuilt model.
```java
String receiptSourceUrl = "https://docs.microsoft.com/en-us/azure/cognitive-services/form-recognizer/media"
+ "/contoso-allinone.jpg";
SyncPoller<OperationResult, IterableStream<RecognizedReceipt>> syncPoller =
SyncPoller<OperationResult, List<RecognizedReceipt>> syncPoller =
formRecognizerClient.beginRecognizeReceiptsFromUrl(receiptSourceUrl);
IterableStream<RecognizedReceipt> receiptPageResults = syncPoller.getFinalResult();
List<RecognizedReceipt> receiptPageResults = syncPoller.getFinalResult();

receiptPageResults.forEach(recognizedReceipt -> {
USReceipt usReceipt = ReceiptExtensions.asUSReceipt(recognizedReceipt);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -99,7 +98,7 @@ public FormRecognizerServiceVersion getServiceVersion() {
* or has been cancelled.
*/
@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);
}
Expand All @@ -123,11 +122,11 @@ public FormRecognizerServiceVersion getServiceVersion() {
* or has been cancelled.
*/
@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),
Expand Down Expand Up @@ -156,7 +155,7 @@ public FormRecognizerServiceVersion getServiceVersion() {
* been cancelled.
*/
@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);
}
Expand Down Expand Up @@ -185,11 +184,11 @@ public FormRecognizerServiceVersion getServiceVersion() {
* been cancelled.
*/
@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),
Expand All @@ -212,7 +211,7 @@ public FormRecognizerServiceVersion getServiceVersion() {
* or has been cancelled.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public PollerFlux<OperationResult, IterableStream<FormPage>> beginRecognizeContentFromUrl(String fileSourceUrl) {
public PollerFlux<OperationResult, List<FormPage>> beginRecognizeContentFromUrl(String fileSourceUrl) {
return beginRecognizeContentFromUrl(fileSourceUrl, null);
}

Expand All @@ -233,10 +232,10 @@ public PollerFlux<OperationResult, IterableStream<FormPage>> beginRecognizeConte
* been cancelled.
*/
@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,
Expand Down Expand Up @@ -264,7 +263,7 @@ public PollerFlux<OperationResult, IterableStream<FormPage>> beginRecognizeConte
* been cancelled.
*/
@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);
}
Expand All @@ -291,7 +290,7 @@ public PollerFlux<OperationResult, IterableStream<FormPage>> beginRecognizeConte
* been cancelled.
*/
@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,
Expand All @@ -317,7 +316,7 @@ public PollerFlux<OperationResult, IterableStream<FormPage>> beginRecognizeConte
* been cancelled.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public PollerFlux<OperationResult, IterableStream<RecognizedReceipt>>
public PollerFlux<OperationResult, List<RecognizedReceipt>>
beginRecognizeReceiptsFromUrl(String sourceUrl) {
return beginRecognizeReceiptsFromUrl(sourceUrl, false, null);
}
Expand All @@ -340,10 +339,10 @@ public PollerFlux<OperationResult, IterableStream<FormPage>> beginRecognizeConte
* been cancelled.
*/
@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,
Expand Down Expand Up @@ -371,7 +370,7 @@ public PollerFlux<OperationResult, IterableStream<FormPage>> beginRecognizeConte
* been cancelled.
*/
@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);
}
Expand Down Expand Up @@ -399,7 +398,7 @@ public PollerFlux<OperationResult, IterableStream<RecognizedReceipt>> beginRecog
* been cancelled.
*/
@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) {

Expand Down Expand Up @@ -466,16 +465,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);
Expand Down Expand Up @@ -536,24 +534,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 {
Expand All @@ -563,8 +560,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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceClient;
import com.azure.core.annotation.ServiceMethod;
import com.azure.core.util.IterableStream;
import com.azure.core.util.polling.SyncPoller;
import reactor.core.publisher.Flux;

import java.io.InputStream;
import java.nio.ByteBuffer;
import java.time.Duration;
import java.util.List;

/**
* This class provides a synchronous client that contains all the operations that apply to Azure Form Recognizer.
Expand Down Expand Up @@ -60,7 +60,7 @@ public final class FormRecognizerClient {
* has failed, or has been cancelled.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public SyncPoller<OperationResult, IterableStream<RecognizedForm>>
public SyncPoller<OperationResult, List<RecognizedForm>>
beginRecognizeCustomFormsFromUrl(String fileSourceUrl, String modelId) {
return beginRecognizeCustomFormsFromUrl(fileSourceUrl, modelId, false, null);
}
Expand All @@ -84,7 +84,7 @@ public final class FormRecognizerClient {
* has failed, or has been cancelled.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public SyncPoller<OperationResult, IterableStream<RecognizedForm>>
public SyncPoller<OperationResult, List<RecognizedForm>>
beginRecognizeCustomFormsFromUrl(String fileSourceUrl, String modelId, boolean includeTextDetails,
Duration pollInterval) {
return client.beginRecognizeCustomFormsFromUrl(fileSourceUrl, modelId, includeTextDetails, pollInterval)
Expand All @@ -109,7 +109,7 @@ public final class FormRecognizerClient {
* has failed, or has been cancelled.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public SyncPoller<OperationResult, IterableStream<RecognizedForm>>
public SyncPoller<OperationResult, List<RecognizedForm>>
beginRecognizeCustomForms(InputStream data, String modelId, long length, FormContentType formContentType) {
return beginRecognizeCustomForms(data, modelId, length, formContentType, false, null);
}
Expand All @@ -135,7 +135,7 @@ public final class FormRecognizerClient {
* has failed, or has been cancelled.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public SyncPoller<OperationResult, IterableStream<RecognizedForm>>
public SyncPoller<OperationResult, List<RecognizedForm>>
beginRecognizeCustomForms(InputStream data, String modelId, long length, FormContentType formContentType,
boolean includeTextDetails, Duration pollInterval) {
Flux<ByteBuffer> buffer = Utility.toFluxByteBuffer(data);
Expand All @@ -158,7 +158,7 @@ public final class FormRecognizerClient {
* or has been cancelled.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public SyncPoller<OperationResult, IterableStream<FormPage>> beginRecognizeContentFromUrl(String fileSourceUrl) {
public SyncPoller<OperationResult, List<FormPage>> beginRecognizeContentFromUrl(String fileSourceUrl) {
return beginRecognizeContentFromUrl(fileSourceUrl, null);
}

Expand All @@ -178,7 +178,7 @@ public SyncPoller<OperationResult, IterableStream<FormPage>> beginRecognizeConte
* failed, or has been cancelled.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public SyncPoller<OperationResult, IterableStream<FormPage>>
public SyncPoller<OperationResult, List<FormPage>>
beginRecognizeContentFromUrl(String sourceUrl, Duration pollInterval) {
return client.beginRecognizeContentFromUrl(sourceUrl, pollInterval).getSyncPoller();
}
Expand All @@ -199,7 +199,7 @@ public SyncPoller<OperationResult, IterableStream<FormPage>> beginRecognizeConte
* been cancelled.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public SyncPoller<OperationResult, IterableStream<FormPage>>
public SyncPoller<OperationResult, List<FormPage>>
beginRecognizeContent(InputStream data, long length, FormContentType formContentType) {
return beginRecognizeContent(data, length, formContentType, null);
}
Expand All @@ -223,7 +223,7 @@ public SyncPoller<OperationResult, IterableStream<FormPage>> beginRecognizeConte
* has failed, or has been cancelled.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public SyncPoller<OperationResult, IterableStream<FormPage>>
public SyncPoller<OperationResult, List<FormPage>>
beginRecognizeContent(InputStream data, long length, FormContentType formContentType, Duration pollInterval) {
// TODO: #9248 should be able to infer form content type
Flux<ByteBuffer> buffer = Utility.toFluxByteBuffer(data);
Expand All @@ -246,7 +246,7 @@ public SyncPoller<OperationResult, IterableStream<FormPage>> beginRecognizeConte
* has failed, or has been cancelled.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public SyncPoller<OperationResult, IterableStream<RecognizedReceipt>>
public SyncPoller<OperationResult, List<RecognizedReceipt>>
beginRecognizeReceiptsFromUrl(String sourceUrl) {
return beginRecognizeReceiptsFromUrl(sourceUrl, false, null);
}
Expand All @@ -269,7 +269,7 @@ public SyncPoller<OperationResult, IterableStream<FormPage>> beginRecognizeConte
* has failed, or has been cancelled.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public SyncPoller<OperationResult, IterableStream<RecognizedReceipt>>
public SyncPoller<OperationResult, List<RecognizedReceipt>>
beginRecognizeReceiptsFromUrl(String sourceUrl, boolean includeTextDetails, Duration pollInterval) {
return client.beginRecognizeReceiptsFromUrl(sourceUrl, includeTextDetails, pollInterval).getSyncPoller();
}
Expand All @@ -291,7 +291,7 @@ public SyncPoller<OperationResult, IterableStream<FormPage>> beginRecognizeConte
* has failed, or has been cancelled.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public SyncPoller<OperationResult, IterableStream<RecognizedReceipt>>
public SyncPoller<OperationResult, List<RecognizedReceipt>>
beginRecognizeReceipts(InputStream data, long length, FormContentType formContentType) {
return beginRecognizeReceipts(data, length, formContentType, false, null);
}
Expand All @@ -316,7 +316,7 @@ public SyncPoller<OperationResult, IterableStream<FormPage>> beginRecognizeConte
* has completed, has failed, or has been cancelled.
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public SyncPoller<OperationResult, IterableStream<RecognizedReceipt>>
public SyncPoller<OperationResult, List<RecognizedReceipt>>
beginRecognizeReceipts(InputStream data, long length, FormContentType formContentType,
boolean includeTextDetails, Duration pollInterval) {
Flux<ByteBuffer> buffer = Utility.toFluxByteBuffer(data);
Expand Down
Loading

0 comments on commit 33b146f

Please sign in to comment.