次の方法で共有


DocumentAnalysisAsyncClient クラス

  • java.lang.Object
    • com.azure.ai.formrecognizer.documentanalysis.DocumentAnalysisAsyncClient

public final class DocumentAnalysisAsyncClient

このクラスは、Form Recognizer Azure Cognitive Service に接続するための非同期クライアントを提供します。

このクライアントは、以下を実行する非同期メソッドを提供します。

  1. カスタム ドキュメント分析: 個別のビジネス データとユース ケースに固有のフォームとドキュメントからのデータの分類、抽出、分析。 modelId を メソッドに渡して、カスタムトレーニング済みモデルを com.azure.ai.formrecognizer.documentanalysis.DocumentAnalysisAsyncClient#beginAnalyzeDocument(String, BinaryData) 使用します。
  2. 一般的なドキュメント分析: テキスト、テーブル、構造、およびキーと値のペアを抽出します。 modelId="rebuilt-document" を メソッドに渡して、Form Recognizer サービスによって提供される一般的なドキュメント モデルをcom.azure.ai.formrecognizer.documentanalysis.DocumentAnalysisAsyncClient#beginAnalyzeDocument(String, BinaryData)使用します。
  3. 事前構築済みモデル分析: 領収書、名刺、請求書、ID、W2、その他のドキュメントを使用して分析します supported prebuilt models. Use the prebuilt receipt model provided by passing modelId="prebuilt-receipt" into the com.azure.ai.formrecognizer.documentanalysis.DocumentAnalysisAsyncClient#beginAnalyzeDocument(String, BinaryData) method.
  4. レイアウト分析: テキスト、選択マーク、テーブル構造、および境界ボックス座標をフォームやドキュメントから抽出します。 modelId="prebuilt-layout" を メソッドに渡すことによって、サービスで提供されたレイアウト分析モデルを com.azure.ai.formrecognizer.documentanalysis.DocumentAnalysisAsyncClient#beginAnalyzeDocument(String, BinaryData) 使用します。
  5. ポーリングとコールバック: 分析操作の状態をチェックするためのサービスのポーリング、または分析が完了したときに通知を受信するためのコールバックの登録を行うメカニズムが含まれています。

このクライアントでは、URL からの入力とストリームからの入力に基づいて、さまざまなメソッドも提供されます。

メモ: このクライアントは 以降のみをサポートします V2022_08_31 。 以前のサービス バージョンと .formrecognizer.training.FormTrainingClientを使用するには。 FormRecognizerClient

サービス クライアントは、開発者が Azure Form Recognizerを使用するための対話のポイントです。 DocumentAnalysisClient は同期サービス クライアントであり、 DocumentAnalysisAsyncClient 非同期サービス クライアントです。 このドキュメントに示す例では、認証に DefaultAzureCredential という名前の資格情報オブジェクトを使用します。これは、ローカルの開発環境や運用環境を含むほとんどのシナリオに適しています。 さらに、運用環境での認証に マネージド ID を 使用することをお勧めします。 認証のさまざまな方法とそれに対応する資格情報の種類の詳細については、 Azure ID のドキュメントを参照してください

サンプル: DefaultAzureCredential を使用して DocumentAnalysisAsyncClient を構築する

次のコード サンプルは、'DefaultAzureCredentialBuilder' を使用して を構成する の作成 DocumentAnalysisAsyncClientを示しています。

DocumentAnalysisAsyncClient documentAnalysisAsyncClient = new DocumentAnalysisClientBuilder()
     .endpoint("{endpoint}")
     .credential(new DefaultAzureCredentialBuilder().build())
     .buildAsyncClient();

さらに、クライアントの作成に使用する次のコード サンプルを参照 AzureKeyCredential してください。

DocumentAnalysisAsyncClient documentAnalysisAsyncClient = new DocumentAnalysisClientBuilder()
     .credential(new AzureKeyCredential("{key}"))
     .endpoint("{endpoint}")
     .buildAsyncClient();

メソッドの概要

修飾子と型 メソッドと説明
PollerFlux<OperationResult,AnalyzeResult> beginAnalyzeDocument(String modelId, BinaryData document)

事前構築済みのモデルまたはカスタム構築された分析モデルのいずれかを使用して、特定のドキュメントの光学式文字認識 (OCR) とセマンティック値を使用してドキュメントのデータを分析します。

PollerFlux<OperationResult,AnalyzeResult> beginAnalyzeDocument(String modelId, BinaryData document, AnalyzeDocumentOptions analyzeDocumentOptions)

事前構築済みのモデルまたはカスタム構築された分析モデルのいずれかを使用して、特定のドキュメントの光学式文字認識 (OCR) とセマンティック値を使用してドキュメントのデータを分析します。

PollerFlux<OperationResult,AnalyzeResult> beginAnalyzeDocumentFromUrl(String modelId, String documentUrl)

事前構築済みのモデルまたはカスタム構築された分析モデルのいずれかを使用して、特定のドキュメントの光学式文字認識 (OCR) とセマンティック値を使用してドキュメントのデータを分析します。

PollerFlux<OperationResult,AnalyzeResult> beginAnalyzeDocumentFromUrl(String modelId, String documentUrl, AnalyzeDocumentOptions analyzeDocumentOptions)

事前構築済みのモデルまたはカスタム構築された分析モデルのいずれかを使用して、特定のドキュメントの光学式文字認識 (OCR) とセマンティック値を使用してドキュメントのデータを分析します。

PollerFlux<OperationResult,AnalyzeResult> beginClassifyDocument(String classifierId, BinaryData document)

ドキュメント分類子を使用して、特定のドキュメントを分類します。

PollerFlux<OperationResult,AnalyzeResult> beginClassifyDocumentFromUrl(String classifierId, String documentUrl)

ドキュメント分類子を使用して、特定のドキュメントを分類します。

メソッドの継承元: java.lang.Object

メソッドの詳細

beginAnalyzeDocument

public PollerFlux beginAnalyzeDocument(String modelId, BinaryData document)

事前構築済みのモデルまたはカスタム構築された分析モデルのいずれかを使用して、特定のドキュメントの光学式文字認識 (OCR) とセマンティック値を使用してドキュメントのデータを分析します。

このサービスは、実行時間の長い操作の取り消しをサポートせず、取り消しサポートがないことを示すエラー メッセージを返します。

再試行が data 有効になっている場合は、渡された を再生可能にする必要があることに注意してください (既定値)。 つまり、 は Flux サブスクライブされるたびに同じデータを生成する必要があります。

Code sample

ドキュメントを分析する。

File document = new File("{local/file_path/fileName.jpg}");
 String modelId = "{model_id}";
 // Utility method to convert input stream to Binary Data
 BinaryData buffer = BinaryData.fromStream(new ByteArrayInputStream(Files.readAllBytes(document.toPath())));

 documentAnalysisAsyncClient.beginAnalyzeDocument(modelId, buffer)
     // if polling operation completed, retrieve the final result.
     .flatMap(AsyncPollResponse::getFinalResult)
     .subscribe(analyzeResult ->
         analyzeResult.getDocuments()
             .forEach(analyzedDocument ->
                 analyzedDocument.getFields()
                     .forEach((key, documentField) -> {
                         System.out.printf("Field text: %s%n", key);
                         System.out.printf("Field value data content: %s%n", documentField.getContent());
                         System.out.printf("Confidence score: %.2f%n", documentField.getConfidence());
                     })));

Parameters:

modelId - 使用する一意のモデル ID。 これを使用して、カスタム モデル ID または事前構築済みモデル ID を指定します。 サポートされている事前構築済みモデル ID については、こちらを参照してください
document - 情報を分析するドキュメントのデータ。

Returns:

PollerFlux<T,U>完了、失敗、または取り消されるまで、分析ドキュメント操作の進行状況をポーリングする 。 完了した操作では、 が AnalyzeResult返されます。

beginAnalyzeDocument

public PollerFlux beginAnalyzeDocument(String modelId, BinaryData document, AnalyzeDocumentOptions analyzeDocumentOptions)

事前構築済みのモデルまたはカスタム構築された分析モデルのいずれかを使用して、特定のドキュメントの光学式文字認識 (OCR) とセマンティック値を使用してドキュメントのデータを分析します。

このサービスは、実行時間の長い操作の取り消しをサポートせず、取り消しサポートがないことを示すエラー メッセージを返します。

再試行が data 有効になっている場合は、渡された を再生可能にする必要があることに注意してください (既定値)。 つまり、 は Flux サブスクライブされるたびに同じデータを生成する必要があります。

Code sample

構成可能なオプションを使用してドキュメントを分析します。 .

File document = new File("{local/file_path/fileName.jpg}");
 String modelId = "{model_id}";
 final AnalyzeDocumentOptions analyzeDocumentOptions =
     new AnalyzeDocumentOptions().setPages(Arrays.asList("1", "3")).setDocumentAnalysisFeatures(
         Collections.singletonList(
             DocumentAnalysisFeature.FORMULAS));

 // Utility method to convert input stream to Binary Data
 BinaryData buffer = BinaryData.fromStream(new ByteArrayInputStream(Files.readAllBytes(document.toPath())));

 documentAnalysisAsyncClient.beginAnalyzeDocument(modelId, buffer, analyzeDocumentOptions)
     // if polling operation completed, retrieve the final result.
     .flatMap(AsyncPollResponse::getFinalResult)
     .subscribe(analyzeResult -> {
         System.out.println(analyzeResult.getModelId());
         analyzeResult.getDocuments()
             .forEach(analyzedDocument ->
                 analyzedDocument.getFields()
                     .forEach((key, documentField) -> {
                         System.out.printf("Field text: %s%n", key);
                         System.out.printf("Field value data content: %s%n", documentField.getContent());
                         System.out.printf("Confidence score: %.2f%n", documentField.getConfidence());
                     }));
     });

Parameters:

modelId - 使用する一意のモデル ID。 これを使用して、カスタム モデル ID または事前構築済みモデル ID を指定します。 サポートされている事前構築済みモデル ID については、こちらを参照してください
document - 情報を分析するドキュメントのデータ。
analyzeDocumentOptions - ドキュメントの分析時に渡される可能性がある追加の構成可能 AnalyzeDocumentOptions

Returns:

PollerFlux<T,U>完了、失敗、または取り消されるまで、分析ドキュメント操作の進行状況をポーリングする 。 完了した操作では、 が AnalyzeResult返されます。

beginAnalyzeDocumentFromUrl

public PollerFlux beginAnalyzeDocumentFromUrl(String modelId, String documentUrl)

事前構築済みのモデルまたはカスタム構築された分析モデルのいずれかを使用して、特定のドキュメントの光学式文字認識 (OCR) とセマンティック値を使用してドキュメントのデータを分析します。

このサービスは、実行時間の長い操作の取り消しをサポートせず、取り消しサポートがないことを示すエラー メッセージを返します。

Code sample

ドキュメントの URL を使用してドキュメントを分析します。

String documentUrl = "{document_url}";
 String modelId = "{model_id}";
 documentAnalysisAsyncClient.beginAnalyzeDocumentFromUrl(modelId, documentUrl)
     // if polling operation completed, retrieve the final result.
     .flatMap(AsyncPollResponse::getFinalResult)
     .subscribe(analyzeResult ->
         analyzeResult.getDocuments()
             .forEach(document ->
                 document.getFields()
                     .forEach((key, documentField) -> {
                         System.out.printf("Field text: %s%n", key);
                         System.out.printf("Field value data content: %s%n", documentField.getContent());
                         System.out.printf("Confidence score: %.2f%n", documentField.getConfidence());
                     })));

Parameters:

modelId - 使用する一意のモデル ID。 これを使用して、カスタム モデル ID または事前構築済みモデル ID を指定します。 サポートされている事前構築済みモデル ID については、こちらを参照してください
documentUrl - 分析するドキュメントの URL。

Returns:

PollerFlux<T,U>完了、失敗、または取り消されるまで、分析ドキュメント操作の進行状況をポーリングする 。 完了した操作では、 が AnalyzeResult返されます。

beginAnalyzeDocumentFromUrl

public PollerFlux beginAnalyzeDocumentFromUrl(String modelId, String documentUrl, AnalyzeDocumentOptions analyzeDocumentOptions)

事前構築済みのモデルまたはカスタム構築された分析モデルのいずれかを使用して、特定のドキュメントの光学式文字認識 (OCR) とセマンティック値を使用してドキュメントのデータを分析します。

このサービスは、実行時間の長い操作の取り消しをサポートせず、取り消しサポートがないことを示すエラー メッセージを返します。

Code sample

構成可能なオプションを使用して、ドキュメントの URL を使用してドキュメントを分析します。

String documentUrl = "{document_url}";
 // analyze a receipt using prebuilt model
 String modelId = "prebuilt-receipt";

 documentAnalysisAsyncClient.beginAnalyzeDocumentFromUrl(modelId, documentUrl,
         new AnalyzeDocumentOptions().setPages(Arrays.asList("1", "3")))
     // if polling operation completed, retrieve the final result.
     .flatMap(AsyncPollResponse::getFinalResult)
     .subscribe(analyzeResult -> {
         System.out.println(analyzeResult.getModelId());
         analyzeResult.getDocuments()
             .forEach(document ->
                 document.getFields()
                     .forEach((key, documentField) -> {
                         System.out.printf("Field text: %s%n", key);
                         System.out.printf("Field value data content: %s%n", documentField.getContent());
                         System.out.printf("Confidence score: %.2f%n", documentField.getConfidence());
                     }));
     });

Parameters:

modelId - 使用する一意のモデル ID。 これを使用して、カスタム モデル ID または事前構築済みモデル ID を指定します。 サポートされている事前構築済みモデル ID については、こちらを参照してください
documentUrl - 入力フォームのソース URL。
analyzeDocumentOptions - ドキュメントの分析時に渡される可能性がある追加の構成可能 AnalyzeDocumentOptions

Returns:

PollerFlux<T,U>完了、失敗、または取り消されるまで、分析ドキュメント操作の進行状況をポーリングする 。 完了した操作では、 が AnalyzeResult返されます。

beginClassifyDocument

public PollerFlux beginClassifyDocument(String classifierId, BinaryData document)

ドキュメント分類子を使用して、特定のドキュメントを分類します。 カスタム分類子モデルを構築する方法の詳細については、次を参照してください。

このサービスは、実行時間の長い操作の取り消しをサポートせず、取り消しサポートがないことを示すエラー メッセージを返します。

再試行が data 有効になっている場合は、渡された を再生可能にする必要があることに注意してください (既定値)。 つまり、 は Flux サブスクライブされるたびに同じデータを生成する必要があります。

Code sample

構成可能なオプションを使用してドキュメントを分析します。

File document = new File("{local/file_path/fileName.jpg}");
 String classifierId = "{model_id}";

 // Utility method to convert input stream to Binary Data
 BinaryData buffer = BinaryData.fromStream(new ByteArrayInputStream(Files.readAllBytes(document.toPath())));

 documentAnalysisAsyncClient.beginClassifyDocument(classifierId, buffer)
     // if polling operation completed, retrieve the final result.
     .flatMap(AsyncPollResponse::getFinalResult)
     .subscribe(analyzeResult -> {
         System.out.println(analyzeResult.getModelId());
         analyzeResult.getDocuments()
             .forEach(analyzedDocument -> System.out.printf("Doc Type: %s%n", analyzedDocument.getDocType()));
     });

Parameters:

classifierId - 使用する一意の分類子 ID。 これを使用して、カスタム分類子 ID を指定します。
document - 情報を分析するドキュメントのデータ。 サービスでサポートされるファイルの種類については、次を参照してください。

Returns:

PollerFlux<T,U>完了、失敗、または取り消されるまで、分析ドキュメント操作の進行状況をポーリングする 。 完了した操作では、 が AnalyzeResult返されます。

beginClassifyDocumentFromUrl

public PollerFlux beginClassifyDocumentFromUrl(String classifierId, String documentUrl)

ドキュメント分類子を使用して、特定のドキュメントを分類します。 カスタム分類子モデルを構築する方法の詳細については、次を参照してください。

このサービスは、実行時間の長い操作の取り消しをサポートせず、取り消しサポートがないことを示すエラー メッセージを返します。

Code sample

ドキュメントの URL を使用してドキュメントを分析します。

String documentUrl = "{document_url}";
 String classifierId = "custom-trained-classifier-id";

 documentAnalysisAsyncClient.beginClassifyDocumentFromUrl(classifierId, documentUrl)
     // if polling operation completed, retrieve the final result.
     .flatMap(AsyncPollResponse::getFinalResult)
     .subscribe(analyzeResult -> {
         System.out.println(analyzeResult.getModelId());
         analyzeResult.getDocuments()
             .forEach(analyzedDocument -> System.out.printf("Doc Type: %s%n", analyzedDocument.getDocType()));
     });

Parameters:

classifierId - 使用する一意の分類子 ID。 これを使用して、カスタム分類子 ID を指定します。
documentUrl - 分析するドキュメントの URL。

Returns:

PollerFlux<T,U>完了、失敗、または取り消されるまで、分析ドキュメント操作の進行状況をポーリングする 。 完了した操作では、 が AnalyzeResult返されます。

適用対象