FormRecognizerAsyncClient クラス
- java.
lang. Object - com.
azure. ai. formrecognizer. FormRecognizerAsyncClient
- com.
public final class FormRecognizerAsyncClient
このクラスは、Form Recognizer Azure Cognitive Service に接続するための非同期クライアントを提供します。
このクライアントは、以下を実行する非同期メソッドを提供します。
- カスタム フォーム分析: 個別のビジネス データとユース ケースに固有のフォームやドキュメントからのデータの抽出と分析。 modelId を メソッドに渡して、カスタムトレーニング済みモデルを beginRecognizeCustomForms 使用します。
- 事前構築済みモデル分析: サポートされている事前構築済みモデル を使用して、領収書、名刺、請求書、その他のドキュメントを分析する 方法を beginRecognizeReceipts 使用して、領収書情報を認識します。
- レイアウト分析: フォームとドキュメントからのテキスト、選択マーク、テーブル、境界ボックス座標の抽出と分析。 tpo メソッドを使用して beginRecognizeContent レイアウト分析を実行します。
- ポーリングとコールバック: サービスをポーリングして分析操作の状態をチェックしたり、分析が完了したときに通知を受信するためのコールバックを登録したりするメカニズムが含まれています。
メモ: このクライアントでは、 以下のみがサポートされます V2_1 。 新しいサービス バージョン DocumentAnalysisClient と DocumentModelAdministrationClientを使用することをお勧めします。
API バージョン 2022-08-31 以降を使用するには、 移行ガイド を参照してください。
サービス クライアントは、開発者が Azure Form Recognizerを使用するための対話のポイントです。 FormRecognizerClient は同期サービス クライアントであり、 FormRecognizerAsyncClient 非同期サービス クライアントです。 このドキュメントに示す例では、認証に DefaultAzureCredential という名前の資格情報オブジェクトを使用します。これは、ローカルの開発環境や運用環境など、ほとんどのシナリオに適しています。 さらに、運用環境での認証には マネージド ID を 使用することをお勧めします。 さまざまな認証方法と、それに対応する資格情報の種類の詳細については、 Azure Identity のドキュメントを参照してください。
サンプル: DefaultAzureCredential を使用して FormRecognizerClient を構築する
次のコード サンプルは、'DefaultAzureCredentialBuilder' を使用して を構成する の作成 FormRecognizerAsyncClientを示しています。
FormRecognizerAsyncClient formRecognizerAsyncClient = new FormRecognizerClientBuilder()
.endpoint("{endpoint}")
.credential(new DefaultAzureCredentialBuilder().build())
.buildAsyncClient();
さらに、クライアントの作成に使用 AzureKeyCredential する次のコード サンプルを参照してください。
FormRecognizerAsyncClient formRecognizerAsyncClient = new FormRecognizerClientBuilder()
.credential(new AzureKeyCredential("{key}"))
.endpoint("{endpoint}")
.buildAsyncClient();
メソッドの概要
メソッドの継承元: java.lang.Object
メソッドの詳細
beginRecognizeBusinessCards
public PollerFlux
光学式文字認識 (OCR) と事前構築済みのビジネス カードトレーニング済みモデルを使用して、ビジネス カード データを認識します。
サービスは実行時間の長い操作の取り消しをサポートせず、取り消しサポートがないことを示すエラー メッセージを返します。
ビジネス カードのフィールドについては、こちらを参照してください。 再試行が businessCard
有効になっている場合は、渡された を再生可能にする必要があることに注意してください (既定値)。 つまり、 Flux
はサブスクライブされるたびに同じデータを生成する必要があります。
Code sample
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:
Returns:
beginRecognizeBusinessCards
public PollerFlux
光学式文字認識 (OCR) と事前構築済みのビジネス カードトレーニング済みモデルを使用して、ドキュメントからビジネス カード データを認識します。
サービスは実行時間の長い操作の取り消しをサポートせず、取り消しサポートがないことを示すエラー メッセージを返します。
ビジネス カードのフィールドについては、こちらを参照してください。 再試行が businessCard
有効になっている場合は、渡された を再生可能にする必要があることに注意してください (既定値)。 つまり、 Flux
はサブスクライブされるたびに同じデータを生成する必要があります。
Code sample
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:
Returns:
beginRecognizeBusinessCardsFromUrl
public PollerFlux
光学式文字認識 (OCR) と事前構築済みのビジネス カードトレーニング済みモデルを使用して、ビジネス カード データを認識します。
サービスは実行時間の長い操作の取り消しをサポートせず、取り消しサポートがないことを示すエラー メッセージを返します。
ビジネス カードのフィールドについては、こちらを参照してください。
Code sample
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:
Returns:
beginRecognizeBusinessCardsFromUrl
public PollerFlux
光学式文字認識 (OCR) と事前構築済みのビジネス カードトレーニング済みモデルを使用して、ビジネス カード データを認識します。
サービスは実行時間の長い操作の取り消しをサポートせず、取り消しサポートがないことを示すエラー メッセージを返します。
ビジネス カードのフィールドについては、こちらを参照してください。
Code sample
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:
Returns:
beginRecognizeContent
public PollerFlux
光学式文字認識 (OCR) を使用してコンテンツ/レイアウト データを認識します。
サービスは実行時間の長い操作の取り消しをサポートせず、取り消しサポートがないことを示すエラー メッセージを返します。
再試行が data
有効になっている場合は、渡された を再生可能にする必要があることに注意してください (既定値)。 つまり、 Flux
はサブスクライブされるたびに同じデータを生成する必要があります。
Code sample
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:
Returns:
beginRecognizeContent
public PollerFlux
光学式文字認識 (OCR) を使用してコンテンツ/レイアウト データを認識します。
サービスは実行時間の長い操作の取り消しをサポートせず、取り消しサポートがないことを示すエラー メッセージを返します。
再試行が data
有効になっている場合は、渡された を再生可能にする必要があることに注意してください (既定値)。 つまり、 Flux
はサブスクライブされるたびに同じデータを生成する必要があります。
コンテンツ認識では、自動言語識別と多言語ドキュメントがサポートされているため、 でドキュメントをその特定の言語として強制的に処理する場合にのみ言語コードを RecognizeContentOptions提供します。
Code sample
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:
Returns:
beginRecognizeContentFromUrl
public PollerFlux
光学式文字認識 (OCR) を使用して、ドキュメントのコンテンツ/レイアウト データを認識します。
サービスは実行時間の長い操作の取り消しをサポートせず、取り消しサポートがないことを示すエラー メッセージを返します。
Code sample
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:
Returns:
beginRecognizeContentFromUrl
public PollerFlux
光学式文字認識 (OCR) とカスタムトレーニング済みモデルを使用して、ドキュメントからレイアウト データを認識します。
サービスは実行時間の長い操作の取り消しをサポートせず、取り消しサポートがないことを示すエラー メッセージを返します。
コンテンツ認識では、自動言語識別と多言語ドキュメントがサポートされているため、 でドキュメントをその特定の言語として強制的に処理する場合にのみ言語コードを RecognizeContentOptions提供します。
Code sample
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:
Returns:
beginRecognizeCustomForms
public PollerFlux
光学式文字認識 (OCR) と、ラベル付きまたはラベルなしのカスタムトレーニング済みモデルを使用して、ドキュメントからフォーム データを認識します。
サービスは実行時間の長い操作の取り消しをサポートせず、取り消しサポートがないことを示すエラー メッセージを返します。
再試行が data
有効になっている場合は、渡された を再生可能にする必要があることに注意してください (既定値)。 つまり、 Flux
はサブスクライブされるたびに同じデータを生成する必要があります。
Code sample
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:
Returns:
beginRecognizeCustomForms
public PollerFlux
光学式文字認識 (OCR) と、ラベル付きまたはラベルなしのカスタムトレーニング済みモデルを使用して、ドキュメントからフォーム データを認識します。
サービスは実行時間の長い操作の取り消しをサポートせず、取り消しサポートがないことを示すエラー メッセージを返します。
再試行が data
有効になっている場合は、渡された を再生可能にする必要があることに注意してください (既定値)。 つまり、 Flux
はサブスクライブされるたびに同じデータを生成する必要があります。
Code sample
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:
Returns:
beginRecognizeCustomFormsFromUrl
public PollerFlux
光学式文字認識 (OCR) と、ラベル付きまたはラベルなしのカスタムトレーニング済みモデルを使用して、ドキュメントからフォーム データを認識します。
サービスは実行時間の長い操作の取り消しをサポートせず、取り消しサポートがないことを示すエラー メッセージを返します。
Code sample
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:
Returns:
beginRecognizeCustomFormsFromUrl
public PollerFlux
光学式文字認識 (OCR) とカスタムトレーニング済みモデルを使用して、ドキュメントからフォーム データを認識します。
サービスは実行時間の長い操作の取り消しをサポートせず、取り消しサポートがないことを示すエラー メッセージを返します。
Code sample
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:
Returns:
beginRecognizeIdentityDocuments
public PollerFlux
光学式文字認識 (OCR) と ID ドキュメント モデルでトレーニングされた事前構築済みモデルを使用して ID ドキュメントを分析し、パスポートと米国の運転免許証から重要な情報を抽出します。 ID ドキュメントで見つかったフィールドについては、 こちらを 参照してください。
サービスは実行時間の長い操作の取り消しをサポートせず、取り消しサポートがないことを示すエラー メッセージを返します。
再試行が identityDocument
有効になっている場合は、渡された を再生可能にする必要があることに注意してください (既定値)。 つまり、 Flux
はサブスクライブされるたびに同じデータを生成する必要があります。
Code sample
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:
Returns:
beginRecognizeIdentityDocuments
public PollerFlux
光学式文字認識 (OCR) と ID ドキュメント モデルでトレーニングされた事前構築済みモデルを使用して ID ドキュメントを分析し、パスポートと米国の運転免許証から重要な情報を抽出します。 ID ドキュメントで見つかったフィールドについては、 こちらを 参照してください。
このサービスは、実行時間の長い操作の取り消しをサポートせず、取り消しサポートがないことを示すエラー メッセージを返します。
再試行が identityDocument
有効になっている場合は、渡された を再生可能にする必要があることに注意してください (既定値)。 つまり、 は Flux
サブスクライブされるたびに同じデータを生成する必要があります。
Code sample
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:
Returns:
beginRecognizeIdentityDocumentsFromUrl
public PollerFlux
光学式文字認識 (OCR) と ID ドキュメント モデルでトレーニングされた事前構築済みモデルを使用して ID ドキュメントを分析し、パスポートと米国の運転免許証から重要な情報を抽出します。 ID ドキュメントで見つかったフィールドについては、 こちらを 参照してください。
このサービスは、実行時間の長い操作の取り消しをサポートせず、取り消しサポートがないことを示すエラー メッセージを返します。
Code sample
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:
Returns:
beginRecognizeIdentityDocumentsFromUrl
public PollerFlux
光学式文字認識 (OCR) と ID ドキュメント モデルでトレーニングされた事前構築済みモデルを使用して ID ドキュメントを分析し、パスポートと米国の運転免許証から重要な情報を抽出します。 ID ドキュメントで見つかったフィールドについては、 こちらを 参照してください。
このサービスは、実行時間の長い操作の取り消しをサポートせず、取り消しサポートがないことを示すエラー メッセージを返します。
Code sample
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:
Returns:
beginRecognizeInvoices
public PollerFlux
光学式文字認識 (OCR) と事前構築済みの請求書トレーニング済みモデルを使用して、請求書データを認識します。
このサービスは、実行時間の長い操作の取り消しをサポートせず、取り消しサポートがないことを示すエラー メッセージを返します。
請求書で見つかったフィールドについては、 こちらを 参照してください。 再試行が invoice
有効になっている場合は、渡された を再生可能にする必要があることに注意してください (既定値)。 つまり、 は Flux
サブスクライブされるたびに同じデータを生成する必要があります。
Code sample
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:
Returns:
beginRecognizeInvoices
public PollerFlux
光学式文字認識 (OCR) と事前構築済みの請求書トレーニング済みモデルを使用して、ドキュメントからの請求書データを認識します。
このサービスは、実行時間の長い操作の取り消しをサポートせず、取り消しサポートがないことを示すエラー メッセージを返します。
請求書で見つかったフィールドについては、 こちらを 参照してください。 再試行が invoice
有効になっている場合は、渡された を再生可能にする必要があることに注意してください (既定値)。 つまり、 は Flux
サブスクライブされるたびに同じデータを生成する必要があります。
Code sample
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:
Returns:
beginRecognizeInvoicesFromUrl
public PollerFlux
光学式文字認識 (OCR) と事前構築済みの請求書トレーニング済みモデルを使用して、請求書データを認識します。
このサービスは、実行時間の長い操作の取り消しをサポートせず、取り消しサポートがないことを示すエラー メッセージを返します。
請求書で見つかったフィールドについては、 こちらを 参照してください。
Code sample
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:
Returns:
beginRecognizeInvoicesFromUrl
public PollerFlux
光学式文字認識 (OCR) と事前構築済みの請求書トレーニング済みモデルを使用して、請求書データを認識します。
このサービスは、実行時間の長い操作の取り消しをサポートせず、取り消しサポートがないことを示すエラー メッセージを返します。
Code sample
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:
Returns:
beginRecognizeReceipts
public PollerFlux
光学式文字認識 (OCR) と事前構築済みのレシートトレーニング済みモデルを使用して、レシート データを認識します。
このサービスは、実行時間の長い操作の取り消しをサポートせず、取り消しサポートがないことを示すエラー メッセージを返します。
領収書で見つかったフィールドについては、 こちらを 参照してください。 再試行が receipt
有効になっている場合は、渡された を再生可能にする必要があることに注意してください (既定値)。 つまり、 は Flux
サブスクライブされるたびに同じデータを生成する必要があります。
Code sample
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:
Returns:
beginRecognizeReceipts
public PollerFlux
光学式文字認識 (OCR) と事前構築済みのレシートトレーニング済みモデルを使用して、ドキュメントからのレシート データを認識します。
このサービスは、実行時間の長い操作の取り消しをサポートせず、取り消しサポートがないことを示すエラー メッセージを返します。
領収書で見つかったフィールドについては、 こちらを 参照してください。 再試行が receipt
有効になっている場合は、渡された を再生可能にする必要があることに注意してください (既定値)。 つまり、 は Flux
サブスクライブされるたびに同じデータを生成する必要があります。
Code sample
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:
Returns:
beginRecognizeReceiptsFromUrl
public PollerFlux
光学式文字認識 (OCR) と事前構築済みのレシートトレーニング済みモデルを使用して、レシート データを認識します。
このサービスは、実行時間の長い操作の取り消しをサポートせず、取り消しサポートがないことを示すエラー メッセージを返します。
領収書で見つかったフィールドについては、 こちらを 参照してください。
Code sample
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:
Returns:
beginRecognizeReceiptsFromUrl
public PollerFlux
光学式文字認識 (OCR) と事前構築済みのレシートトレーニング済みモデルを使用して、レシート データを認識します。
このサービスは、実行時間の長い操作の取り消しをサポートせず、取り消しサポートがないことを示すエラー メッセージを返します。
Code sample
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:
Returns:
適用対象
Azure SDK for Java