Skip to content

Commit

Permalink
Document Intelligence 2024-11-30 GA SDK generation (#42980)
Browse files Browse the repository at this point in the history
  • Loading branch information
samvaity authored Dec 12, 2024
1 parent 5bad7bf commit d5188a1
Show file tree
Hide file tree
Showing 202 changed files with 6,192 additions and 6,412 deletions.
2 changes: 1 addition & 1 deletion eng/versioning/version_client.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ com.azure:azure-sdk-parent;1.6.0;1.6.0
com.azure:azure-client-sdk-parent;1.7.0;1.7.0
com.azure:azure-ai-anomalydetector;3.0.0-beta.5;3.0.0-beta.6
com.azure:azure-ai-contentsafety;1.0.9;1.1.0-beta.1
com.azure:azure-ai-documentintelligence;1.0.0-beta.4;1.0.0-beta.5
com.azure:azure-ai-documentintelligence;1.0.0-beta.4;1.0.0
com.azure:azure-ai-documenttranslator;1.0.0-beta.1;1.0.0-beta.2
com.azure:azure-ai-formrecognizer;4.1.12;4.2.0-beta.1
com.azure:azure-ai-formrecognizer-perf;1.0.0-beta.1;1.0.0-beta.1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Release History

## 1.0.0-beta.5 (Unreleased)
## 1.0.0 (Unreleased)

### Features Added

Expand Down Expand Up @@ -115,7 +115,7 @@ https://azure.github.io/azure-sdk/releases/latest/java.html.
null,
null,
ContentFormat.MARKDOWN,
new AnalyzeDocumentRequest().setBase64Source(Files.readAllBytes(document.toPath())));
new AnalyzeDocumentRequest().setBytesSource(Files.readAllBytes(document.toPath())));
```
For the complete sample, see [Sample: Markdown](https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/documentintelligence/azure-ai-documentintelligence/src/samples/java/com/azure/ai/documentintelligence/AnalyzeLayoutMarkdownOutput.java).

Expand All @@ -133,7 +133,7 @@ https://azure.github.io/azure-sdk/releases/latest/java.html.
Arrays.asList(DocumentAnalysisFeature.QUERY_FIELDS),
Arrays.asList("Address", "InvoiceNumber"),
null,
new AnalyzeDocumentRequest().setBase64Source(Files.readAllBytes(document.toPath())));
new AnalyzeDocumentRequest().setBytesSource(Files.readAllBytes(document.toPath())));
```
For the complete sample, see [Sample: Query Fields](https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/documentintelligence/azure-ai-documentintelligence/src/samples/java/com/azure/ai/documentintelligence/AnalyzeAddOnQueryFields.java).

Expand Down Expand Up @@ -204,7 +204,7 @@ https://azure.github.io/azure-sdk/releases/latest/java.html.
Arrays.asList(DocumentAnalysisFeature.FORMULAS),
null,
null,
new AnalyzeDocumentRequest().setBase64Source(Files.readAllBytes(document.toPath())));
new AnalyzeDocumentRequest().setBytesSource(Files.readAllBytes(document.toPath())));
```

For the complete sample, see [Sample: KeyValuePair](https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/documentintelligence/azure-ai-documentintelligence/src/samples/java/com/azure/ai/documentintelligence/AnalyzeAddOnKeyValuePair.java).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ SDK introduces a new enum _ContentFormat_ with value "text" or "markdown" to ind

```java
File document = new File("{your-file-to-analyze}");
SyncPoller<AnalyzeResultOperation, AnalyzeResultOperation> analyzeLayoutResultPoller =
SyncPoller<AnalyzeOperation, AnalyzeResult> analyzeLayoutResultPoller =
client.beginAnalyzeDocument("prebuilt-layout", null,
null,
null,
null,
null,
ContentFormat.MARKDOWN,
new AnalyzeDocumentRequest().setBase64Source(Files.readAllBytes(document.toPath())));
DocumentContentFormat.MARKDOWN,
new AnalyzeDocumentOptions().setBytesSource(Files.readAllBytes(document.toPath())));
```
For the complete sample, see [Sample: Markdown][Sample-AnalyzeLayoutMarkdownOutput].

Expand All @@ -57,14 +57,14 @@ existing fields defined by the model as fallback.

```java
File document = new File("{your-file-to-analyze}");
SyncPoller<AnalyzeResultOperation, AnalyzeResultOperation> analyzeLayoutResultPoller =
SyncPoller<AnalyzeOperation, AnalyzeResult> analyzeLayoutResultPoller =
client.beginAnalyzeDocument("prebuilt-layout", null,
null,
null,
Arrays.asList(DocumentAnalysisFeature.QUERY_FIELDS),
Arrays.asList("Address", "InvoiceNumber"),
null,
new AnalyzeDocumentRequest().setBase64Source(Files.readAllBytes(document.toPath())));
new AnalyzeDocumentOptions().setBytesSource(Files.readAllBytes(document.toPath())));
```
For the complete sample, see [Sample: Query Fields][Sample-AnalyzeAddOnQueryFields].

Expand Down Expand Up @@ -170,14 +170,14 @@ the _Currency_ field in result has been removed.

```java
File document = new File("{your-file-to-analyze}");
SyncPoller<AnalyzeResultOperation, AnalyzeResultOperation> analyzeLayoutResultPoller =
SyncPoller<AnalyzeOperation, AnalyzeResult> analyzeLayoutResultPoller =
client.beginAnalyzeDocument("prebuilt-layout", null,
null,
null,
Arrays.asList(DocumentAnalysisFeature.FORMULAS),
null,
null,
new AnalyzeDocumentRequest().setBase64Source(Files.readAllBytes(document.toPath())));
new AnalyzeDocumentOptions().setBytesSource(Files.readAllBytes(document.toPath())));
```

For the complete sample, see [Sample: KeyValuePair][Sample-AnalyzeAddOnKeyValuePair].
Expand Down Expand Up @@ -206,4 +206,4 @@ For additional samples please take a look at the [Document Intelligence Samples]
[Sample-AnalyzeLayoutMarkdownOutput]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/documentintelligence/azure-ai-documentintelligence/src/samples/java/com/azure/ai/documentintelligence/AnalyzeLayoutMarkdownOutput.java
[service_supported_models]: https://aka.ms/azsdk/documentintelligence/models

![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-java%2Fsdk%2Fdocumentintelligence%2Fazure-ai-documentintelligence%2Fmigration-guide.png)
![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-java%2Fsdk%2Fdocumentintelligence%2Fazure-ai-documentintelligence%2Fmigration-guide.png)
79 changes: 30 additions & 49 deletions sdk/documentintelligence/azure-ai-documentintelligence/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ It includes the following main features:
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-ai-documentintelligence</artifactId>
<version>1.0.0-beta.4</version>
<version>1.0.0</version>
</dependency>
```
[//]: # ({x-version-update-end})
Expand All @@ -43,15 +43,16 @@ This table shows the relationship between SDK versions and supported API version
| 1.0.0-beta.2 | 2024-02-29-preview |
| 1.0.0-beta.3 | 2024-02-29-preview |
| 1.0.0-beta.4 | 2024-07-31-preview |
| 1.0.0 | 2024-11-30 |

> Note: Please rely on the older `azure-ai-formrecognizer` library through the older service API versions for retired
> models, such as `"prebuilt-businessCard"` and `"prebuilt-document"`. For more information, see [Changelog][changelog].
> The below table describes the relationship of each client and its supported API version(s):
| API version | Supported clients |
|------------------------------------------------------------|-----------------------------------------------------------------------------------------------|
| 2023-10-31-preview, 2024-02-29-preview, 2024-07-31-preview | DocumentIntelligenceClient and DocumentIntelligenceAsyncClient |
| 2023-07-31 | DocumentAnalysisClient and DocumentModelAdministrationClient in `azure-ai-formrecognizer` SDK |
| API version | Supported clients |
|------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------|
| 2023-10-31-preview, 2024-02-29-preview, 2024-07-31-preview, 2024-11-30 | DocumentIntelligenceClient and DocumentIntelligenceAsyncClient |
| 2023-07-31 | DocumentAnalysisClient and DocumentModelAdministrationClient in `azure-ai-formrecognizer` SDK |

Please see the [Migration Guide][migration_guide] for more information about migrating from `azure-ai-formrecognizer` to `azure-ai-documentintelligence`.

Expand All @@ -73,12 +74,11 @@ DocumentIntelligenceClient documentIntelligenceClient = new DocumentIntelligence
.buildClient();
```
or
```java readme-sample-createDocumentModelAdministrationClient
DocumentIntelligenceAdministrationClient client =
new DocumentIntelligenceAdministrationClientBuilder()
.credential(new AzureKeyCredential("{key}"))
.endpoint("{endpoint}")
.buildClient();
```java com.azure.ai.documentanalysis.readme.DocumentIntelligenceAdministrationClient
DocumentIntelligenceAdministrationClient documentIntelligenceAsyncClient = new DocumentIntelligenceAdministrationClientBuilder()
.credential(new AzureKeyCredential("{key}"))
.endpoint("{endpoint}")
.buildClient();
```

#### Create an Azure DocumentIntelligence client with Azure Active Directory credential
Expand Down Expand Up @@ -165,16 +165,9 @@ File layoutDocument = new File("local/file_path/filename.png");
Path filePath = layoutDocument.toPath();
BinaryData layoutDocumentData = BinaryData.fromFile(filePath, (int) layoutDocument.length());

SyncPoller<AnalyzeResultOperation, AnalyzeResult> analyzeLayoutResultPoller =
SyncPoller<AnalyzeOperation, AnalyzeResult> analyzeLayoutResultPoller =
documentIntelligenceClient.beginAnalyzeDocument("prebuilt-layout",
null,
null,
null,
null,
null,
null,
null,
new AnalyzeDocumentRequest().setBase64Source(Files.readAllBytes(layoutDocument.toPath())));
new AnalyzeDocumentOptions(Files.readAllBytes(layoutDocument.toPath())));

AnalyzeResult analyzeLayoutResult = analyzeLayoutResultPoller.getFinalResult();

Expand Down Expand Up @@ -226,21 +219,14 @@ For example, to analyze fields from a sales receipt, into the `beginAnalyzeDocum
File sourceFile = new File("../documentintelligence/azure-ai-documentintelligence/src/samples/resources/"
+ "sample-forms/receipts/contoso-allinone.jpg");

SyncPoller<AnalyzeResultOperation, AnalyzeResult> analyzeReceiptPoller =
SyncPoller<AnalyzeOperation, AnalyzeResult> analyzeReceiptPoller =
documentIntelligenceClient.beginAnalyzeDocument("prebuilt-receipt",
null,
null,
null,
null,
null,
null,
null,
new AnalyzeDocumentRequest().setBase64Source(Files.readAllBytes(sourceFile.toPath())));
new AnalyzeDocumentOptions(Files.readAllBytes(sourceFile.toPath())));

AnalyzeResult receiptResults = analyzeReceiptPoller.getFinalResult();

for (int i = 0; i < receiptResults.getDocuments().size(); i++) {
Document analyzedReceipt = receiptResults.getDocuments().get(i);
AnalyzedDocument analyzedReceipt = receiptResults.getDocuments().get(i);
Map<String, DocumentField> receiptFields = analyzedReceipt.getFields();
System.out.printf("----------- Analyzing receipt info %d -----------%n", i);
DocumentField merchantNameField = receiptFields.get("MerchantName");
Expand Down Expand Up @@ -301,18 +287,18 @@ More details on setting up a container and required file structure can be found
String blobContainerUrl = "{SAS_URL_of_your_container_in_blob_storage}";
// The shared access signature (SAS) Url of your Azure Blob Storage container with your forms.
SyncPoller<DocumentModelBuildOperationDetails, DocumentModelDetails> buildOperationPoller =
administrationClient.beginBuildDocumentModel(new BuildDocumentModelRequest("modelID", DocumentBuildMode.TEMPLATE)
administrationClient.beginBuildDocumentModel(new BuildDocumentModelOptions("modelID", DocumentBuildMode.TEMPLATE)
.setAzureBlobSource(new AzureBlobContentSource(blobContainerUrl)));

DocumentModelDetails documentModelDetails = buildOperationPoller.getFinalResult();

// Model Info
System.out.printf("Model ID: %s%n", documentModelDetails.getModelId());
System.out.printf("Model Description: %s%n", documentModelDetails.getDescription());
System.out.printf("Model created on: %s%n%n", documentModelDetails.getCreatedDateTime());
System.out.printf("Model created on: %s%n%n", documentModelDetails.getCreatedOn());

System.out.println("Document Fields:");
documentModelDetails.getDocTypes().forEach((key, documentTypeDetails) -> {
System.out.println("AnalyzedDocument Fields:");
documentModelDetails.getDocumentTypes().forEach((key, documentTypeDetails) -> {
documentTypeDetails.getFieldSchema().forEach((field, documentFieldSchema) -> {
System.out.printf("Field: %s", field);
System.out.printf("Field type: %s", documentFieldSchema.getType());
Expand All @@ -328,23 +314,18 @@ was built on.
```java com.azure.ai.documentintelligence.readme.analyzeCustomModel
String documentUrl = "{document-url}";
String modelId = "{custom-built-model-ID}";
SyncPoller<AnalyzeResultOperation, AnalyzeResult> analyzeDocumentPoller = documentIntelligenceClient.beginAnalyzeDocument(modelId,
"1",
"en-US",
StringIndexType.TEXT_ELEMENTS,
Arrays.asList(DocumentAnalysisFeature.LANGUAGES),
null,
ContentFormat.TEXT,
null,
new AnalyzeDocumentRequest().setUrlSource(documentUrl));
SyncPoller<AnalyzeOperation, AnalyzeResult> analyzeDocumentPoller = documentIntelligenceClient.beginAnalyzeDocument(modelId,
new AnalyzeDocumentOptions(documentUrl).setPages(Collections.singletonList("1")).setLocale("en-US")
.setStringIndexType(StringIndexType.TEXT_ELEMENTS).setDocumentAnalysisFeatures(Arrays.asList(DocumentAnalysisFeature.LANGUAGES))
.setOutputContentFormat(DocumentContentFormat.TEXT));

AnalyzeResult analyzeResult = analyzeDocumentPoller.getFinalResult();

for (int i = 0; i < analyzeResult.getDocuments().size(); i++) {
final Document analyzedDocument = analyzeResult.getDocuments().get(i);
final AnalyzedDocument analyzedDocument = analyzeResult.getDocuments().get(i);
System.out.printf("----------- Analyzing custom document %d -----------%n", i);
System.out.printf("Analyzed document has doc type %s with confidence : %.2f%n",
analyzedDocument.getDocType(), analyzedDocument.getConfidence());
analyzedDocument.getDocumentType(), analyzedDocument.getConfidence());
}

analyzeResult.getPages().forEach(documentPage -> {
Expand Down Expand Up @@ -385,7 +366,7 @@ for (int i = 0; i < tables.size(); i++) {
Manage the models in your Document Intelligence account.
```java com.azure.ai.documentintelligence.readme.manageModels

ResourceDetails resourceDetails = administrationClient.getResourceInfo();
DocumentIntelligenceResourceDetails resourceDetails = administrationClient.getResourceDetails();
System.out.printf("The resource has %s models, and we can have at most %s models.%n",
resourceDetails.getCustomDocumentModels().getCount(), resourceDetails.getCustomDocumentModels().getLimit());

Expand All @@ -398,9 +379,9 @@ customDocumentModels.forEach(documentModelInfo -> {
DocumentModelDetails documentModel = administrationClient.getModel(documentModelInfo.getModelId());
System.out.printf("Model ID: %s%n", documentModel.getModelId());
System.out.printf("Model Description: %s%n", documentModel.getDescription());
System.out.printf("Model created on: %s%n", documentModel.getCreatedDateTime());
if (documentModel.getDocTypes() != null) {
documentModel.getDocTypes().forEach((key, documentTypeDetails) -> {
System.out.printf("Model created on: %s%n", documentModel.getCreatedOn());
if (documentModel.getDocumentTypes() != null) {
documentModel.getDocumentTypes().forEach((key, documentTypeDetails) -> {
documentTypeDetails.getFieldSchema().forEach((field, documentFieldSchema) -> {
System.out.printf("Field: %s, ", field);
System.out.printf("Field type: %s, ", documentFieldSchema.getType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "java",
"TagPrefix": "java/documentintelligence/azure-ai-documentintelligence",
"Tag": "java/documentintelligence/azure-ai-documentintelligence_4f742a2c4a"
"Tag": "java/documentintelligence/azure-ai-documentintelligence_b4bb23cfcf"
}
Loading

0 comments on commit d5188a1

Please sign in to comment.