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

Update recorded data usage in FormRecognizer tests infrastructure #22799

Merged
merged 5 commits into from
Jul 8, 2021
Merged
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
16 changes: 8 additions & 8 deletions sdk/formrecognizer/azure-ai-formrecognizer/README.md
Original file line number Diff line number Diff line change
@@ -53,25 +53,25 @@ Below is an example of how you can create a Form Recognizer resource using the C
```bash
# Create a new resource group to hold the Form Recognizer resource -
# if using an existing resource group, skip this step
az group create --name my-resource-group --location westus2
az group create --name <your-resource-group> --location <location>
```

```bash
# Create Form Recognizer
az cognitiveservices account create \
--name form-recognizer-resource \
--resource-group my-resource-group \
--name <your-form-recognizer-resource-name> \
--resource-group <your-resource-group> \
--kind FormRecognizer \
--sku S0 \
--location westus2 \
--sku <sku> \
--location <location> \
--yes
```
### Authenticate the client
In order to interact with the Form Recognizer service, you will need to create an instance of the Form Recognizer client.
Both the asynchronous and synchronous clients can be created by using `FormRecognizerClientBuilder`. Invoking `buildClient()`
will create the synchronous client, while invoking `buildAsyncClient` will create its asynchronous counterpart.

You will need an **endpoint** and a **key** to instantiate a client object.
You will need an **endpoint**, and a **key** to instantiate a client object.

##### Looking up the endpoint
You can find the **endpoint** for your Form Recognizer resource in the [Azure Portal][azure_portal],
@@ -137,7 +137,7 @@ Authentication with AAD requires some initial setup:
* [Register a new Azure Active Directory application][register_AAD_application]
* [Grant access][grant_access] to Form Recognizer by assigning the `"Cognitive Services User"` role to your service principal.

After setup, you can choose which type of [credential][azure_identity_credential_type] from azure.identity to use.
After the setup, you can choose which type of [credential][azure_identity_credential_type] from azure.identity to use.
As an example, [DefaultAzureCredential][wiki_identity] can be used to authenticate the client:
Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables:
AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.
@@ -210,7 +210,7 @@ The following section provides several code snippets covering some of the most c
* [Manage Your Models](#manage-your-models "Manage Your Models")

### Recognize Forms Using a Custom Model
Recognize name/value pairs and table data from forms. These models are trained with your own data,
Recognize the name/value pairs and table data from forms. These models are trained with your own data,
so they're tailored to your forms. You should only recognize forms of the same form type that the custom model was trained on.
<!-- embedme ./src/samples/java/com/azure/ai/formrecognizer/ReadmeSamples.java#L93-L110 -->
```java
Original file line number Diff line number Diff line change
@@ -238,7 +238,7 @@ public final class FormRecognizerAsyncClient {

final RecognizeCustomFormsOptions finalRecognizeCustomFormsOptions
= getRecognizeCustomFormOptions(recognizeCustomFormsOptions);
final boolean isFieldElementsIncluded = recognizeCustomFormsOptions.isFieldElementsIncluded();
final boolean isFieldElementsIncluded = finalRecognizeCustomFormsOptions.isFieldElementsIncluded();
return new PollerFlux<>(
finalRecognizeCustomFormsOptions.getPollInterval(),
streamActivationOperation(
@@ -335,7 +335,7 @@ public PollerFlux<FormRecognizerOperationResult, List<FormPage>> beginRecognizeC
? null : Language.fromString(finalRecognizeContentOptions.getLanguage().toString()),
finalRecognizeContentOptions.getReadingOrder() != null
? com.azure.ai.formrecognizer.implementation.models.ReadingOrder.fromString(
recognizeContentOptions.getReadingOrder().toString())
finalRecognizeContentOptions.getReadingOrder().toString())
: null,
new SourcePath().setSource(formUrl),
context)
@@ -426,7 +426,7 @@ PollerFlux<FormRecognizerOperationResult, List<FormPage>> beginRecognizeContent(
? null : Language.fromString(finalRecognizeContentOptions.getLanguage().toString()),
finalRecognizeContentOptions.getReadingOrder() != null
? com.azure.ai.formrecognizer.implementation.models.ReadingOrder.fromString(
recognizeContentOptions.getReadingOrder().toString())
finalRecognizeContentOptions.getReadingOrder().toString())
: null,
form,
length,
Original file line number Diff line number Diff line change
@@ -288,6 +288,8 @@ private static TextAppearance getTextAppearance(TextLine textLine) {
}
TextAppearanceHelper.setStyleConfidence(textAppearance,
textLine.getAppearance().getStyle().getConfidence());
} else {
return null;
}
return textAppearance;
}
@@ -358,18 +360,12 @@ private static FormField setFormField(String name, FieldData valueData, FieldVal
DateTimeFormatter.ofPattern("HH:mm:ss"));
value = new com.azure.ai.formrecognizer.models.FieldValue(fieldTime, FieldValueType.TIME);
} else {
throw LOGGER.logExceptionAsError(new RuntimeException(String.format(NORMALIZATION_ERROR_MESSAGE,
fieldValue.getType())));
value = new com.azure.ai.formrecognizer.models.FieldValue(null, FieldValueType.TIME);
}
break;
case DATE:
if (fieldValue.getValueDate() != null) {
value = new com.azure.ai.formrecognizer.models.FieldValue(fieldValue.getValueDate(),
FieldValueType.DATE);
} else {
throw LOGGER.logExceptionAsError(new RuntimeException(String.format(NORMALIZATION_ERROR_MESSAGE,
fieldValue.getType())));
}
value = new com.azure.ai.formrecognizer.models.FieldValue(fieldValue.getValueDate(),
FieldValueType.DATE);
break;
case INTEGER:
if (fieldValue.getValueInteger() != null) {
@@ -384,12 +380,21 @@ private static FormField setFormField(String name, FieldData valueData, FieldVal
FieldValueType.FLOAT);
break;
case ARRAY:
value = new com.azure.ai.formrecognizer.models.FieldValue(
toFieldValueArray(fieldValue.getValueArray(), readResults), FieldValueType.LIST);
if (fieldValue.getValueArray() != null) {
value = new com.azure.ai.formrecognizer.models.FieldValue(
toFieldValueArray(fieldValue.getValueArray(), readResults), FieldValueType.LIST);
} else {
value = new com.azure.ai.formrecognizer.models.FieldValue(null, FieldValueType.LIST);
}
break;
case OBJECT:
value = new com.azure.ai.formrecognizer.models.FieldValue(
if (fieldValue.getValueObject() != null) {
value = new com.azure.ai.formrecognizer.models.FieldValue(
toFieldValueObject(fieldValue.getValueObject(), readResults), FieldValueType.MAP);
} else {
value = new com.azure.ai.formrecognizer.models.FieldValue(null, FieldValueType.MAP);
}

break;
case SELECTION_MARK:
if (fieldValue.getValueSelectionMark() != null) {
@@ -444,9 +449,6 @@ private static float setDefaultConfidenceValue(Float confidence) {
*/
private static Map<String, FormField> toFieldValueObject(Map<String, FieldValue> valueObject,
List<ReadResult> readResults) {
if (valueObject == null) {
return null;
}
Map<String, FormField> fieldValueObjectMap = new TreeMap<>();
valueObject.forEach((key, fieldValue) -> {

@@ -473,9 +475,6 @@ private static Map<String, FormField> toFieldValueObject(Map<String, FieldValue>
* @return The List of {@link FormField}.
*/
private static List<FormField> toFieldValueArray(List<FieldValue> valueArray, List<ReadResult> readResults) {
if (valueArray == null) {
return null;
}
return valueArray.stream()
.map(fieldValue -> {
FieldData valueData = null;
Loading