16 строки
14 KiB
YAML
16 строки
14 KiB
YAML
### YamlMime:JavaPackage
|
|
uid: "com.azure.ai.formrecognizer"
|
|
fullName: "com.azure.ai.formrecognizer"
|
|
name: "com.azure.ai.formrecognizer"
|
|
summary: "[Azure Form Recognizer][] is a cloud-based service provided by Microsoft Azure that utilizes machine learning to extract information from various types of forms.\n\n\n[Azure Form Recognizer]: https://aka.ms/form-recognizer-3.0.0"
|
|
classes:
|
|
- "com.azure.ai.formrecognizer.FormRecognizerAsyncClient"
|
|
- "com.azure.ai.formrecognizer.FormRecognizerClient"
|
|
- "com.azure.ai.formrecognizer.FormRecognizerClientBuilder"
|
|
enums:
|
|
- "com.azure.ai.formrecognizer.FormRecognizerServiceVersion"
|
|
desc: "[Azure Form Recognizer][] is a cloud-based service provided by Microsoft Azure that utilizes machine learning to extract information from various types of forms. It is designed to automate the process of form recognition, data extraction, and form understanding. Azure Form Recognizer can handle structured forms, such as invoices, receipts, and surveys, as well as unstructured form data, such as contracts, agreements, and financial reports.\n\nThe service uses advanced optical character recognition (OCR) technology to extract text and key-value pairs from custom forms, enabling organizations to automate data entry tasks that would otherwise require manual effort. It can recognize and extract information like dates, addresses, invoice numbers, line items, and other relevant data points from forms.\n\nThe Azure Form Recognizer client library allows Java developers to interact with the Azure Form Recognizer service. It provides a set of classes and methods that abstract the underlying RESTful API of Azure Form Recognizer, making it easier to integrate the service into Java applications.\n\nThe Azure Form Recognizer client library provides the following capabilities:\n\n1. Form recognizing: It allows you to submit forms to extract information like text, key-value pairs, tables, and form fields. You can analyze both structured and unstructured documents.\n2. Model Management: It enables you to train custom models by providing labeled training data. You can also list and delete existing models.\n3. Recognize Results: It provides methods to retrieve and interpret analysis results, including extracted text and field values, confidence scores, and form layout information.\n4. Polling and Callbacks: It includes mechanisms for polling the service to check the status of an analysis operation or registering callbacks to receive notifications when the analysis is complete.\n\n## Getting Started ##\n\nThe Azure Form Recognizer library provides analysis clients like <xref uid=\"com.azure.ai.formrecognizer.FormRecognizerAsyncClient\" data-throw-if-not-resolved=\"false\" data-raw-source=\"com.azure.ai.formrecognizer.FormRecognizerAsyncClient\"></xref> and <xref uid=\"com.azure.ai.formrecognizer.FormRecognizerClient\" data-throw-if-not-resolved=\"false\" data-raw-source=\"com.azure.ai.formrecognizer.FormRecognizerClient\"></xref> to connect to the Form Recognizer Azure Cognitive Service to analyze information from forms and extract it into structured data. It also provides training clients like <xref uid=\"com.azure.ai.formrecognizer.training.FormTrainingClient\" data-throw-if-not-resolved=\"false\" data-raw-source=\"com.azure.ai.formrecognizer.training.FormTrainingClient\"></xref> and <xref uid=\"com.azure.ai.formrecognizer.training.FormTrainingAsyncClient\" data-throw-if-not-resolved=\"false\" data-raw-source=\"com.azure.ai.formrecognizer.training.FormTrainingAsyncClient\"></xref> to build and manage models from custom forms.\n\n**Note:**This client only supports <xref uid=\"com.azure.ai.formrecognizer.FormRecognizerServiceVersion.V2_1\" data-throw-if-not-resolved=\"false\" data-raw-source=\"com.azure.ai.formrecognizer.FormRecognizerServiceVersion#V2_1\"></xref> and lower. Recommended to use a newer service version, <xref uid=\"com.azure.ai.formrecognizer.documentanalysis.DocumentAnalysisClient\" data-throw-if-not-resolved=\"false\" data-raw-source=\"com.azure.ai.formrecognizer.documentanalysis.DocumentAnalysisClient\"></xref> and <xref uid=\"com.azure.ai.formrecognizer.documentanalysis.administration.DocumentModelAdministrationClient\" data-throw-if-not-resolved=\"false\" data-raw-source=\"com.azure.ai.formrecognizer.documentanalysis.administration.DocumentModelAdministrationClient\"></xref>.\n\n**Refer to the [Migration guide][] to use API versions 2022-08-31 and up.**\n\nService clients are the point of interaction for developers to use Azure Form Recognizer. <xref uid=\"com.azure.ai.formrecognizer.FormRecognizerClient\" data-throw-if-not-resolved=\"false\" data-raw-source=\"com.azure.ai.formrecognizer.FormRecognizerClient\"></xref> is the synchronous service client and <xref uid=\"com.azure.ai.formrecognizer.FormRecognizerAsyncClient\" data-throw-if-not-resolved=\"false\" data-raw-source=\"com.azure.ai.formrecognizer.FormRecognizerAsyncClient\"></xref> is the asynchronous service client. The examples shown in this document use a credential object named DefaultAzureCredential for authentication, which is appropriate for most scenarios, including local development and production environments. Additionally, we recommend using [managed identity][] for authentication in production environments. You can find more information on different ways of authenticating and their corresponding credential types in the [Azure Identity documentation\"][Azure Identity documentation].\n\n**Sample: Construct a FormRecognizerClient with DefaultAzureCredential**\n\nThe following code sample demonstrates the creation of a <xref uid=\"com.azure.ai.formrecognizer.FormRecognizerClient\" data-throw-if-not-resolved=\"false\" data-raw-source=\"com.azure.ai.formrecognizer.FormRecognizerClient\"></xref>, using the \\`DefaultAzureCredentialBuilder\\` to configure it.\n\n```java\nFormRecognizerClient formRecognizerClient = new FormRecognizerClientBuilder()\n .endpoint(\"{endpoint}\")\n .credential(new DefaultAzureCredentialBuilder().build())\n .buildClient();\n```\n\nFurther, see the code sample below to use <xref uid=\"com.azure.core.credential.AzureKeyCredential\" data-throw-if-not-resolved=\"false\" data-raw-source=\"AzureKeyCredential\"></xref> for client creation.\n\n```java\nFormRecognizerClient formRecognizerClient = new FormRecognizerClientBuilder()\n .credential(new AzureKeyCredential(\"{key}\"))\n .endpoint(\"{endpoint}\")\n .buildClient();\n```\n\nLet's take a look at the analysis client scenarios and their respective usage below.\n\n\n--------------------\n\n## Analyzing forms with prebuilt models ##\n\n[Form Recognizer models][] and their associated output to help you choose the best model to address your document scenario needs.\n\nYou can use domain specific models or train a custom model tailored to your specific business needs and use cases.\n\n**Sample: Recognize data from receipts using a url source**\n\nThe following code sample demonstrates how to detect and extract data from receipts using optical character recognition (OCR).\n\n```java\nString receiptUrl = \"https://raw.githubusercontent.com/Azure/azure-sdk-for-java/main/sdk/formrecognizer\"\n + \"/azure-ai-formrecognizer/src/samples/resources/sample-forms/receipts/contoso-allinone.jpg\";\n SyncPoller<FormRecognizerOperationResult, List<RecognizedForm>> syncPoller =\n formRecognizerClient.beginRecognizeReceiptsFromUrl(receiptUrl);\n List<RecognizedForm> receiptPageResults = syncPoller.getFinalResult();\n\n for (int i = 0; i < receiptPageResults.size(); i++) {\n RecognizedForm recognizedForm = receiptPageResults.get(i);\n Map<String, FormField> recognizedFields = recognizedForm.getFields();\n System.out.printf(\"----------- Recognizing receipt info for page %d -----------%n\", i);\n FormField merchantNameField = recognizedFields.get(\"MerchantName\");\n if (merchantNameField != null) {\n if (FieldValueType.STRING == merchantNameField.getValue().getValueType()) {\n String merchantName = merchantNameField.getValue().asString();\n System.out.printf(\"Merchant Name: %s, confidence: %.2f%n\",\n merchantName, merchantNameField.getConfidence());\n }\n }\n\n FormField merchantPhoneNumberField = recognizedFields.get(\"MerchantPhoneNumber\");\n if (merchantPhoneNumberField != null) {\n if (FieldValueType.PHONE_NUMBER == merchantPhoneNumberField.getValue().getValueType()) {\n String merchantAddress = merchantPhoneNumberField.getValue().asPhoneNumber();\n System.out.printf(\"Merchant Phone number: %s, confidence: %.2f%n\",\n merchantAddress, merchantPhoneNumberField.getConfidence());\n }\n }\n\n FormField transactionDateField = recognizedFields.get(\"TransactionDate\");\n if (transactionDateField != null) {\n if (FieldValueType.DATE == transactionDateField.getValue().getValueType()) {\n LocalDate transactionDate = transactionDateField.getValue().asDate();\n System.out.printf(\"Transaction Date: %s, confidence: %.2f%n\",\n transactionDate, transactionDateField.getConfidence());\n }\n }\n\n FormField receiptItemsField = recognizedFields.get(\"Items\");\n if (receiptItemsField != null) {\n System.out.printf(\"Receipt Items: %n\");\n if (FieldValueType.LIST == receiptItemsField.getValue().getValueType()) {\n List<FormField> receiptItems = receiptItemsField.getValue().asList();\n receiptItems.stream()\n .filter(receiptItem -> FieldValueType.MAP == receiptItem.getValue().getValueType())\n .map(formField -> formField.getValue().asMap())\n .forEach(formFieldMap -> formFieldMap.forEach((key, formField) -> {\n if (\"Quantity\".equals(key)) {\n if (FieldValueType.FLOAT == formField.getValue().getValueType()) {\n Float quantity = formField.getValue().asFloat();\n System.out.printf(\"Quantity: %f, confidence: %.2f%n\",\n quantity, formField.getConfidence());\n }\n }\n }));\n }\n }\n }\n```\n\nYou can also extract data from a local receipt with prebuilt models using the <xref uid=\"com.azure.ai.formrecognizer.FormRecognizerClient.beginRecognizeReceipts(java.io.InputStream,long,com.azure.ai.formrecognizer.models.RecognizeReceiptsOptions,com.azure.core.util.Context)\" data-throw-if-not-resolved=\"false\" data-raw-source=\"beginRecognizeReceipts\"></xref> method.\n\nFor more information on which supported model you should use refer to [models usage documentation][].\n\n\n--------------------\n\n## Analyze a custom form with a model trained with or without labels. ##\n\nAnalyze a custom form with a model trained with or without labels. Custom models are trained with your own data, so they're tailored to your documents.\n\nFor more information, see [train a model with labels][].\n\n**Sample: Analyze a custom form with a model trained with labels**\n\nThis sample demonstrates how to recognize form fields and other content from your custom forms, using models you trained with your own form types.\n\n```java\nString trainingFilesUrl = \"{SAS_URL_of_your_container_in_blob_storage}\";\n boolean useTrainingLabels = true;\n\n SyncPoller<FormRecognizerOperationResult, CustomFormModel> trainingPoller =\n formTrainingClient.beginTraining(trainingFilesUrl,\n useTrainingLabels,\n new TrainingOptions()\n .setModelName(\"my model trained with labels\"),\n Context.NONE);\n\n CustomFormModel customFormModel = trainingPoller.getFinalResult();\n\n // Model Info\n System.out.printf(\"Model Id: %s%n\", customFormModel.getModelId());\n\n String customFormUrl = \"customFormUrl\";\n String modelId = customFormModel.getModelId();\n SyncPoller<FormRecognizerOperationResult, List<RecognizedForm>> recognizeFormPoller =\n formRecognizerClient.beginRecognizeCustomFormsFromUrl(modelId, customFormUrl);\n\n List<RecognizedForm> recognizedForms = recognizeFormPoller.getFinalResult();\n\n for (int i = 0; i < recognizedForms.size(); i++) {\n RecognizedForm form = recognizedForms.get(i);\n System.out.printf(\"----------- Recognized custom form info for page %d -----------%n\", i);\n System.out.printf(\"Form type: %s%n\", form.getFormType());\n System.out.printf(\"Form type confidence: %.2f%n\", form.getFormTypeConfidence());\n form.getFields().forEach((label, formField) ->\n System.out.printf(\"Field %s has value %s with confidence score of %f.%n\", label,\n formField.getValueData().getText(),\n formField.getConfidence())\n );\n }\n```\n\nFor a suggested approach to extracting information from custom forms with known fields, see [strongly-typing a recognized form][].\n\n\n[Azure Form Recognizer]: https://aka.ms/form-recognizer-3.0.0\n[Migration guide]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/formrecognizer/azure-ai-formrecognizer/migration-guide.md\n[managed identity]: https://learn.microsoft.com/azure/active-directory/managed-identities-azure-resources/\n[Azure Identity documentation]: https://learn.microsoft.com/java/api/overview/azure/identity-readme\n[Form Recognizer models]: https://learn.microsoft.com/azure/applied-ai-services/form-recognizer/concept-model-overview?view=form-recog-3.0.0#model-overview\n[models usage documentation]: https://learn.microsoft.com/azure/applied-ai-services/form-recognizer/concept-model-overview?view=form-recog-2.1.0\n[train a model with labels]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/v3/TrainModelWithLabels.java\n[strongly-typing a recognized form]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/v3/StronglyTypedRecognizedForm.java"
|
|
metadata: {}
|
|
package: "com.azure.ai.formrecognizer"
|
|
artifact: com.azure:azure-ai-formrecognizer:4.1.11
|