你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

FormRecognizerAsyncClient 类

  • java.lang.Object
    • com.azure.ai.formrecognizer.FormRecognizerAsyncClient

public final class FormRecognizerAsyncClient

此类提供一个异步客户端,用于连接到 表单识别器 Azure 认知服务。

此客户端提供用于执行以下操作的异步方法:

  1. 自定义表单分析:从特定于不同业务数据和用例的表单和文档中提取和分析数据。 通过将自定义训练的模型 modelId 传递到 方法, beginRecognizeCustomForms 使用该模型。
  2. 预生成模型分析:使用 支持的预生成模型 分析收据、名片、发票和其他文档 使用 beginRecognizeReceipts 方法识别收据信息。
  3. 布局分析:从窗体和文档中提取和分析文本、选择标记、表格和边界框坐标。 使用 beginRecognizeContent tpo 方法执行布局分析。
  4. 轮询和回调:它包括轮询服务以检查分析操作的状态或注册回调以在分析完成时接收通知的机制。

注意: 此客户端仅支持 V2_1 和 更低版本。 建议使用较新的服务版本 DocumentAnalysisClientDocumentModelAdministrationClient

若要使用 API 版本 2022-08-31 及更新,请参阅 迁移指南

服务客户端是开发人员使用 Azure 表单识别器的交互点。 FormRecognizerClient 是同步服务客户端, FormRecognizerAsyncClient 是异步服务客户端。 本文档中显示的示例使用名为 DefaultAzureCredential 的凭据对象进行身份验证,该对象适用于大多数方案,包括本地开发和生产环境。 此外,我们建议使用 托管标识 在生产环境中进行身份验证。 可以在 Azure 标识文档中找到有关不同身份验证方式及其相应凭据类型的详细信息。

示例:使用 DefaultAzureCredential 构造 FormRecognizerClient

下面的代码示例演示如何 FormRecognizerAsyncClient使用“DefaultAzureCredentialBuilder”对其进行配置来创建 。

FormRecognizerAsyncClient formRecognizerAsyncClient = new FormRecognizerClientBuilder()
     .endpoint("{endpoint}")
     .credential(new DefaultAzureCredentialBuilder().build())
     .buildAsyncClient();

此外,请参阅下面的代码示例,以用于 AzureKeyCredential 创建客户端。

FormRecognizerAsyncClient formRecognizerAsyncClient = new FormRecognizerClientBuilder()
     .credential(new AzureKeyCredential("{key}"))
     .endpoint("{endpoint}")
     .buildAsyncClient();

方法摘要

修饰符和类型 方法和描述
PollerFlux<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeBusinessCards(Flux<ByteBuffer> businessCard, long length)

使用光学字符识别 (OCR) 和预生成的业务卡训练模型来识别业务卡数据。

PollerFlux<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeBusinessCards(Flux<ByteBuffer> businessCard, long length, RecognizeBusinessCardsOptions recognizeBusinessCardsOptions)

使用光学字符识别 (OCR) 和预生成的业务卡训练模型识别文档中的业务卡数据。

PollerFlux<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeBusinessCardsFromUrl(String businessCardUrl)

使用光学字符识别 (OCR) 和预先生成的业务卡训练模型来识别业务卡数据。

PollerFlux<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeBusinessCardsFromUrl(String businessCardUrl, RecognizeBusinessCardsOptions recognizeBusinessCardsOptions)

使用光学字符识别 (OCR) 和预先生成的业务卡训练模型来识别业务卡数据。

PollerFlux<FormRecognizerOperationResult,List<FormPage>> beginRecognizeContent(Flux<ByteBuffer> form, long length)

使用光学字符识别 (OCR) 识别内容/布局数据。

PollerFlux<FormRecognizerOperationResult,List<FormPage>> beginRecognizeContent(Flux<ByteBuffer> form, long length, RecognizeContentOptions recognizeContentOptions)

使用光学字符识别 (OCR) 识别内容/布局数据。

PollerFlux<FormRecognizerOperationResult,List<FormPage>> beginRecognizeContentFromUrl(String formUrl)

使用光学字符识别 (OCR) 识别文档中的内容/布局数据。

PollerFlux<FormRecognizerOperationResult,List<FormPage>> beginRecognizeContentFromUrl(String formUrl, RecognizeContentOptions recognizeContentOptions)

使用光学字符识别 (OCR) 和自定义训练模型识别文档中的布局数据。

PollerFlux<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeCustomForms(String modelId, Flux<ByteBuffer> form, long length)

使用光学字符识别 (OCR) 和带或不带标签的自定义训练模型来识别文档中的表单数据。

PollerFlux<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeCustomForms(String modelId, Flux<ByteBuffer> form, long length, RecognizeCustomFormsOptions recognizeCustomFormsOptions)

使用光学字符识别 (OCR) 和带或不带标签的自定义训练模型来识别文档中的表单数据。

PollerFlux<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeCustomFormsFromUrl(String modelId, String formUrl)

使用光学字符识别 (OCR) 和带或不带标签的自定义训练模型来识别文档中的表单数据。

PollerFlux<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeCustomFormsFromUrl(String modelId, String formUrl, RecognizeCustomFormsOptions recognizeCustomFormsOptions)

使用光学字符识别 (OCR) 和自定义训练模型识别文档中的表单数据。

PollerFlux<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeIdentityDocuments(Flux<ByteBuffer> identityDocument, long length)

使用光学字符识别 (OCR) 和基于身份证明文件模型训练的预生成模型来分析标识文档,以从护照和美国驾驶执照中提取关键信息。

PollerFlux<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeIdentityDocuments(Flux<ByteBuffer> identityDocument, long length, RecognizeIdentityDocumentOptions recognizeIdentityDocumentOptions)

使用光学字符识别 (OCR) 和基于身份证明文件模型训练的预生成模型从护照和美国驾驶执照中提取关键信息,分析身份文档。

PollerFlux<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeIdentityDocumentsFromUrl(String identityDocumentUrl)

使用光学字符识别 (OCR) 和基于身份证明文件模型训练的预生成模型从护照和美国驾驶执照中提取关键信息,分析身份文档。

PollerFlux<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeIdentityDocumentsFromUrl(String identityDocumentUrl, RecognizeIdentityDocumentOptions recognizeIdentityDocumentOptions)

使用光学字符识别 (OCR) 和基于身份证明文件模型训练的预生成模型从护照和美国驾驶执照中提取关键信息,分析身份文档。

PollerFlux<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeInvoices(Flux<ByteBuffer> invoice, long length)

使用光学字符识别 (OCR) 和预生成发票训练模型来识别发票数据。

PollerFlux<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeInvoices(Flux<ByteBuffer> invoice, long length, RecognizeInvoicesOptions recognizeInvoicesOptions)

使用光学字符识别 (OCR) 和预生成发票训练模型从文档识别发票数据。

PollerFlux<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeInvoicesFromUrl(String invoiceUrl)

使用光学字符识别 (OCR) 和预生成发票训练模型来识别发票数据。

PollerFlux<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeInvoicesFromUrl(String invoiceUrl, RecognizeInvoicesOptions recognizeInvoicesOptions)

使用光学字符识别 (OCR) 和预生成发票训练模型来识别发票数据。

PollerFlux<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeReceipts(Flux<ByteBuffer> receipt, long length)

使用光学字符识别 (OCR) 和预生成的收据训练模型来识别收据数据。

PollerFlux<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeReceipts(Flux<ByteBuffer> receipt, long length, RecognizeReceiptsOptions recognizeReceiptsOptions)

使用光学字符识别 (OCR) 和预生成收据训练模型识别文档中的回执数据。

PollerFlux<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeReceiptsFromUrl(String receiptUrl)

使用光学字符识别 (OCR) 和预生成的收据训练模型来识别收据数据。

PollerFlux<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeReceiptsFromUrl(String receiptUrl, RecognizeReceiptsOptions recognizeReceiptsOptions)

使用光学字符识别 (OCR) 和预生成的收据训练模型来识别收据数据。

方法继承自 java.lang.Object

方法详细信息

beginRecognizeBusinessCards

public PollerFlux<>> beginRecognizeBusinessCards(Flux businessCard, long length)

使用光学字符识别 (OCR) 和预生成的业务卡训练模型来识别业务卡数据。

该服务不支持取消长时间运行的操作,并返回一条错误消息,指示缺少取消支持。

有关业务卡上的字段,请参阅此处。 请注意, businessCard 如果启用了重试 (默认) ,则传递的 必须可重播。 换句话说, Flux 必须在每次订阅时生成相同的数据。

代码示例

File businessCard = new File("{local/file_path/fileName.jpg}");
 Flux<ByteBuffer> buffer = toFluxByteBuffer(new ByteArrayInputStream(Files.readAllBytes(businessCard.toPath())));
 // if training polling operation completed, retrieve the final result.
 formRecognizerAsyncClient.beginRecognizeBusinessCards(buffer, businessCard.length())
     .flatMap(AsyncPollResponse::getFinalResult)
     .subscribe(recognizedBusinessCards -> {
         for (int i = 0; i < recognizedBusinessCards.size(); i++) {
             RecognizedForm recognizedForm = recognizedBusinessCards.get(i);
             Map<String, FormField> recognizedFields = recognizedForm.getFields();
             System.out.printf("----------- Recognized Business Card page %d -----------%n", i);
             FormField contactNamesFormField = recognizedFields.get("ContactNames");
             if (contactNamesFormField != null) {
                 if (FieldValueType.LIST == contactNamesFormField.getValue().getValueType()) {
                     List<FormField> contactNamesList = contactNamesFormField.getValue().asList();
                     contactNamesList.stream()
                         .filter(contactName -> FieldValueType.MAP == contactName.getValue().getValueType())
                         .map(contactName -> {
                             System.out.printf("Contact name: %s%n", contactName.getValueData().getText());
                             return contactName.getValue().asMap();
                         })
                         .forEach(contactNamesMap -> contactNamesMap.forEach((key, contactName) -> {
                             if ("FirstName".equals(key)) {
                                 if (FieldValueType.STRING == contactName.getValue().getValueType()) {
                                     String firstName = contactName.getValue().asString();
                                     System.out.printf("\tFirst Name: %s, confidence: %.2f%n",
                                         firstName, contactName.getConfidence());
                                 }
                             }
                             if ("LastName".equals(key)) {
                                 if (FieldValueType.STRING == contactName.getValue().getValueType()) {
                                     String lastName = contactName.getValue().asString();
                                     System.out.printf("\tLast Name: %s, confidence: %.2f%n",
                                         lastName, contactName.getConfidence());
                                 }
                             }
                         }));
                 }
             }
             FormField jobTitles = recognizedFields.get("JobTitles");
             if (jobTitles != null) {
                 if (FieldValueType.LIST == jobTitles.getValue().getValueType()) {
                     List<FormField> jobTitlesItems = jobTitles.getValue().asList();
                     jobTitlesItems.forEach(jobTitlesItem -> {
                         if (FieldValueType.STRING == jobTitlesItem.getValue().getValueType()) {
                             String jobTitle = jobTitlesItem.getValue().asString();
                             System.out.printf("Job Title: %s, confidence: %.2f%n",
                                 jobTitle, jobTitlesItem.getConfidence());
                         }
                     });
                 }
             }
         }
     });

Parameters:

businessCard - 要从中识别业务卡信息的文档的数据。
length - 数据的确切长度。

Returns:

一个 ,PollerFlux<T,U>用于轮询识别业务卡操作,直到它完成、失败或已取消。 完成的操作返回 的列表 RecognizedForm

beginRecognizeBusinessCards

public PollerFlux<>> beginRecognizeBusinessCards(Flux businessCard, long length, RecognizeBusinessCardsOptions recognizeBusinessCardsOptions)

使用光学字符识别 (OCR) 和预生成的业务卡训练模型识别文档中的业务卡数据。

该服务不支持取消长时间运行的操作,并返回一条错误消息,指示缺少取消支持。

有关业务卡上的字段,请参阅此处。 请注意, businessCard 如果启用了重试 (默认) ,则传递的 必须可重播。 换句话说, Flux 必须在每次订阅时生成相同的数据。

代码示例

File businessCard = new File("{local/file_path/fileName.jpg}");
 boolean includeFieldElements = true;
 // Utility method to convert input stream to Byte buffer
 Flux<ByteBuffer> buffer = toFluxByteBuffer(new ByteArrayInputStream(Files.readAllBytes(businessCard.toPath())));
 // if training polling operation completed, retrieve the final result.
 formRecognizerAsyncClient.beginRecognizeBusinessCards(buffer, businessCard.length(),
     new RecognizeBusinessCardsOptions()
         .setContentType(FormContentType.IMAGE_JPEG)
         .setFieldElementsIncluded(includeFieldElements))
     .setPollInterval(Duration.ofSeconds(5))
     .flatMap(AsyncPollResponse::getFinalResult)
     .subscribe(recognizedBusinessCards -> {
         for (int i = 0; i < recognizedBusinessCards.size(); i++) {
             RecognizedForm recognizedForm = recognizedBusinessCards.get(i);
             Map<String, FormField> recognizedFields = recognizedForm.getFields();
             System.out.printf("----------- Recognized Business Card page %d -----------%n", i);
             FormField contactNamesFormField = recognizedFields.get("ContactNames");
             if (contactNamesFormField != null) {
                 if (FieldValueType.LIST == contactNamesFormField.getValue().getValueType()) {
                     List<FormField> contactNamesList = contactNamesFormField.getValue().asList();
                     contactNamesList.stream()
                         .filter(contactName -> FieldValueType.MAP == contactName.getValue().getValueType())
                         .map(contactName -> {
                             System.out.printf("Contact name: %s%n", contactName.getValueData().getText());
                             return contactName.getValue().asMap();
                         })
                         .forEach(contactNamesMap -> contactNamesMap.forEach((key, contactName) -> {
                             if ("FirstName".equals(key)) {
                                 if (FieldValueType.STRING == contactName.getValue().getValueType()) {
                                     String firstName = contactName.getValue().asString();
                                     System.out.printf("\tFirst Name: %s, confidence: %.2f%n",
                                         firstName, contactName.getConfidence());
                                 }
                             }
                             if ("LastName".equals(key)) {
                                 if (FieldValueType.STRING == contactName.getValue().getValueType()) {
                                     String lastName = contactName.getValue().asString();
                                     System.out.printf("\tLast Name: %s, confidence: %.2f%n",
                                         lastName, contactName.getConfidence());
                                 }
                             }
                         }));
                 }
             }
             FormField jobTitles = recognizedFields.get("JobTitles");
             if (jobTitles != null) {
                 if (FieldValueType.LIST == jobTitles.getValue().getValueType()) {
                     List<FormField> jobTitlesItems = jobTitles.getValue().asList();
                     jobTitlesItems.forEach(jobTitlesItem -> {
                         if (FieldValueType.STRING == jobTitlesItem.getValue().getValueType()) {
                             String jobTitle = jobTitlesItem.getValue().asString();
                             System.out.printf("Job Title: %s, confidence: %.2f%n",
                                 jobTitle, jobTitlesItem.getConfidence());
                         }
                     });
                 }
             }
         }
     });

Parameters:

businessCard - 要从中识别业务卡信息的文档的数据。
length - 数据的确切长度。
recognizeBusinessCardsOptions - 分析业务卡时可能传递的其他可配置RecognizeBusinessCardsOptions项。

Returns:

一个 ,PollerFlux<T,U>用于轮询识别业务卡操作,直到它完成、失败或已取消。 完成的操作返回 的列表 RecognizedForm

beginRecognizeBusinessCardsFromUrl

public PollerFlux<>> beginRecognizeBusinessCardsFromUrl(String businessCardUrl)

使用光学字符识别 (OCR) 和预生成的业务卡训练模型来识别业务卡数据。

该服务不支持取消长时间运行的操作,并返回一条错误消息,指示缺少取消支持。

有关业务卡上的字段,请参阅此处

代码示例

String formUrl = "{form_url}";
 String modelId = "{custom_trained_model_id}";

 // if training polling operation completed, retrieve the final result.
 formRecognizerAsyncClient.beginRecognizeCustomFormsFromUrl(modelId, formUrl)
     // if training polling operation completed, retrieve the final result.
     .flatMap(AsyncPollResponse::getFinalResult)
     .flatMap(Flux::fromIterable)
     .subscribe(recognizedForm -> recognizedForm.getFields()
         .forEach((fieldText, formField) -> {
             System.out.printf("Field text: %s%n", fieldText);
             System.out.printf("Field value data text: %s%n", formField.getValueData().getText());
             System.out.printf("Confidence score: %.2f%n", formField.getConfidence());
         }));

Parameters:

businessCardUrl - 输入业务卡的源 URL。

Returns:

一个 ,PollerFlux<T,U>用于轮询识别业务卡操作,直到它完成、失败或已取消。 完成的操作返回 的列表 RecognizedForm

beginRecognizeBusinessCardsFromUrl

public PollerFlux<>> beginRecognizeBusinessCardsFromUrl(String businessCardUrl, RecognizeBusinessCardsOptions recognizeBusinessCardsOptions)

使用光学字符识别 (OCR) 和预先生成的业务卡训练模型来识别业务卡数据。

该服务不支持取消长时间运行的操作,并返回一条错误消息,指示没有取消支持。

有关在企业卡中找到的字段,请参阅此处

代码示例

String businessCardUrl = "{business_card_url}";
 boolean includeFieldElements = true;
 // if training polling operation completed, retrieve the final result.
 formRecognizerAsyncClient.beginRecognizeBusinessCardsFromUrl(businessCardUrl,
     new RecognizeBusinessCardsOptions()
         .setFieldElementsIncluded(includeFieldElements))
     .setPollInterval(Duration.ofSeconds(5))
     .flatMap(AsyncPollResponse::getFinalResult)
     .subscribe(recognizedBusinessCards -> {
         for (int i = 0; i < recognizedBusinessCards.size(); i++) {
             RecognizedForm recognizedBusinessCard = recognizedBusinessCards.get(i);
             Map<String, FormField> recognizedFields = recognizedBusinessCard.getFields();
             System.out.printf("----------- Recognized Business Card page %d -----------%n", i);
             FormField contactNamesFormField = recognizedFields.get("ContactNames");
             if (contactNamesFormField != null) {
                 if (FieldValueType.LIST == contactNamesFormField.getValue().getValueType()) {
                     List<FormField> contactNamesList = contactNamesFormField.getValue().asList();
                     contactNamesList.stream()
                         .filter(contactName -> FieldValueType.MAP == contactName.getValue().getValueType())
                         .map(contactName -> {
                             System.out.printf("Contact name: %s%n", contactName.getValueData().getText());
                             return contactName.getValue().asMap();
                         })
                         .forEach(contactNamesMap -> contactNamesMap.forEach((key, contactName) -> {
                             if ("FirstName".equals(key)) {
                                 if (FieldValueType.STRING == contactName.getValue().getValueType()) {
                                     String firstName = contactName.getValue().asString();
                                     System.out.printf("\tFirst Name: %s, confidence: %.2f%n",
                                         firstName, contactName.getConfidence());
                                 }
                             }
                             if ("LastName".equals(key)) {
                                 if (FieldValueType.STRING == contactName.getValue().getValueType()) {
                                     String lastName = contactName.getValue().asString();
                                     System.out.printf("\tLast Name: %s, confidence: %.2f%n",
                                         lastName, contactName.getConfidence());
                                 }
                             }
                         }));
                 }
             }
             FormField jobTitles = recognizedFields.get("JobTitles");
             if (jobTitles != null) {
                 if (FieldValueType.LIST == jobTitles.getValue().getValueType()) {
                     List<FormField> jobTitlesItems = jobTitles.getValue().asList();
                     jobTitlesItems.forEach(jobTitlesItem -> {
                         if (FieldValueType.STRING == jobTitlesItem.getValue().getValueType()) {
                             String jobTitle = jobTitlesItem.getValue().asString();
                             System.out.printf("Job Title: %s, confidence: %.2f%n",
                                 jobTitle, jobTitlesItem.getConfidence());
                         }
                     });
                 }
             }
         }
     });

Parameters:

businessCardUrl - 输入业务卡的源 URL。
recognizeBusinessCardsOptions - 分析业务卡时可能传递的其他可配置项RecognizeBusinessCardsOptions

Returns:

一个 PollerFlux<T,U> ,用于轮询识别业务卡操作,直到操作完成、失败或已取消。 完成的操作返回 的列表 RecognizedForm

beginRecognizeContent

public PollerFlux<>> beginRecognizeContent(Flux form, long length)

使用光学字符识别 (OCR) 识别内容/布局数据。

该服务不支持取消长时间运行的操作,并返回一条错误消息,指示没有取消支持。

请注意, data 如果启用重试 (默认) ,则传递的 必须可重播。 换句话说, Flux 每次订阅 时都必须生成相同的数据。

代码示例

File form = new File("{local/file_path/fileName.jpg}");
 // Utility method to convert input stream to Byte buffer
 Flux<ByteBuffer> buffer = toFluxByteBuffer(new ByteArrayInputStream(Files.readAllBytes(form.toPath())));

 // if training polling operation completed, retrieve the final result.
 formRecognizerAsyncClient.beginRecognizeContent(buffer, form.length())
     .flatMap(AsyncPollResponse::getFinalResult)
     .flatMap(Flux::fromIterable)
     .subscribe(formPage -> {
         System.out.printf("Page Angle: %s%n", formPage.getTextAngle());
         System.out.printf("Page Dimension unit: %s%n", formPage.getUnit());
         // Table information
         System.out.println("Recognized Tables: ");
         formPage.getTables().forEach(formTable ->
             formTable.getCells().forEach(recognizedTableCell ->
                 System.out.printf("%s ", recognizedTableCell.getText())));
     });

Parameters:

form - 要从中识别内容信息的表单的数据。
length - 数据的确切长度。

Returns:

PollerFlux<T,U> 询识别内容操作,直到它已完成、失败或已取消。 完成的操作返回 的列表 FormPage

beginRecognizeContent

public PollerFlux<>> beginRecognizeContent(Flux form, long length, RecognizeContentOptions recognizeContentOptions)

使用光学字符识别 (OCR) 识别内容/布局数据。

该服务不支持取消长时间运行的操作,并返回一条错误消息,指示没有取消支持。

请注意, data 如果启用重试 (默认) ,则传递的 必须可重播。 换句话说, Flux 每次订阅 时都必须生成相同的数据。

内容识别支持自动语言识别和多语言文档,因此仅当你想要强制将文档作为特定语言在 中 RecognizeContentOptions进行处理时,才提供语言代码。

代码示例

File form = new File("{local/file_path/fileName.jpg}");
 // Utility method to convert input stream to Byte buffer
 Flux<ByteBuffer> buffer = toFluxByteBuffer(new ByteArrayInputStream(Files.readAllBytes(form.toPath())));
 // if training polling operation completed, retrieve the final result.
 formRecognizerAsyncClient.beginRecognizeContent(buffer, form.length(),
     new RecognizeContentOptions()
         .setContentType(FormContentType.IMAGE_JPEG)
         .setPollInterval(Duration.ofSeconds(5)))
     .flatMap(AsyncPollResponse::getFinalResult)
     .flatMap(Flux::fromIterable)
     .subscribe(formPage -> {
         System.out.printf("Page Angle: %s%n", formPage.getTextAngle());
         System.out.printf("Page Dimension unit: %s%n", formPage.getUnit());
         // Table information
         System.out.println("Recognized Tables: ");
         formPage.getTables().forEach(formTable -> formTable.getCells().forEach(recognizedTableCell ->
             System.out.printf("%s ", recognizedTableCell.getText())));
     });

Parameters:

form - 要从中识别内容信息的表单的数据。
length - 数据的确切长度。
recognizeContentOptions - 识别表单上的内容/布局时可能传递的其他可配置项 RecognizeContentOptions

Returns:

PollerFlux<T,U> 询识别内容操作,直到它已完成、失败或已取消。 完成的操作返回 的列表 FormPage

beginRecognizeContentFromUrl

public PollerFlux<>> beginRecognizeContentFromUrl(String formUrl)

使用光学字符识别 (OCR) 识别文档中的内容/布局数据。

该服务不支持取消长时间运行的操作,并返回一条错误消息,指示没有取消支持。

代码示例

String formUrl = "{formUrl}";
 formRecognizerAsyncClient.beginRecognizeContentFromUrl(formUrl)
     // if training polling operation completed, retrieve the final result.
     .flatMap(AsyncPollResponse::getFinalResult)
     .flatMap(Flux::fromIterable)
     .subscribe(formPage -> {
         System.out.printf("Page Angle: %s%n", formPage.getTextAngle());
         System.out.printf("Page Dimension unit: %s%n", formPage.getUnit());
         // Table information
         System.out.println("Recognized Tables: ");
         formPage.getTables().forEach(formTable ->
             formTable.getCells().forEach(recognizedTableCell ->
                 System.out.printf("%s ", recognizedTableCell.getText())));
     });

Parameters:

formUrl - 要分析的表单的 URL。

Returns:

一个 PollerFlux<T,U> ,它轮询识别内容操作,直到它完成、失败或已取消。 完成的操作返回 的列表 FormPage

beginRecognizeContentFromUrl

public PollerFlux<>> beginRecognizeContentFromUrl(String formUrl, RecognizeContentOptions recognizeContentOptions)

使用光学字符识别 (OCR) 和自定义训练模型识别文档中的布局数据。

该服务不支持取消长时间运行的操作,并返回一条错误消息,指示没有取消支持。

内容识别支持自动语言识别和多语言文档,因此仅当你想要强制将文档作为特定语言在 中 RecognizeContentOptions进行处理时,才提供语言代码。

代码示例

String formUrl = "{formUrl}";
 // if training polling operation completed, retrieve the final result.
 formRecognizerAsyncClient.beginRecognizeContentFromUrl(formUrl,
     new RecognizeContentOptions().setPollInterval(Duration.ofSeconds(5)))
     .flatMap(AsyncPollResponse::getFinalResult)
     .flatMap(Flux::fromIterable)
     .subscribe(formPage -> {
         System.out.printf("Page Angle: %s%n", formPage.getTextAngle());
         System.out.printf("Page Dimension unit: %s%n", formPage.getUnit());
         // Table information
         System.out.println("Recognized Tables: ");
         formPage.getTables().forEach(formTable ->
             formTable.getCells().forEach(recognizedTableCell ->
                 System.out.printf("%s ", recognizedTableCell.getText())));
     });

Parameters:

formUrl - 输入窗体的源 URL。
recognizeContentOptions - 识别表单上的内容/布局时可能传递的其他可配置项 RecognizeContentOptions

Returns:

一个 PollerFlux<T,U> ,它轮询已识别的内容/布局操作,直到它完成、失败或已取消。 完成的操作返回 的列表 FormPage

beginRecognizeCustomForms

public PollerFlux<>> beginRecognizeCustomForms(String modelId, Flux form, long length)

使用光学字符识别 (OCR) 和带或不带标签的自定义训练模型来识别文档中的表单数据。

该服务不支持取消长时间运行的操作,并返回一条错误消息,指示没有取消支持。

请注意, data 如果启用重试 (默认) ,则传递的 必须可重播。 换句话说, Flux 每次订阅 时都必须生成相同的数据。

代码示例

File form = new File("{local/file_path/fileName.jpg}");
 String modelId = "{custom_trained_model_id}";
 // Utility method to convert input stream to Byte buffer
 Flux<ByteBuffer> buffer = toFluxByteBuffer(new ByteArrayInputStream(Files.readAllBytes(form.toPath())));

 // if training polling operation completed, retrieve the final result.
 formRecognizerAsyncClient.beginRecognizeCustomForms(modelId, buffer, form.length())
     // if training polling operation completed, retrieve the final result.
     .flatMap(AsyncPollResponse::getFinalResult)
     .flatMap(Flux::fromIterable)
     .subscribe(recognizedForm -> recognizedForm.getFields()
         .forEach((fieldText, formField) -> {
             System.out.printf("Field text: %s%n", fieldText);
             System.out.printf("Field value data text: %s%n", formField.getValueData().getText());
             System.out.printf("Confidence score: %.2f%n", formField.getConfidence());
         }));

Parameters:

modelId - 要使用的 UUID 字符串格式自定义训练模型 ID。
form - 要从中识别表单信息的表单数据。
length - 数据的确切长度。

Returns:

一个 PollerFlux<T,U> ,它轮询识别自定义表单操作,直到它已完成、失败或已取消。 完成的操作返回 的列表 RecognizedForm

beginRecognizeCustomForms

public PollerFlux<>> beginRecognizeCustomForms(String modelId, Flux form, long length, RecognizeCustomFormsOptions recognizeCustomFormsOptions)

使用光学字符识别 (OCR) 和带或不带标签的自定义训练模型来识别文档中的表单数据。

该服务不支持取消长时间运行的操作,并返回一条错误消息,指示没有取消支持。

请注意, data 如果启用重试 (默认) ,则传递的 必须可重播。 换句话说, Flux 每次订阅 时都必须生成相同的数据。

代码示例

File form = new File("{local/file_path/fileName.jpg}");
 String modelId = "{custom_trained_model_id}";
 boolean includeFieldElements = true;
 // Utility method to convert input stream to Byte buffer
 Flux<ByteBuffer> buffer = toFluxByteBuffer(new ByteArrayInputStream(Files.readAllBytes(form.toPath())));

 // if training polling operation completed, retrieve the final result.
 formRecognizerAsyncClient.beginRecognizeCustomForms(modelId, buffer, form.length(),
     new RecognizeCustomFormsOptions()
         .setContentType(FormContentType.IMAGE_JPEG)
         .setFieldElementsIncluded(includeFieldElements)
         .setPollInterval(Duration.ofSeconds(5)))
     // if training polling operation completed, retrieve the final result.
     .flatMap(AsyncPollResponse::getFinalResult)
     .flatMap(Flux::fromIterable)
     .subscribe(recognizedForm -> recognizedForm.getFields()
         .forEach((fieldName, formField) -> {
             System.out.printf("Field text: %s%n", fieldName);
             System.out.printf("Field value data text: %s%n", formField.getValueData().getText());
             System.out.printf("Confidence score: %.2f%n", formField.getConfidence());
         }));

Parameters:

modelId - 要使用的 UUID 字符串格式自定义训练模型 ID。
form - 要从中识别表单信息的表单数据。
length - 数据的确切长度。
recognizeCustomFormsOptions - 识别自定义窗体时可能传递的附加可配置项 RecognizeCustomFormsOptions

Returns:

一个 PollerFlux<T,U> ,它轮询识别自定义表单操作,直到它已完成、失败或已取消。 完成的操作返回 的列表 RecognizedForm

beginRecognizeCustomFormsFromUrl

public PollerFlux<>> beginRecognizeCustomFormsFromUrl(String modelId, String formUrl)

使用光学字符识别 (OCR) 和带或不带标签的自定义训练模型来识别文档中的表单数据。

该服务不支持取消长时间运行的操作,并返回一条错误消息,指示没有取消支持。

代码示例

String formUrl = "{form_url}";
 String modelId = "{custom_trained_model_id}";

 // if training polling operation completed, retrieve the final result.
 formRecognizerAsyncClient.beginRecognizeCustomFormsFromUrl(modelId, formUrl)
     // if training polling operation completed, retrieve the final result.
     .flatMap(AsyncPollResponse::getFinalResult)
     .flatMap(Flux::fromIterable)
     .subscribe(recognizedForm -> recognizedForm.getFields()
         .forEach((fieldText, formField) -> {
             System.out.printf("Field text: %s%n", fieldText);
             System.out.printf("Field value data text: %s%n", formField.getValueData().getText());
             System.out.printf("Confidence score: %.2f%n", formField.getConfidence());
         }));

Parameters:

modelId - 要使用的 UUID 字符串格式自定义训练模型 ID。
formUrl - 要分析的表单的 URL。

Returns:

一个 PollerFlux<T,U> ,它轮询识别自定义表单操作,直到它已完成、失败或已取消。 完成的操作返回 的列表 RecognizedForm

beginRecognizeCustomFormsFromUrl

public PollerFlux<>> beginRecognizeCustomFormsFromUrl(String modelId, String formUrl, RecognizeCustomFormsOptions recognizeCustomFormsOptions)

使用光学字符识别 (OCR) 和自定义训练模型识别文档中的表单数据。

该服务不支持取消长时间运行的操作,并返回一条错误消息,指示没有取消支持。

代码示例

String formUrl = "{formUrl}";
 String modelId = "{model_id}";
 boolean includeFieldElements = true;

 formRecognizerAsyncClient.beginRecognizeCustomFormsFromUrl(modelId, formUrl,
     new RecognizeCustomFormsOptions()
         .setFieldElementsIncluded(includeFieldElements)
         .setPollInterval(Duration.ofSeconds(10)))
     // if training polling operation completed, retrieve the final result.
     .flatMap(AsyncPollResponse::getFinalResult)
     .flatMap(Flux::fromIterable)
     .subscribe(recognizedForm -> recognizedForm.getFields()
         .forEach((fieldText, formField) -> {
             System.out.printf("Field text: %s%n", fieldText);
             System.out.printf("Field value data text: %s%n", formField.getValueData().getText());
             System.out.printf("Confidence score: %.2f%n", formField.getConfidence());
         }));

Parameters:

modelId - 要使用的 UUID 字符串格式自定义训练模型 ID。
formUrl - 输入窗体的源 URL。
recognizeCustomFormsOptions - 识别自定义窗体时可能传递的附加可配置项 RecognizeCustomFormsOptions

Returns:

一个 PollerFlux<T,U> ,它轮询识别自定义表单操作,直到它已完成、失败或已取消。 完成的操作返回 的列表 RecognizedForm

beginRecognizeIdentityDocuments

public PollerFlux<>> beginRecognizeIdentityDocuments(Flux identityDocument, long length)

使用光学字符识别 (OCR) 和基于身份证明文件模型训练的预生成模型来分析标识文档,以从护照和美国驾驶执照中提取关键信息。 有关在标识文档上找到的字段,请参阅 此处

该服务不支持取消长时间运行的操作,并返回一条错误消息,指示没有取消支持。

请注意, identityDocument 如果启用重试 (默认) ,则传递的 必须可重播。 换句话说, Flux 每次订阅 时都必须生成相同的数据。

代码示例

File license = new File("local/file_path/license.jpg");
 Flux<ByteBuffer> buffer =
     toFluxByteBuffer(new ByteArrayInputStream(Files.readAllBytes(license.toPath())));
 // if training polling operation completed, retrieve the final result.
 formRecognizerAsyncClient.beginRecognizeIdentityDocuments(buffer, license.length())
     .flatMap(AsyncPollResponse::getFinalResult)
     .subscribe(recognizedIDDocumentResult -> {
         for (int i = 0; i < recognizedIDDocumentResult.size(); i++) {
             RecognizedForm recognizedForm = recognizedIDDocumentResult.get(i);
             Map<String, FormField> recognizedFields = recognizedForm.getFields();
             System.out.printf("----------- Recognized license info for page %d -----------%n", i);

             FormField firstNameField = recognizedFields.get("FirstName");
             if (firstNameField != null) {
                 if (FieldValueType.STRING == firstNameField.getValue().getValueType()) {
                     String firstName = firstNameField.getValue().asString();
                     System.out.printf("First Name: %s, confidence: %.2f%n",
                         firstName, firstNameField.getConfidence());
                 }
             }

             FormField lastNameField = recognizedFields.get("LastName");
             if (lastNameField != null) {
                 if (FieldValueType.STRING == lastNameField.getValue().getValueType()) {
                     String lastName = lastNameField.getValue().asString();
                     System.out.printf("Last name: %s, confidence: %.2f%n",
                         lastName, lastNameField.getConfidence());
                 }
             }

             FormField countryRegionFormField = recognizedFields.get("CountryRegion");
             if (countryRegionFormField != null) {
                 if (FieldValueType.STRING == countryRegionFormField.getValue().getValueType()) {
                     String countryRegion = countryRegionFormField.getValue().asCountryRegion();
                     System.out.printf("Country or region: %s, confidence: %.2f%n",
                         countryRegion, countryRegionFormField.getConfidence());
                 }
             }

             FormField dateOfExpirationField = recognizedFields.get("DateOfExpiration");
             if (dateOfExpirationField != null) {
                 if (FieldValueType.DATE == dateOfExpirationField.getValue().getValueType()) {
                     LocalDate expirationDate = dateOfExpirationField.getValue().asDate();
                     System.out.printf("Document date of expiration: %s, confidence: %.2f%n",
                         expirationDate, dateOfExpirationField.getConfidence());
                 }
             }

             FormField documentNumberField = recognizedFields.get("DocumentNumber");
             if (documentNumberField != null) {
                 if (FieldValueType.STRING == documentNumberField.getValue().getValueType()) {
                     String documentNumber = documentNumberField.getValue().asString();
                     System.out.printf("Document number: %s, confidence: %.2f%n",
                         documentNumber, documentNumberField.getConfidence());
                 }
             }
         }
     });

Parameters:

identityDocument - 要从中识别标识文档信息的文档的数据。
length - 数据的确切长度。

Returns:

PollerFlux<T,U> 询识别标识文档操作,直到其完成、失败或已取消。 完成的操作返回 的列表 RecognizedForm

beginRecognizeIdentityDocuments

public PollerFlux<>> beginRecognizeIdentityDocuments(Flux identityDocument, long length, RecognizeIdentityDocumentOptions recognizeIdentityDocumentOptions)

使用光学字符识别 (OCR) 和基于身份证明文件模型训练的预生成模型来分析标识文档,以从护照和美国驾驶执照中提取关键信息。 有关在标识文档上找到的字段,请参阅 此处

该服务不支持取消长时间运行的操作,并返回一条错误消息,指示缺少取消支持。

请注意, identityDocument 如果启用了重试 (默认) ,则传递的 必须可重播。 换句话说, Flux 必须在每次订阅时生成相同的数据。

代码示例

File licenseDocument = new File("local/file_path/license.jpg");
 boolean includeFieldElements = true;
 // Utility method to convert input stream to Byte buffer
 Flux<ByteBuffer> buffer =
     toFluxByteBuffer(new ByteArrayInputStream(Files.readAllBytes(licenseDocument.toPath())));
 // if training polling operation completed, retrieve the final result.
 formRecognizerAsyncClient.beginRecognizeIdentityDocuments(buffer,
     licenseDocument.length(),
     new RecognizeIdentityDocumentOptions()
         .setContentType(FormContentType.IMAGE_JPEG)
         .setFieldElementsIncluded(includeFieldElements))
     .setPollInterval(Duration.ofSeconds(5))
     .flatMap(AsyncPollResponse::getFinalResult)
     .subscribe(recognizedIDDocumentResult -> {
         for (int i = 0; i < recognizedIDDocumentResult.size(); i++) {
             RecognizedForm recognizedForm = recognizedIDDocumentResult.get(i);
             Map<String, FormField> recognizedFields = recognizedForm.getFields();
             System.out.printf("----------- Recognized license info for page %d -----------%n", i);

             FormField firstNameField = recognizedFields.get("FirstName");
             if (firstNameField != null) {
                 if (FieldValueType.STRING == firstNameField.getValue().getValueType()) {
                     String firstName = firstNameField.getValue().asString();
                     System.out.printf("First Name: %s, confidence: %.2f%n",
                         firstName, firstNameField.getConfidence());
                 }
             }

             FormField lastNameField = recognizedFields.get("LastName");
             if (lastNameField != null) {
                 if (FieldValueType.STRING == lastNameField.getValue().getValueType()) {
                     String lastName = lastNameField.getValue().asString();
                     System.out.printf("Last name: %s, confidence: %.2f%n",
                         lastName, lastNameField.getConfidence());
                 }
             }

             FormField countryRegionFormField = recognizedFields.get("CountryRegion");
             if (countryRegionFormField != null) {
                 if (FieldValueType.STRING == countryRegionFormField.getValue().getValueType()) {
                     String countryRegion = countryRegionFormField.getValue().asCountryRegion();
                     System.out.printf("Country or region: %s, confidence: %.2f%n",
                         countryRegion, countryRegionFormField.getConfidence());
                 }
             }

             FormField dateOfExpirationField = recognizedFields.get("DateOfExpiration");
             if (dateOfExpirationField != null) {
                 if (FieldValueType.DATE == dateOfExpirationField.getValue().getValueType()) {
                     LocalDate expirationDate = dateOfExpirationField.getValue().asDate();
                     System.out.printf("Document date of expiration: %s, confidence: %.2f%n",
                         expirationDate, dateOfExpirationField.getConfidence());
                 }
             }

             FormField documentNumberField = recognizedFields.get("DocumentNumber");
             if (documentNumberField != null) {
                 if (FieldValueType.STRING == documentNumberField.getValue().getValueType()) {
                     String documentNumber = documentNumberField.getValue().asString();
                     System.out.printf("Document number: %s, confidence: %.2f%n",
                         documentNumber, documentNumberField.getConfidence());
                 }
             }
         }
     });

Parameters:

identityDocument - 要从中识别标识文档信息的文档的数据。
length - 数据的确切长度。
recognizeIdentityDocumentOptions - 分析标识文档时可能传递的其他可配置 RecognizeIdentityDocumentOptions 项。

Returns:

一个 PollerFlux<T,U> ,它轮询识别标识文档操作,直到它完成、失败或已取消。 完成的操作返回 的列表 RecognizedForm

beginRecognizeIdentityDocumentsFromUrl

public PollerFlux<>> beginRecognizeIdentityDocumentsFromUrl(String identityDocumentUrl)

使用光学字符识别 (OCR) 和基于身份证明文件模型训练的预生成模型从护照和美国驾驶执照中提取关键信息,分析身份文档。 有关在标识文档上找到的字段,请参阅 此处

该服务不支持取消长时间运行的操作,并返回一条错误消息,指示缺少取消支持。

代码示例

String idDocumentUrl = "idDocumentUrl";
 // if training polling operation completed, retrieve the final result.
 formRecognizerAsyncClient.beginRecognizeIdentityDocumentsFromUrl(idDocumentUrl)
     .flatMap(AsyncPollResponse::getFinalResult)
     .subscribe(recognizedIDDocumentResult -> {
         for (int i = 0; i < recognizedIDDocumentResult.size(); i++) {
             RecognizedForm recognizedForm = recognizedIDDocumentResult.get(i);
             Map<String, FormField> recognizedFields = recognizedForm.getFields();
             System.out.printf("----------- Recognized license info for page %d -----------%n", i);

             FormField firstNameField = recognizedFields.get("FirstName");
             if (firstNameField != null) {
                 if (FieldValueType.STRING == firstNameField.getValue().getValueType()) {
                     String firstName = firstNameField.getValue().asString();
                     System.out.printf("First Name: %s, confidence: %.2f%n",
                         firstName, firstNameField.getConfidence());
                 }
             }

             FormField lastNameField = recognizedFields.get("LastName");
             if (lastNameField != null) {
                 if (FieldValueType.STRING == lastNameField.getValue().getValueType()) {
                     String lastName = lastNameField.getValue().asString();
                     System.out.printf("Last name: %s, confidence: %.2f%n",
                         lastName, lastNameField.getConfidence());
                 }
             }

             FormField countryRegionFormField = recognizedFields.get("CountryRegion");
             if (countryRegionFormField != null) {
                 if (FieldValueType.STRING == countryRegionFormField.getValue().getValueType()) {
                     String countryRegion = countryRegionFormField.getValue().asCountryRegion();
                     System.out.printf("Country or region: %s, confidence: %.2f%n",
                         countryRegion, countryRegionFormField.getConfidence());
                 }
             }

             FormField dateOfExpirationField = recognizedFields.get("DateOfExpiration");
             if (dateOfExpirationField != null) {
                 if (FieldValueType.DATE == dateOfExpirationField.getValue().getValueType()) {
                     LocalDate expirationDate = dateOfExpirationField.getValue().asDate();
                     System.out.printf("Document date of expiration: %s, confidence: %.2f%n",
                         expirationDate, dateOfExpirationField.getConfidence());
                 }
             }

             FormField documentNumberField = recognizedFields.get("DocumentNumber");
             if (documentNumberField != null) {
                 if (FieldValueType.STRING == documentNumberField.getValue().getValueType()) {
                     String documentNumber = documentNumberField.getValue().asString();
                     System.out.printf("Document number: %s, confidence: %.2f%n",
                         documentNumber, documentNumberField.getConfidence());
                 }
             }
         }
     });

Parameters:

identityDocumentUrl - 输入标识文档的源 URL。

Returns:

一个 PollerFlux<T,U> ,它轮询识别标识文档操作,直到它完成、失败或已取消。 完成的操作返回 的列表 RecognizedForm

beginRecognizeIdentityDocumentsFromUrl

public PollerFlux<>> beginRecognizeIdentityDocumentsFromUrl(String identityDocumentUrl, RecognizeIdentityDocumentOptions recognizeIdentityDocumentOptions)

使用光学字符识别 (OCR) 和基于身份证明文件模型训练的预生成模型从护照和美国驾驶执照中提取关键信息,分析身份文档。 有关在标识文档上找到的字段,请参阅 此处

该服务不支持取消长时间运行的操作,并返回一条错误消息,指示缺少取消支持。

代码示例

String licenseDocumentUrl = "licenseDocumentUrl";
 boolean includeFieldElements = true;
 // if training polling operation completed, retrieve the final result.
 formRecognizerAsyncClient.beginRecognizeIdentityDocumentsFromUrl(licenseDocumentUrl,
     new RecognizeIdentityDocumentOptions()
         .setFieldElementsIncluded(includeFieldElements))
     .setPollInterval(Duration.ofSeconds(5))
     .flatMap(AsyncPollResponse::getFinalResult)
     .subscribe(recognizedIDDocumentResult -> {
         for (int i = 0; i < recognizedIDDocumentResult.size(); i++) {
             RecognizedForm recognizedForm = recognizedIDDocumentResult.get(i);
             Map<String, FormField> recognizedFields = recognizedForm.getFields();
             System.out.printf("----------- Recognized license info for page %d -----------%n", i);

             FormField firstNameField = recognizedFields.get("FirstName");
             if (firstNameField != null) {
                 if (FieldValueType.STRING == firstNameField.getValue().getValueType()) {
                     String firstName = firstNameField.getValue().asString();
                     System.out.printf("First Name: %s, confidence: %.2f%n",
                         firstName, firstNameField.getConfidence());
                 }
             }

             FormField lastNameField = recognizedFields.get("LastName");
             if (lastNameField != null) {
                 if (FieldValueType.STRING == lastNameField.getValue().getValueType()) {
                     String lastName = lastNameField.getValue().asString();
                     System.out.printf("Last name: %s, confidence: %.2f%n",
                         lastName, lastNameField.getConfidence());
                 }
             }

             FormField countryRegionFormField = recognizedFields.get("CountryRegion");
             if (countryRegionFormField != null) {
                 if (FieldValueType.STRING == countryRegionFormField.getValue().getValueType()) {
                     String countryRegion = countryRegionFormField.getValue().asCountryRegion();
                     System.out.printf("Country or region: %s, confidence: %.2f%n",
                         countryRegion, countryRegionFormField.getConfidence());
                 }
             }

             FormField dateOfExpirationField = recognizedFields.get("DateOfExpiration");
             if (dateOfExpirationField != null) {
                 if (FieldValueType.DATE == dateOfExpirationField.getValue().getValueType()) {
                     LocalDate expirationDate = dateOfExpirationField.getValue().asDate();
                     System.out.printf("Document date of expiration: %s, confidence: %.2f%n",
                         expirationDate, dateOfExpirationField.getConfidence());
                 }
             }

             FormField documentNumberField = recognizedFields.get("DocumentNumber");
             if (documentNumberField != null) {
                 if (FieldValueType.STRING == documentNumberField.getValue().getValueType()) {
                     String documentNumber = documentNumberField.getValue().asString();
                     System.out.printf("Document number: %s, confidence: %.2f%n",
                         documentNumber, documentNumberField.getConfidence());
                 }
             }
         }
     });

Parameters:

identityDocumentUrl - 输入标识文档的源 URL。
recognizeIdentityDocumentOptions - 分析标识文档时可能传递的其他可配置 RecognizeIdentityDocumentOptions 项。

Returns:

一个 , PollerFlux<T,U> 它轮询分析标识文档操作,直到它完成、失败或已取消。 完成的操作返回 的列表 RecognizedForm

beginRecognizeInvoices

public PollerFlux<>> beginRecognizeInvoices(Flux invoice, long length)

使用光学字符识别 (OCR) 和预生成发票训练模型来识别发票数据。

该服务不支持取消长时间运行的操作,并返回一条错误消息,指示缺少取消支持。

有关发票上的字段,请参阅 此处 。 请注意, invoice 如果启用了重试 (默认) ,则传递的 必须可重播。 换句话说, Flux 必须在每次订阅时生成相同的数据。

代码示例

File invoice = new File("local/file_path/invoice.jpg");
 Flux<ByteBuffer> buffer =
     toFluxByteBuffer(new ByteArrayInputStream(Files.readAllBytes(invoice.toPath())));
 // if training polling operation completed, retrieve the final result.
 formRecognizerAsyncClient.beginRecognizeInvoices(buffer, invoice.length())
     .flatMap(AsyncPollResponse::getFinalResult)
     .subscribe(recognizedInvoices -> {
         for (int i = 0; i < recognizedInvoices.size(); i++) {
             RecognizedForm recognizedForm = recognizedInvoices.get(i);
             Map<String, FormField> recognizedFields = recognizedForm.getFields();
             FormField customAddrFormField = recognizedFields.get("CustomerAddress");
             if (customAddrFormField != null) {
                 if (FieldValueType.STRING == customAddrFormField.getValue().getValueType()) {
                     System.out.printf("Customer Address: %s%n", customAddrFormField.getValue().asString());
                 }
             }
             FormField invoiceDateFormField = recognizedFields.get("InvoiceDate");
             if (invoiceDateFormField != null) {
                 if (FieldValueType.DATE == invoiceDateFormField.getValue().getValueType()) {
                     LocalDate invoiceDate = invoiceDateFormField.getValue().asDate();
                     System.out.printf("Invoice Date: %s, confidence: %.2f%n",
                         invoiceDate, invoiceDateFormField.getConfidence());
                 }
             }
         }
     });

Parameters:

invoice - 要从中识别发票信息的文档的数据。
length - 数据的确切长度。

Returns:

一个 , PollerFlux<T,U> 它轮询识别发票操作,直到它已完成、失败或已取消。 完成的操作返回 的列表 RecognizedForm

beginRecognizeInvoices

public PollerFlux<>> beginRecognizeInvoices(Flux invoice, long length, RecognizeInvoicesOptions recognizeInvoicesOptions)

使用光学字符识别 (OCR) 和预生成发票训练模型从文档识别发票数据。

该服务不支持取消长时间运行的操作,并返回一条错误消息,指示缺少取消支持。

有关发票上的字段,请参阅 此处 。 请注意, invoice 如果启用了重试 (默认) ,则传递的 必须可重播。 换句话说, Flux 必须在每次订阅时生成相同的数据。

代码示例

File invoice = new File("local/file_path/invoice.jpg");
 boolean includeFieldElements = true;
 // Utility method to convert input stream to Byte buffer
 Flux<ByteBuffer> buffer =
     toFluxByteBuffer(new ByteArrayInputStream(Files.readAllBytes(invoice.toPath())));
 // if training polling operation completed, retrieve the final result.
 formRecognizerAsyncClient.beginRecognizeInvoices(buffer,
     invoice.length(),
     new RecognizeInvoicesOptions()
         .setContentType(FormContentType.IMAGE_JPEG)
         .setFieldElementsIncluded(includeFieldElements))
     .setPollInterval(Duration.ofSeconds(5))
     .flatMap(AsyncPollResponse::getFinalResult)
     .subscribe(recognizedInvoices -> {
         for (int i = 0; i < recognizedInvoices.size(); i++) {
             RecognizedForm recognizedForm = recognizedInvoices.get(i);
             Map<String, FormField> recognizedFields = recognizedForm.getFields();
             FormField customAddrFormField = recognizedFields.get("CustomerAddress");
             if (customAddrFormField != null) {
                 if (FieldValueType.STRING == customAddrFormField.getValue().getValueType()) {
                     System.out.printf("Customer Address: %s%n", customAddrFormField.getValue().asString());
                 }
             }
             FormField invoiceDateFormField = recognizedFields.get("InvoiceDate");
             if (invoiceDateFormField != null) {
                 if (FieldValueType.DATE == invoiceDateFormField.getValue().getValueType()) {
                     LocalDate invoiceDate = invoiceDateFormField.getValue().asDate();
                     System.out.printf("Invoice Date: %s, confidence: %.2f%n",
                         invoiceDate, invoiceDateFormField.getConfidence());
                 }
             }
         }
     });

Parameters:

invoice - 要从中识别发票信息的文档的数据。
length - 数据的确切长度。
recognizeInvoicesOptions - 分析发票时可能传递的其他可配置 RecognizeInvoicesOptions 项。

Returns:

一个 , PollerFlux<T,U> 它轮询识别发票操作,直到它已完成、失败或已取消。 完成的操作返回 的列表 RecognizedForm

beginRecognizeInvoicesFromUrl

public PollerFlux<>> beginRecognizeInvoicesFromUrl(String invoiceUrl)

使用光学字符识别 (OCR) 和预生成发票训练模型来识别发票数据。

该服务不支持取消长时间运行的操作,并返回一条错误消息,指示缺少取消支持。

有关发票上的字段,请参阅 此处

代码示例

String invoiceUrl = "invoice_url";
 // if training polling operation completed, retrieve the final result.
 formRecognizerAsyncClient.beginRecognizeInvoicesFromUrl(invoiceUrl)
     .flatMap(AsyncPollResponse::getFinalResult)
     .subscribe(recognizedInvoices -> {
         for (int i = 0; i < recognizedInvoices.size(); i++) {
             RecognizedForm recognizedForm = recognizedInvoices.get(i);
             Map<String, FormField> recognizedFields = recognizedForm.getFields();
             FormField customAddrFormField = recognizedFields.get("CustomerAddress");
             if (customAddrFormField != null) {
                 if (FieldValueType.STRING == customAddrFormField.getValue().getValueType()) {
                     System.out.printf("Customer Address: %s%n", customAddrFormField.getValue().asString());
                 }
             }
             FormField invoiceDateFormField = recognizedFields.get("InvoiceDate");
             if (invoiceDateFormField != null) {
                 if (FieldValueType.DATE == invoiceDateFormField.getValue().getValueType()) {
                     LocalDate invoiceDate = invoiceDateFormField.getValue().asDate();
                     System.out.printf("Invoice Date: %s, confidence: %.2f%n",
                         invoiceDate, invoiceDateFormField.getConfidence());
                 }
             }
         }
     });

Parameters:

invoiceUrl - 要分析的发票的 URL。

Returns:

一个 , PollerFlux<T,U> 它轮询识别发票操作,直到它已完成、失败或已取消。 完成的操作返回 的列表 RecognizedForm

beginRecognizeInvoicesFromUrl

public PollerFlux<>> beginRecognizeInvoicesFromUrl(String invoiceUrl, RecognizeInvoicesOptions recognizeInvoicesOptions)

使用光学字符识别 (OCR) 和预生成发票训练模型来识别发票数据。

该服务不支持取消长时间运行的操作,并返回一条错误消息,指示缺少取消支持。

代码示例

String invoiceUrl = "invoice_url";
 boolean includeFieldElements = true;
 // if training polling operation completed, retrieve the final result.
 formRecognizerAsyncClient.beginRecognizeInvoicesFromUrl(invoiceUrl,
     new RecognizeInvoicesOptions()
         .setFieldElementsIncluded(includeFieldElements))
     .setPollInterval(Duration.ofSeconds(5))
     .flatMap(AsyncPollResponse::getFinalResult)
     .subscribe(recognizedInvoices -> {
         for (int i = 0; i < recognizedInvoices.size(); i++) {
             RecognizedForm recognizedForm = recognizedInvoices.get(i);
             Map<String, FormField> recognizedFields = recognizedForm.getFields();
             FormField customAddrFormField = recognizedFields.get("CustomerAddress");
             if (customAddrFormField != null) {
                 if (FieldValueType.STRING == customAddrFormField.getValue().getValueType()) {
                     System.out.printf("Customer Address: %s%n", customAddrFormField.getValue().asString());
                 }
             }
             FormField invoiceDateFormField = recognizedFields.get("InvoiceDate");
             if (invoiceDateFormField != null) {
                 if (FieldValueType.DATE == invoiceDateFormField.getValue().getValueType()) {
                     LocalDate invoiceDate = invoiceDateFormField.getValue().asDate();
                     System.out.printf("Invoice Date: %s, confidence: %.2f%n",
                         invoiceDate, invoiceDateFormField.getConfidence());
                 }
             }
         }
     });

Parameters:

invoiceUrl - 输入发票的源 URL。
recognizeInvoicesOptions - 分析发票时可能传递的其他可配置 RecognizeInvoicesOptions 项。

Returns:

一个 , PollerFlux<T,U> 它轮询识别发票操作,直到它已完成、失败或已取消。 完成的操作返回 的列表 RecognizedForm

beginRecognizeReceipts

public PollerFlux<>> beginRecognizeReceipts(Flux receipt, long length)

使用光学字符识别 (OCR) 和预生成的收据训练模型来识别收据数据。

该服务不支持取消长时间运行的操作,并返回一条错误消息,指示缺少取消支持。

有关在收据上找到的字段,请参阅 此处 。 请注意, receipt 如果启用了重试 (默认) ,则传递的 必须可重播。 换句话说, Flux 必须在每次订阅时生成相同的数据。

代码示例

String formUrl = "{form_url}";
 String modelId = "{custom_trained_model_id}";

 // if training polling operation completed, retrieve the final result.
 formRecognizerAsyncClient.beginRecognizeCustomFormsFromUrl(modelId, formUrl)
     // if training polling operation completed, retrieve the final result.
     .flatMap(AsyncPollResponse::getFinalResult)
     .flatMap(Flux::fromIterable)
     .subscribe(recognizedForm -> recognizedForm.getFields()
         .forEach((fieldText, formField) -> {
             System.out.printf("Field text: %s%n", fieldText);
             System.out.printf("Field value data text: %s%n", formField.getValueData().getText());
             System.out.printf("Confidence score: %.2f%n", formField.getConfidence());
         }));

Parameters:

receipt - 要从中识别回执信息的文档的数据。
length - 数据的确切长度。

Returns:

PollerFlux<T,U> 询识别回执操作,直到它完成、失败或已取消。 完成的操作返回 的列表 RecognizedForm

beginRecognizeReceipts

public PollerFlux<>> beginRecognizeReceipts(Flux receipt, long length, RecognizeReceiptsOptions recognizeReceiptsOptions)

使用光学字符识别 (OCR) 和预生成收据训练模型识别文档中的回执数据。

该服务不支持取消长时间运行的操作,并返回一条错误消息,指示缺少取消支持。

有关在收据上找到的字段,请参阅 此处 。 请注意, receipt 如果启用了重试 (默认) ,则传递的 必须可重播。 换句话说, Flux 必须在每次订阅时生成相同的数据。

代码示例

String formUrl = "{form_url}";
 String modelId = "{custom_trained_model_id}";

 // if training polling operation completed, retrieve the final result.
 formRecognizerAsyncClient.beginRecognizeCustomFormsFromUrl(modelId, formUrl)
     // if training polling operation completed, retrieve the final result.
     .flatMap(AsyncPollResponse::getFinalResult)
     .flatMap(Flux::fromIterable)
     .subscribe(recognizedForm -> recognizedForm.getFields()
         .forEach((fieldText, formField) -> {
             System.out.printf("Field text: %s%n", fieldText);
             System.out.printf("Field value data text: %s%n", formField.getValueData().getText());
             System.out.printf("Confidence score: %.2f%n", formField.getConfidence());
         }));

Parameters:

receipt - 要从中识别回执信息的文档的数据。
length - 数据的确切长度。
recognizeReceiptsOptions - 分析回执时可能传递的其他可配置 RecognizeReceiptsOptions 值。

Returns:

PollerFlux<T,U> 询识别回执操作,直到它完成、失败或已取消。 完成的操作返回 的列表 RecognizedForm

beginRecognizeReceiptsFromUrl

public PollerFlux<>> beginRecognizeReceiptsFromUrl(String receiptUrl)

使用光学字符识别 (OCR) 和预生成的收据训练模型来识别收据数据。

该服务不支持取消长时间运行的操作,并返回一条错误消息,指示缺少取消支持。

有关在收据上找到的字段,请参阅 此处

代码示例

String formUrl = "{form_url}";
 String modelId = "{custom_trained_model_id}";

 // if training polling operation completed, retrieve the final result.
 formRecognizerAsyncClient.beginRecognizeCustomFormsFromUrl(modelId, formUrl)
     // if training polling operation completed, retrieve the final result.
     .flatMap(AsyncPollResponse::getFinalResult)
     .flatMap(Flux::fromIterable)
     .subscribe(recognizedForm -> recognizedForm.getFields()
         .forEach((fieldText, formField) -> {
             System.out.printf("Field text: %s%n", fieldText);
             System.out.printf("Field value data text: %s%n", formField.getValueData().getText());
             System.out.printf("Confidence score: %.2f%n", formField.getConfidence());
         }));

Parameters:

receiptUrl - 要分析的收据的 URL。

Returns:

PollerFlux<T,U> 询识别回执操作,直到它完成、失败或已取消。 完成的操作返回 的列表 RecognizedForm

beginRecognizeReceiptsFromUrl

public PollerFlux<>> beginRecognizeReceiptsFromUrl(String receiptUrl, RecognizeReceiptsOptions recognizeReceiptsOptions)

使用光学字符识别 (OCR) 和预生成的收据训练模型来识别收据数据。

该服务不支持取消长时间运行的操作,并返回一条错误消息,指示缺少取消支持。

代码示例

String formUrl = "{form_url}";
 String modelId = "{custom_trained_model_id}";

 // if training polling operation completed, retrieve the final result.
 formRecognizerAsyncClient.beginRecognizeCustomFormsFromUrl(modelId, formUrl)
     // if training polling operation completed, retrieve the final result.
     .flatMap(AsyncPollResponse::getFinalResult)
     .flatMap(Flux::fromIterable)
     .subscribe(recognizedForm -> recognizedForm.getFields()
         .forEach((fieldText, formField) -> {
             System.out.printf("Field text: %s%n", fieldText);
             System.out.printf("Field value data text: %s%n", formField.getValueData().getText());
             System.out.printf("Confidence score: %.2f%n", formField.getConfidence());
         }));

Parameters:

receiptUrl - 输入回执的源 URL。
recognizeReceiptsOptions - 分析回执时可能传递的附加可配置 RecognizeReceiptsOptions 值。

Returns:

PollerFlux<T,U> 询识别接收操作,直到它已完成、失败或已取消。 完成的操作返回 的列表 RecognizedForm

适用于