Share via


DocumentAnalysisClient クラス

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

public final class DocumentAnalysisClient

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

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

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

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

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

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

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

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

DocumentAnalysisClient documentAnalysisClient = new DocumentAnalysisClientBuilder()
     .endpoint("{endpoint}")
     .credential(new DefaultAzureCredentialBuilder().build())
     .buildClient();

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

DocumentAnalysisClient documentAnalysisClient = new DocumentAnalysisClientBuilder()
     .credential(new AzureKeyCredential("{key}"))
     .endpoint("{endpoint}")
     .buildClient();

メソッドの概要

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

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

SyncPoller<OperationResult,AnalyzeResult> beginAnalyzeDocument(String modelId, BinaryData document, AnalyzeDocumentOptions analyzeDocumentOptions, Context context)

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

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

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

SyncPoller<OperationResult,AnalyzeResult> beginAnalyzeDocumentFromUrl(String modelId, String documentUrl, AnalyzeDocumentOptions analyzeDocumentOptions, Context context)

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

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

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

SyncPoller<OperationResult,AnalyzeResult> beginClassifyDocument(String classifierId, BinaryData document, Context context)

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

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

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

SyncPoller<OperationResult,AnalyzeResult> beginClassifyDocumentFromUrl(String classifierId, String documentUrl, Context context)

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

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

メソッドの詳細

beginAnalyzeDocument

public SyncPoller beginAnalyzeDocument(String modelId, BinaryData document)

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

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

Code sample

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

     documentAnalysisClient.beginAnalyzeDocument(modelId, BinaryData.fromBytes(fileContent))
         .getFinalResult()
         .getDocuments().stream()
         .map(AnalyzedDocument::getFields)
         .forEach(documentFieldMap -> documentFieldMap.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:

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

beginAnalyzeDocument

public SyncPoller beginAnalyzeDocument(String modelId, BinaryData document, AnalyzeDocumentOptions analyzeDocumentOptions, Context context)

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

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

Code sample

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

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

 documentAnalysisClient.beginAnalyzeDocument(modelId, BinaryData.fromBytes(fileContent),
         new AnalyzeDocumentOptions().setPages(Arrays.asList("1", "3")), Context.NONE)
     .getFinalResult()
     .getDocuments().stream()
     .map(AnalyzedDocument::getFields)
     .forEach(documentFieldMap -> documentFieldMap.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
context - サービス呼び出し中に HTTP パイプラインを介して渡される追加のコンテキスト。

Returns:

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

beginAnalyzeDocumentFromUrl

public SyncPoller beginAnalyzeDocumentFromUrl(String modelId, String documentUrl)

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

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

Code sample

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

String documentUrl = "{document_url}";
 String modelId = "{custom_trained_model_id}";

 documentAnalysisClient.beginAnalyzeDocumentFromUrl(modelId, documentUrl).getFinalResult()
     .getDocuments().stream()
     .map(AnalyzedDocument::getFields)
     .forEach(documentFieldMap -> documentFieldMap.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:

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

beginAnalyzeDocumentFromUrl

public SyncPoller beginAnalyzeDocumentFromUrl(String modelId, String documentUrl, AnalyzeDocumentOptions analyzeDocumentOptions, Context context)

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

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

Code sample

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

String documentUrl = "{document_url}";
 String modelId = "{custom_trained_model_id}";

 documentAnalysisClient.beginAnalyzeDocumentFromUrl(modelId, documentUrl).getFinalResult()
     .getDocuments().stream()
     .map(AnalyzedDocument::getFields)
     .forEach(documentFieldMap -> documentFieldMap.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
context - サービス呼び出し中に HTTP パイプラインを介して渡される追加のコンテキスト。

Returns:

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

beginClassifyDocument

public SyncPoller beginClassifyDocument(String classifierId, BinaryData document)

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

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

Code sample

File document = new File("{local/file_path/fileName.jpg}");
 String classifierId = "{custom_trained_classifier_id}";
 byte[] fileContent = Files.readAllBytes(document.toPath());

 documentAnalysisClient.beginClassifyDocument(classifierId, BinaryData.fromBytes(fileContent))
     .getFinalResult()
     .getDocuments()
     .forEach(analyzedDocument -> System.out.printf("Doc Type: %s%n", analyzedDocument.getDocType()));

Parameters:

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

Returns:

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

beginClassifyDocument

public SyncPoller beginClassifyDocument(String classifierId, BinaryData document, Context context)

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

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

Code sample

File document = new File("{local/file_path/fileName.jpg}");
 String classifierId = "{custom_trained_classifier_id}";
 byte[] fileContent = Files.readAllBytes(document.toPath());

 documentAnalysisClient.beginClassifyDocument(classifierId, BinaryData.fromBytes(fileContent), Context.NONE)
     .getFinalResult()
     .getDocuments()
     .forEach(analyzedDocument -> System.out.printf("Doc Type: %s%n", analyzedDocument.getDocType()));

Parameters:

classifierId - 使用する一意の分類子 ID。 これを使用して、カスタム分類子 ID を指定します。
document - 情報を分析するドキュメントのデータ。
context - サービス呼び出し中に HTTP パイプラインを介して渡される追加のコンテキスト。

Returns:

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

beginClassifyDocumentFromUrl

public SyncPoller beginClassifyDocumentFromUrl(String classifierId, String documentUrl)

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

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

Code sample

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

String documentUrl = "{file_source_url}";
 String classifierId = "{custom_trained_classifier_id}";

 documentAnalysisClient.beginClassifyDocumentFromUrl(classifierId, documentUrl)
     .getFinalResult()
     .getDocuments()
     .forEach(analyzedDocument -> System.out.printf("Doc Type: %s%n", analyzedDocument.getDocType()));

Parameters:

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

Returns:

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

beginClassifyDocumentFromUrl

public SyncPoller beginClassifyDocumentFromUrl(String classifierId, String documentUrl, Context context)

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

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

Code sample

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

String documentUrl = "{file_source_url}";
 String classifierId = "{custom_trained_classifier_id}";

 documentAnalysisClient.beginClassifyDocumentFromUrl(classifierId, documentUrl, Context.NONE)
     .getFinalResult()
     .getDocuments()
     .forEach(analyzedDocument -> System.out.printf("Doc Type: %s%n", analyzedDocument.getDocType()));

Parameters:

classifierId - 使用する一意の分類子 ID。 これを使用して、カスタム分類子 ID を指定します。 サポートされている事前構築済みモデル ID については、こちらを参照してください
documentUrl - 入力ドキュメントのソース URL。
context - サービス呼び出し中に HTTP パイプラインを介して渡される追加のコンテキスト。

Returns:

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

適用対象