Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions sdk/formrecognizer/azure-ai-formrecognizer/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Release History

## 1.0.0-beta.3 (Unreleased)
- Update FormRecognizer API calls to return a `List` instead of `IterableStream`.
- Fix bug in FormRecognizer API's to support multipage document recognition.
- Add `getFormRecognizerClient()` and `getFormRecognizerAsyncClient()` in FormTrainingClient and FormTrainingAsyncClient
- Add `FormTrainingClientBuilder` to build `FormTrainingAsyncClient` and `FormTrainingClient`
Expand Down
14 changes: 7 additions & 7 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 =
Comment thread
samvaity marked this conversation as resolved.
Outdated
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,12 +169,12 @@ 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>> recognizeContentPoller =
formRecognizerClient.beginRecognizeContentFromUrl(analyzeFilePath);

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

layoutPageResults.forEach(formPage -> {
contentPageResults.forEach(formPage -> {
// Table information
System.out.println("----Recognizing content ----");
System.out.printf("Has width: %d and height: %d, measured with unit: %s.%n", formPage.getWidth(),
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 @@ -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.
Expand All @@ -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);
}
Expand All @@ -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),
Expand All @@ -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);
}
Expand All @@ -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),
Expand All @@ -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);
}

Expand All @@ -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}.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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,
Expand All @@ -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);
}
Expand All @@ -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,
Expand All @@ -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);
}
Expand All @@ -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,
Expand All @@ -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);
}
Expand All @@ -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) {

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand All @@ -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);
Expand Down
Loading