DocumentAnalysisAsyncClient クラス
- java.
lang. Object - com.
azure. ai. formrecognizer. documentanalysis. DocumentAnalysisAsyncClient
- com.
public final class DocumentAnalysisAsyncClient
このクラスは、Form Recognizer Azure Cognitive Service に接続するための非同期クライアントを提供します。
このクライアントは、以下を実行する非同期メソッドを提供します。
- カスタム ドキュメント分析: 個別のビジネス データとユース ケースに固有のフォームとドキュメントからのデータの分類、抽出、分析。 modelId を メソッドに渡して、カスタムトレーニング済みモデルを com.azure.ai.formrecognizer.documentanalysis.DocumentAnalysisAsyncClient#beginAnalyzeDocument(String, BinaryData) 使用します。
- 一般的なドキュメント分析: テキスト、テーブル、構造、およびキーと値のペアを抽出します。 modelId="rebuilt-document" を メソッドに渡して、Form Recognizer サービスによって提供される一般的なドキュメント モデルをcom.azure.ai.formrecognizer.documentanalysis.DocumentAnalysisAsyncClient#beginAnalyzeDocument(String, BinaryData)使用します。
- 事前構築済みモデル分析: 領収書、名刺、請求書、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.
- レイアウト分析: テキスト、選択マーク、テーブル構造、および境界ボックス座標をフォームやドキュメントから抽出します。 modelId="prebuilt-layout" を メソッドに渡すことによって、サービスで提供されたレイアウト分析モデルを com.azure.ai.formrecognizer.documentanalysis.DocumentAnalysisAsyncClient#beginAnalyzeDocument(String, BinaryData) 使用します。
- ポーリングとコールバック: 分析操作の状態をチェックするためのサービスのポーリング、または分析が完了したときに通知を受信するためのコールバックの登録を行うメカニズムが含まれています。
このクライアントでは、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();
メソッドの概要
メソッドの継承元: java.lang.Object
メソッドの詳細
beginAnalyzeDocument
public PollerFlux
事前構築済みのモデルまたはカスタム構築された分析モデルのいずれかを使用して、特定のドキュメントの光学式文字認識 (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:
Returns:
beginAnalyzeDocument
public PollerFlux
事前構築済みのモデルまたはカスタム構築された分析モデルのいずれかを使用して、特定のドキュメントの光学式文字認識 (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:
Returns:
beginAnalyzeDocumentFromUrl
public PollerFlux
事前構築済みのモデルまたはカスタム構築された分析モデルのいずれかを使用して、特定のドキュメントの光学式文字認識 (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:
Returns:
beginAnalyzeDocumentFromUrl
public PollerFlux
事前構築済みのモデルまたはカスタム構築された分析モデルのいずれかを使用して、特定のドキュメントの光学式文字認識 (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:
Returns:
beginClassifyDocument
public PollerFlux
ドキュメント分類子を使用して、特定のドキュメントを分類します。 カスタム分類子モデルを構築する方法の詳細については、次を参照してください。
このサービスは、実行時間の長い操作の取り消しをサポートせず、取り消しサポートがないことを示すエラー メッセージを返します。
再試行が 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:
Returns:
beginClassifyDocumentFromUrl
public PollerFlux
ドキュメント分類子を使用して、特定のドキュメントを分類します。 カスタム分類子モデルを構築する方法の詳細については、次を参照してください。
このサービスは、実行時間の長い操作の取り消しをサポートせず、取り消しサポートがないことを示すエラー メッセージを返します。
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:
Returns:
適用対象
Azure SDK for Java