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

FormRecognizerClient 类

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

public final class FormRecognizerClient

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

此客户端提供同步方法来执行:

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

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

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

示例:使用 DefaultAzureCredential 构造 FormRecognizerClient

下面的代码示例演示如何使用“DefaultAzureCredentialBuilder”创建 FormRecognizerClient它来配置它。

FormRecognizerClient formRecognizerClient = new FormRecognizerClientBuilder()
     .endpoint("{endpoint}")
     .credential(new DefaultAzureCredentialBuilder().build())
     .buildClient();

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

FormRecognizerClient formRecognizerClient = new FormRecognizerClientBuilder()
     .credential(new AzureKeyCredential("{key}"))
     .endpoint("{endpoint}")
     .buildClient();

方法摘要

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

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

SyncPoller<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeBusinessCards(InputStream businessCard, long length, RecognizeBusinessCardsOptions recognizeBusinessCardsOptions, Context context)

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

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

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

SyncPoller<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeBusinessCardsFromUrl(String businessCardUrl, RecognizeBusinessCardsOptions recognizeBusinessCardsOptions, Context context)

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

SyncPoller<FormRecognizerOperationResult,List<FormPage>> beginRecognizeContent(InputStream form, long length)

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

SyncPoller<FormRecognizerOperationResult,List<FormPage>> beginRecognizeContent(InputStream form, long length, RecognizeContentOptions recognizeContentOptions, Context context)

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

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

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

SyncPoller<FormRecognizerOperationResult,List<FormPage>> beginRecognizeContentFromUrl(String formUrl, RecognizeContentOptions recognizeContentOptions, Context context)

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

SyncPoller<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeCustomForms(String modelId, InputStream form, long length)

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

SyncPoller<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeCustomForms(String modelId, InputStream form, long length, RecognizeCustomFormsOptions recognizeCustomFormsOptions, Context context)

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

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

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

SyncPoller<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeCustomFormsFromUrl(String modelId, String formUrl, RecognizeCustomFormsOptions recognizeCustomFormsOptions, Context context)

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

SyncPoller<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeIdentityDocuments(InputStream identityDocument, long length)

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

SyncPoller<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeIdentityDocuments(InputStream identityDocument, long length, RecognizeIdentityDocumentOptions recognizeIdentityDocumentOptions, Context context)

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

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

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

SyncPoller<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeIdentityDocumentsFromUrl(String identityDocumentUrl, RecognizeIdentityDocumentOptions recognizeIdentityDocumentOptions, Context context)

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

SyncPoller<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeInvoices(InputStream invoice, long length)

使用光学字符识别 (OCR) 和预生成的定型发票模型从提供的文档数据中识别数据。

SyncPoller<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeInvoices(InputStream invoice, long length, RecognizeInvoicesOptions recognizeInvoicesOptions, Context context)

使用光学字符识别 (OCR) 和预生成的定型发票模型从提供的文档数据中识别数据。

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

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

SyncPoller<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeInvoicesFromUrl(String invoiceUrl, RecognizeInvoicesOptions recognizeInvoicesOptions, Context context)

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

SyncPoller<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeReceipts(InputStream receipt, long length)

使用光学字符识别 (OCR) 和预生成的定型收据模型识别提供的文档数据。

SyncPoller<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeReceipts(InputStream receipt, long length, RecognizeReceiptsOptions recognizeReceiptsOptions, Context context)

使用光学字符识别 (OCR) 和预生成的定型收据模型识别提供的文档数据。

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

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

SyncPoller<FormRecognizerOperationResult,List<RecognizedForm>> beginRecognizeReceiptsFromUrl(String receiptUrl, RecognizeReceiptsOptions recognizeReceiptsOptions, Context context)

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

方法继承自 java.lang.Object

方法详细信息

beginRecognizeBusinessCards

public SyncPoller<>> beginRecognizeBusinessCards(InputStream businessCard, long length)

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

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

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

代码示例

File businessCard = new File("{local/file_path/fileName.jpg}");
 byte[] fileContent = Files.readAllBytes(businessCard.toPath());
 try (InputStream targetStream = new ByteArrayInputStream(fileContent)) {
     formRecognizerClient.beginRecognizeBusinessCards(targetStream, businessCard.length()).getFinalResult()
         .forEach(recognizedBusinessCard -> {
             Map<String, FormField> recognizedFields = recognizedBusinessCard.getFields();
             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:

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

beginRecognizeBusinessCards

public SyncPoller<>> beginRecognizeBusinessCards(InputStream businessCard, long length, RecognizeBusinessCardsOptions recognizeBusinessCardsOptions, Context context)

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

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

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

代码示例

File businessCard = new File("{local/file_path/fileName.jpg}");
 boolean includeFieldElements = true;
 byte[] fileContent = Files.readAllBytes(businessCard.toPath());
 try (InputStream targetStream = new ByteArrayInputStream(fileContent)) {
     for (RecognizedForm recognizedForm : formRecognizerClient.beginRecognizeBusinessCards(targetStream,
         businessCard.length(),
         new RecognizeBusinessCardsOptions()
             .setContentType(FormContentType.IMAGE_JPEG)
             .setFieldElementsIncluded(includeFieldElements),
         Context.NONE).setPollInterval(Duration.ofSeconds(5))
         .getFinalResult()) {
         Map<String, FormField> recognizedFields = recognizedForm.getFields();
         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
context - 在服务调用期间通过 HTTP 管道传递的其他上下文。

Returns:

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

beginRecognizeBusinessCardsFromUrl

public SyncPoller<>> beginRecognizeBusinessCardsFromUrl(String businessCardUrl)

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

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

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

代码示例

String businessCardUrl = "{business_card_url}";
 formRecognizerClient.beginRecognizeBusinessCardsFromUrl(businessCardUrl)
     .getFinalResult()
     .forEach(recognizedBusinessCard -> {
         Map<String, FormField> recognizedFields = recognizedBusinessCard.getFields();
         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。

Returns:

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

beginRecognizeBusinessCardsFromUrl

public SyncPoller<>> beginRecognizeBusinessCardsFromUrl(String businessCardUrl, RecognizeBusinessCardsOptions recognizeBusinessCardsOptions, Context context)

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

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

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

代码示例

String businessCardUrl = "{business_card_url}";
 formRecognizerClient.beginRecognizeBusinessCardsFromUrl(businessCardUrl,
     new RecognizeBusinessCardsOptions()
         .setFieldElementsIncluded(true), Context.NONE)
     .setPollInterval(Duration.ofSeconds(5)).getFinalResult()
     .forEach(recognizedBusinessCard -> {
         Map<String, FormField> recognizedFields = recognizedBusinessCard.getFields();
         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项。
context - 在服务调用期间通过 HTTP 管道传递的其他上下文。

Returns:

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

beginRecognizeContent

public SyncPoller<>> beginRecognizeContent(InputStream form, long length)

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

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

代码示例

File form = new File("{local/file_path/fileName.pdf}");
 byte[] fileContent = Files.readAllBytes(form.toPath());
 try (InputStream targetStream = new ByteArrayInputStream(fileContent)) {
     formRecognizerClient.beginRecognizeContent(targetStream, form.length())
         .getFinalResult()
         .forEach(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()
                 .stream()
                 .flatMap(formTable -> formTable.getCells().stream())
                 .forEach(recognizedTableCell -> System.out.printf("%s ", recognizedTableCell.getText()));
         });
 }

Parameters:

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

Returns:

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

beginRecognizeContent

public SyncPoller<>> beginRecognizeContent(InputStream form, long length, RecognizeContentOptions recognizeContentOptions, Context context)

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

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

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

代码示例

File form = new File("{file_source_url}");
 byte[] fileContent = Files.readAllBytes(form.toPath());
 try (InputStream targetStream = new ByteArrayInputStream(fileContent)) {

     for (FormPage formPage : formRecognizerClient.beginRecognizeContent(targetStream, form.length(),
         new RecognizeContentOptions()
             .setPollInterval(Duration.ofSeconds(5)), Context.NONE)
         .getFinalResult()) {
         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()
             .stream()
             .flatMap(formTable -> formTable.getCells().stream())
             .forEach(recognizedTableCell -> System.out.printf("%s ", recognizedTableCell.getText()));
     }
 }

Parameters:

form - 要从中识别内容信息的表单的数据。
length - 数据的确切长度。
recognizeContentOptions - 识别表单上的内容/布局时可能传递的附加可配置 RecognizeContentOptions 项。
context - 在服务调用期间通过 HTTP 管道传递的其他上下文。

Returns:

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

beginRecognizeContentFromUrl

public SyncPoller<>> beginRecognizeContentFromUrl(String formUrl)

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

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

代码示例

String formUrl = "{form_url}";
 formRecognizerClient.beginRecognizeContentFromUrl(formUrl)
     .getFinalResult()
     .forEach(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()
             .stream()
             .flatMap(formTable -> formTable.getCells().stream())
             .forEach(recognizedTableCell -> System.out.printf("%s ", recognizedTableCell.getText()));
     });

Parameters:

formUrl - 要分析的表单的 URL。

Returns:

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

beginRecognizeContentFromUrl

public SyncPoller<>> beginRecognizeContentFromUrl(String formUrl, RecognizeContentOptions recognizeContentOptions, Context context)

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

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

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

代码示例

String formPath = "{file_source_url}";
 formRecognizerClient.beginRecognizeContentFromUrl(formPath,
     new RecognizeContentOptions()
         .setPollInterval(Duration.ofSeconds(5)), Context.NONE)
     .getFinalResult()
     .forEach(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()
             .stream()
             .flatMap(formTable -> formTable.getCells().stream())
             .forEach(recognizedTableCell -> System.out.printf("%s ", recognizedTableCell.getText()));
     });

Parameters:

formUrl - 输入窗体的源 URL。
recognizeContentOptions - 识别表单上的内容/布局时可能传递的附加可配置 RecognizeContentOptions 项。
context - 在服务调用期间通过 HTTP 管道传递的其他上下文。

Returns:

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

beginRecognizeCustomForms

public SyncPoller<>> beginRecognizeCustomForms(String modelId, InputStream form, long length)

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

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

代码示例

File form = new File("{local/file_path/fileName.jpg}");
 String modelId = "{custom_trained_model_id}";
 byte[] fileContent = Files.readAllBytes(form.toPath());
 try (InputStream targetStream = new ByteArrayInputStream(fileContent)) {

     formRecognizerClient.beginRecognizeCustomForms(modelId, targetStream, form.length())
         .getFinalResult()
         .stream()
         .map(RecognizedForm::getFields)
         .forEach(formFieldMap -> formFieldMap.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:

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

beginRecognizeCustomForms

public SyncPoller<>> beginRecognizeCustomForms(String modelId, InputStream form, long length, RecognizeCustomFormsOptions recognizeCustomFormsOptions, Context context)

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

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

代码示例

File form = new File("{local/file_path/fileName.jpg}");
 String modelId = "{custom_trained_model_id}";
 boolean includeFieldElements = true;
 byte[] fileContent = Files.readAllBytes(form.toPath());

 try (InputStream targetStream = new ByteArrayInputStream(fileContent)) {
     formRecognizerClient.beginRecognizeCustomForms(modelId, targetStream, form.length(),
         new RecognizeCustomFormsOptions()
             .setContentType(FormContentType.IMAGE_JPEG)
             .setFieldElementsIncluded(includeFieldElements)
             .setPollInterval(Duration.ofSeconds(10)), Context.NONE)
         .getFinalResult()
         .stream()
         .map(RecognizedForm::getFields)
         .forEach(formFieldMap -> formFieldMap.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 - 数据的确切长度。
recognizeCustomFormsOptions - 识别自定义窗体时可能传递的附加可配置 RecognizeCustomFormsOptions 项。
context - 在服务调用期间通过 HTTP 管道传递的其他上下文。

Returns:

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

beginRecognizeCustomFormsFromUrl

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

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

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

代码示例

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

 formRecognizerClient.beginRecognizeCustomFormsFromUrl(modelId, formUrl).getFinalResult()
     .stream()
     .map(RecognizedForm::getFields)
     .forEach(formFieldMap -> formFieldMap.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:

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

beginRecognizeCustomFormsFromUrl

public SyncPoller<>> beginRecognizeCustomFormsFromUrl(String modelId, String formUrl, RecognizeCustomFormsOptions recognizeCustomFormsOptions, Context context)

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

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

代码示例

String analyzeFilePath = "{file_source_url}";
 String modelId = "{model_id}";
 boolean includeFieldElements = true;

 formRecognizerClient.beginRecognizeCustomFormsFromUrl(modelId, analyzeFilePath,
     new RecognizeCustomFormsOptions()
         .setFieldElementsIncluded(includeFieldElements)
         .setPollInterval(Duration.ofSeconds(10)), Context.NONE)
     .getFinalResult()
     .stream()
     .map(RecognizedForm::getFields)
     .forEach(formFieldMap -> formFieldMap.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 项。
context - 在服务调用期间通过 HTTP 管道传递的其他上下文。

Returns:

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

beginRecognizeIdentityDocuments

public SyncPoller<>> beginRecognizeIdentityDocuments(InputStream identityDocument, long length)

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

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

代码示例

File license = new File("local/file_path/license.jpg");
 ByteArrayInputStream inputStream = new ByteArrayInputStream(Files.readAllBytes(license.toPath()));
 // if training polling operation completed, retrieve the final result.
 formRecognizerClient.beginRecognizeIdentityDocuments(inputStream, license.length())
     .getFinalResult()
     .stream()
     .map(RecognizedForm::getFields)
     .forEach(recognizedFields -> {
         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:

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

beginRecognizeIdentityDocuments

public SyncPoller<>> beginRecognizeIdentityDocuments(InputStream identityDocument, long length, RecognizeIdentityDocumentOptions recognizeIdentityDocumentOptions, Context context)

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

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

代码示例

File licenseDocument = new File("local/file_path/license.jpg");
 boolean includeFieldElements = true;
 // Utility method to convert input stream to Byte buffer
 ByteArrayInputStream inputStream = new ByteArrayInputStream(Files.readAllBytes(licenseDocument.toPath()));
 // if training polling operation completed, retrieve the final result.
 formRecognizerClient.beginRecognizeIdentityDocuments(inputStream,
     licenseDocument.length(),
     new RecognizeIdentityDocumentOptions()
         .setContentType(FormContentType.IMAGE_JPEG)
         .setFieldElementsIncluded(includeFieldElements),
     Context.NONE)
     .setPollInterval(Duration.ofSeconds(5))
     .getFinalResult()
     .stream()
     .map(RecognizedForm::getFields)
     .forEach(recognizedFields -> {
         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 dateOfBirthField = recognizedFields.get("DateOfBirth");
         if (dateOfBirthField != null) {
             if (FieldValueType.DATE == dateOfBirthField.getValue().getValueType()) {
                 LocalDate dateOfBirth = dateOfBirthField.getValue().asDate();
                 System.out.printf("Date of Birth: %s, confidence: %.2f%n",
                     dateOfBirth, dateOfBirthField.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 项。
context - 在服务调用期间通过 HTTP 管道传递的其他上下文。

Returns:

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

beginRecognizeIdentityDocumentsFromUrl

public SyncPoller<>> beginRecognizeIdentityDocumentsFromUrl(String identityDocumentUrl)

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

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

代码示例

String licenseDocumentUrl = "licenseDocumentUrl";
 // if training polling operation completed, retrieve the final result.
 formRecognizerClient.beginRecognizeIdentityDocumentsFromUrl(licenseDocumentUrl)
     .getFinalResult()
     .stream()
     .map(RecognizedForm::getFields)
     .forEach(recognizedFields -> {
         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 dateOfBirthField = recognizedFields.get("DateOfBirth");
         if (dateOfBirthField != null) {
             if (FieldValueType.DATE == dateOfBirthField.getValue().getValueType()) {
                 LocalDate dateOfBirth = dateOfBirthField.getValue().asDate();
                 System.out.printf("Date of Birth: %s, confidence: %.2f%n",
                     dateOfBirth, dateOfBirthField.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:

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

beginRecognizeIdentityDocumentsFromUrl

public SyncPoller<>> beginRecognizeIdentityDocumentsFromUrl(String identityDocumentUrl, RecognizeIdentityDocumentOptions recognizeIdentityDocumentOptions, Context context)

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

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

代码示例

String licenseDocumentUrl = "licenseDocumentUrl";
 boolean includeFieldElements = true;
 // if training polling operation completed, retrieve the final result.
 formRecognizerClient.beginRecognizeIdentityDocumentsFromUrl(licenseDocumentUrl,
     new RecognizeIdentityDocumentOptions()
         .setFieldElementsIncluded(includeFieldElements),
     Context.NONE).setPollInterval(Duration.ofSeconds(5))
     .getFinalResult()
     .stream()
     .map(RecognizedForm::getFields)
     .forEach(recognizedFields -> {
         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 值。
context - 在服务调用期间通过 HTTP 管道传递的其他上下文。

Returns:

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

beginRecognizeInvoices

public SyncPoller<>> beginRecognizeInvoices(InputStream invoice, long length)

使用光学字符识别 (OCR) 和预生成的定型发票模型从提供的文档数据中识别数据。

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

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

代码示例

File invoice = new File("local/file_path/invoice.jpg");
 ByteArrayInputStream inputStream = new ByteArrayInputStream(Files.readAllBytes(invoice.toPath()));
 // if training polling operation completed, retrieve the final result.
 formRecognizerClient.beginRecognizeInvoices(inputStream, invoice.length())
     .getFinalResult()
     .stream()
     .map(RecognizedForm::getFields)
     .forEach(recognizedFields -> {
         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:

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

beginRecognizeInvoices

public SyncPoller<>> beginRecognizeInvoices(InputStream invoice, long length, RecognizeInvoicesOptions recognizeInvoicesOptions, Context context)

使用光学字符识别 (OCR) 和预生成的定型发票模型从提供的文档数据中识别数据。

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

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

代码示例

File invoice = new File("local/file_path/invoice.jpg");
 boolean includeFieldElements = true;
 // Utility method to convert input stream to Byte buffer
 ByteArrayInputStream inputStream = new ByteArrayInputStream(Files.readAllBytes(invoice.toPath()));
 // if training polling operation completed, retrieve the final result.
 formRecognizerClient.beginRecognizeInvoices(inputStream,
     invoice.length(),
     new RecognizeInvoicesOptions()
         .setContentType(FormContentType.IMAGE_JPEG)
         .setFieldElementsIncluded(includeFieldElements),
     Context.NONE)
     .setPollInterval(Duration.ofSeconds(5))
     .getFinalResult()
     .stream()
     .map(RecognizedForm::getFields)
     .forEach(recognizedFields -> {
         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
context - 在服务调用期间通过 HTTP 管道传递的其他上下文。

Returns:

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

beginRecognizeInvoicesFromUrl

public SyncPoller<>> beginRecognizeInvoicesFromUrl(String invoiceUrl)

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

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

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

代码示例

String invoiceUrl = "invoice_url";
 // if training polling operation completed, retrieve the final result.
 formRecognizerClient.beginRecognizeInvoicesFromUrl(invoiceUrl)
     .getFinalResult()
     .stream()
     .map(RecognizedForm::getFields)
     .forEach(recognizedFields -> {
         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:

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

beginRecognizeInvoicesFromUrl

public SyncPoller<>> beginRecognizeInvoicesFromUrl(String invoiceUrl, RecognizeInvoicesOptions recognizeInvoicesOptions, Context context)

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

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

代码示例

String invoiceUrl = "invoice_url";
 boolean includeFieldElements = true;
 // if training polling operation completed, retrieve the final result.
 formRecognizerClient.beginRecognizeInvoicesFromUrl(invoiceUrl,
     new RecognizeInvoicesOptions()
         .setFieldElementsIncluded(includeFieldElements),
     Context.NONE).setPollInterval(Duration.ofSeconds(5))
     .getFinalResult()
     .stream()
     .map(RecognizedForm::getFields)
     .forEach(recognizedFields -> {
         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
context - 在服务调用期间通过 HTTP 管道传递的其他上下文。

Returns:

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

beginRecognizeReceipts

public SyncPoller<>> beginRecognizeReceipts(InputStream receipt, long length)

使用光学字符识别 (OCR) 和预生成的定型收据模型识别提供的文档数据。

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

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

代码示例

File receipt = new File("{receipt_url}");
 byte[] fileContent = Files.readAllBytes(receipt.toPath());
 try (InputStream targetStream = new ByteArrayInputStream(fileContent)) {

     formRecognizerClient.beginRecognizeReceipts(targetStream, receipt.length()).getFinalResult()
         .forEach(recognizedReceipt -> {
             Map<String, FormField> recognizedFields = recognizedReceipt.getFields();
             FormField merchantNameField = recognizedFields.get("MerchantName");
             if (merchantNameField != null) {
                 if (FieldValueType.STRING == merchantNameField.getValue().getValueType()) {
                     String merchantName = merchantNameField.getValue().asString();
                     System.out.printf("Merchant Name: %s, confidence: %.2f%n",
                         merchantName, merchantNameField.getConfidence());
                 }
             }

             FormField merchantPhoneNumberField = recognizedFields.get("MerchantPhoneNumber");
             if (merchantPhoneNumberField != null) {
                 if (FieldValueType.PHONE_NUMBER == merchantPhoneNumberField.getValue().getValueType()) {
                     String merchantAddress = merchantPhoneNumberField.getValue().asPhoneNumber();
                     System.out.printf("Merchant Phone number: %s, confidence: %.2f%n",
                         merchantAddress, merchantPhoneNumberField.getConfidence());
                 }
             }

             FormField transactionDateField = recognizedFields.get("TransactionDate");
             if (transactionDateField != null) {
                 if (FieldValueType.DATE == transactionDateField.getValue().getValueType()) {
                     LocalDate transactionDate = transactionDateField.getValue().asDate();
                     System.out.printf("Transaction Date: %s, confidence: %.2f%n",
                         transactionDate, transactionDateField.getConfidence());
                 }
             }

             FormField receiptItemsField = recognizedFields.get("Items");
             if (receiptItemsField != null) {
                 System.out.printf("Receipt Items: %n");
                 if (FieldValueType.LIST == receiptItemsField.getValue().getValueType()) {
                     List<FormField> receiptItems = receiptItemsField.getValue().asList();
                     receiptItems.stream()
                         .filter(receiptItem -> FieldValueType.MAP == receiptItem.getValue().getValueType())
                         .map(formField -> formField.getValue().asMap())
                         .forEach(formFieldMap -> formFieldMap.forEach((key, formField) -> {
                             if ("Quantity".equals(key)) {
                                 if (FieldValueType.FLOAT == formField.getValue().getValueType()) {
                                     Float quantity = formField.getValue().asFloat();
                                     System.out.printf("Quantity: %f, confidence: %.2f%n",
                                         quantity, formField.getConfidence());
                                 }
                             }
                         }));
                 }
             }
         });
 }

Parameters:

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

Returns:

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

beginRecognizeReceipts

public SyncPoller<>> beginRecognizeReceipts(InputStream receipt, long length, RecognizeReceiptsOptions recognizeReceiptsOptions, Context context)

使用光学字符识别 (OCR) 和预生成的定型收据模型识别提供的文档数据。

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

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

代码示例

File receipt = new File("{local/file_path/fileName.jpg}");
 boolean includeFieldElements = true;
 byte[] fileContent = Files.readAllBytes(receipt.toPath());
 try (InputStream targetStream = new ByteArrayInputStream(fileContent)) {
     for (RecognizedForm recognizedForm : formRecognizerClient
         .beginRecognizeReceipts(targetStream, receipt.length(),
             new RecognizeReceiptsOptions()
                 .setContentType(FormContentType.IMAGE_JPEG)
                 .setFieldElementsIncluded(includeFieldElements)
                 .setLocale(FormRecognizerLocale.EN_US)
                 .setPollInterval(Duration.ofSeconds(5)), Context.NONE)
         .getFinalResult()) {
         Map<String, FormField> recognizedFields = recognizedForm.getFields();
         FormField merchantNameField = recognizedFields.get("MerchantName");
         if (merchantNameField != null) {
             if (FieldValueType.STRING == merchantNameField.getValue().getValueType()) {
                 String merchantName = merchantNameField.getValue().asString();
                 System.out.printf("Merchant Name: %s, confidence: %.2f%n",
                     merchantName, merchantNameField.getConfidence());
             }
         }
         FormField merchantPhoneNumberField = recognizedFields.get("MerchantPhoneNumber");
         if (merchantPhoneNumberField != null) {
             if (FieldValueType.PHONE_NUMBER == merchantPhoneNumberField.getValue().getValueType()) {
                 String merchantAddress = merchantPhoneNumberField.getValue().asPhoneNumber();
                 System.out.printf("Merchant Phone number: %s, confidence: %.2f%n",
                     merchantAddress, merchantPhoneNumberField.getConfidence());
             }
         }
         FormField transactionDateField = recognizedFields.get("TransactionDate");
         if (transactionDateField != null) {
             if (FieldValueType.DATE == transactionDateField.getValue().getValueType()) {
                 LocalDate transactionDate = transactionDateField.getValue().asDate();
                 System.out.printf("Transaction Date: %s, confidence: %.2f%n",
                     transactionDate, transactionDateField.getConfidence());
             }
         }
         FormField receiptItemsField = recognizedFields.get("Items");
         if (receiptItemsField != null) {
             System.out.printf("Receipt Items: %n");
             if (FieldValueType.LIST == receiptItemsField.getValue().getValueType()) {
                 List<FormField> receiptItems = receiptItemsField.getValue().asList();
                 receiptItems.stream()
                     .filter(receiptItem -> FieldValueType.MAP == receiptItem.getValue().getValueType())
                     .map(formField -> formField.getValue().asMap())
                     .forEach(formFieldMap -> formFieldMap.forEach((key, formField) -> {
                         if ("Quantity".equals(key)) {
                             if (FieldValueType.FLOAT == formField.getValue().getValueType()) {
                                 Float quantity = formField.getValue().asFloat();
                                 System.out.printf("Quantity: %f, confidence: %.2f%n",
                                     quantity, formField.getConfidence());
                             }
                         }
                     }));
             }
         }
     }
 }

Parameters:

receipt - 要从中识别回执信息的收据数据。
length - 数据的确切长度。
recognizeReceiptsOptions - 分析回执时可能传递的附加可配置 RecognizeReceiptsOptions 值。
context - 在服务调用期间通过 HTTP 管道传递的其他上下文。

Returns:

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

beginRecognizeReceiptsFromUrl

public SyncPoller<>> beginRecognizeReceiptsFromUrl(String receiptUrl)

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

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

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

代码示例

String receiptUrl = "{file_source_url}";
 formRecognizerClient.beginRecognizeReceiptsFromUrl(receiptUrl)
     .getFinalResult()
     .forEach(recognizedReceipt -> {
         Map<String, FormField> recognizedFields = recognizedReceipt.getFields();
         FormField merchantNameField = recognizedFields.get("MerchantName");
         if (merchantNameField != null) {
             if (FieldValueType.STRING == merchantNameField.getValue().getValueType()) {
                 String merchantName = merchantNameField.getValue().asString();
                 System.out.printf("Merchant Name: %s, confidence: %.2f%n",
                     merchantName, merchantNameField.getConfidence());
             }
         }

         FormField merchantPhoneNumberField = recognizedFields.get("MerchantPhoneNumber");
         if (merchantPhoneNumberField != null) {
             if (FieldValueType.PHONE_NUMBER == merchantPhoneNumberField.getValue().getValueType()) {
                 String merchantAddress = merchantPhoneNumberField.getValue().asPhoneNumber();
                 System.out.printf("Merchant Phone number: %s, confidence: %.2f%n",
                     merchantAddress, merchantPhoneNumberField.getConfidence());
             }
         }

         FormField transactionDateField = recognizedFields.get("TransactionDate");
         if (transactionDateField != null) {
             if (FieldValueType.DATE == transactionDateField.getValue().getValueType()) {
                 LocalDate transactionDate = transactionDateField.getValue().asDate();
                 System.out.printf("Transaction Date: %s, confidence: %.2f%n",
                     transactionDate, transactionDateField.getConfidence());
             }
         }

         FormField receiptItemsField = recognizedFields.get("Items");
         if (receiptItemsField != null) {
             System.out.printf("Receipt Items: %n");
             if (FieldValueType.LIST == receiptItemsField.getValue().getValueType()) {
                 List<FormField> receiptItems = receiptItemsField.getValue().asList();
                 receiptItems.stream()
                     .filter(receiptItem -> FieldValueType.MAP == receiptItem.getValue().getValueType())
                     .map(formField -> formField.getValue().asMap())
                     .forEach(formFieldMap -> formFieldMap.forEach((key, formField) -> {
                         if ("Quantity".equals(key)) {
                             if (FieldValueType.FLOAT == formField.getValue().getValueType()) {
                                 Float quantity = formField.getValue().asFloat();
                                 System.out.printf("Quantity: %f, confidence: %.2f%n",
                                     quantity, formField.getConfidence());
                             }
                         }
                     }));
             }
         }
     });

Parameters:

receiptUrl - 要分析的收据的 URL。

Returns:

一个 SyncPoller<T,U> ,用于轮询识别接收操作的进度,直到它已完成、失败或已取消。 完成的操作返回 的列表 RecognizedForm

beginRecognizeReceiptsFromUrl

public SyncPoller<>> beginRecognizeReceiptsFromUrl(String receiptUrl, RecognizeReceiptsOptions recognizeReceiptsOptions, Context context)

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

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

代码示例

String receiptUrl = "{receipt_url}";
 formRecognizerClient.beginRecognizeReceiptsFromUrl(receiptUrl,
     new RecognizeReceiptsOptions()
         .setLocale(FormRecognizerLocale.EN_US)
         .setPollInterval(Duration.ofSeconds(5))
         .setFieldElementsIncluded(true), Context.NONE)
     .getFinalResult()
     .forEach(recognizedReceipt -> {
         Map<String, FormField> recognizedFields = recognizedReceipt.getFields();
         FormField merchantNameField = recognizedFields.get("MerchantName");
         if (merchantNameField != null) {
             if (FieldValueType.STRING == merchantNameField.getValue().getValueType()) {
                 String merchantName = merchantNameField.getValue().asString();
                 System.out.printf("Merchant Name: %s, confidence: %.2f%n",
                     merchantName, merchantNameField.getConfidence());
             }
         }

         FormField merchantPhoneNumberField = recognizedFields.get("MerchantPhoneNumber");
         if (merchantPhoneNumberField != null) {
             if (FieldValueType.PHONE_NUMBER == merchantPhoneNumberField.getValue().getValueType()) {
                 String merchantAddress = merchantPhoneNumberField.getValue().asPhoneNumber();
                 System.out.printf("Merchant Phone number: %s, confidence: %.2f%n",
                     merchantAddress, merchantPhoneNumberField.getConfidence());
             }
         }

         FormField transactionDateField = recognizedFields.get("TransactionDate");
         if (transactionDateField != null) {
             if (FieldValueType.DATE == transactionDateField.getValue().getValueType()) {
                 LocalDate transactionDate = transactionDateField.getValue().asDate();
                 System.out.printf("Transaction Date: %s, confidence: %.2f%n",
                     transactionDate, transactionDateField.getConfidence());
             }
         }

         FormField receiptItemsField = recognizedFields.get("Items");
         if (receiptItemsField != null) {
             System.out.printf("Receipt Items: %n");
             if (FieldValueType.LIST == receiptItemsField.getValue().getValueType()) {
                 List<FormField> receiptItems = receiptItemsField.getValue().asList();
                 receiptItems.stream()
                     .filter(receiptItem -> FieldValueType.MAP == receiptItem.getValue().getValueType())
                     .map(formField -> formField.getValue().asMap())
                     .forEach(formFieldMap -> formFieldMap.forEach((key, formField) -> {
                         if ("Quantity".equals(key)) {
                             if (FieldValueType.FLOAT == formField.getValue().getValueType()) {
                                 Float quantity = formField.getValue().asFloat();
                                 System.out.printf("Quantity: %f, confidence: %.2f%n",
                                     quantity, formField.getConfidence());
                             }
                         }
                     }));
             }
         }
     });

Parameters:

receiptUrl - 输入回执的源 URL。
recognizeReceiptsOptions - 分析回执时可能传递的附加可配置 RecognizeReceiptsOptions 值。
context - 在服务调用期间通过 HTTP 管道传递的其他上下文。

Returns:

一个 SyncPoller<T,U> ,用于轮询识别接收操作的进度,直到它已完成、失败或已取消。 完成的操作返回 的列表 RecognizedForm

适用于