你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

DocumentIntelligenceClient.AnalyzeDocument Method

Definition

Overloads

AnalyzeDocument(WaitUntil, String, RequestContent, String, String, String, IEnumerable<DocumentAnalysisFeature>, IEnumerable<String>, String, IEnumerable<AnalyzeOutputOption>, RequestContext)

[Protocol Method] Analyzes document with document model.

AnalyzeDocument(WaitUntil, String, AnalyzeDocumentContent, String, String, Nullable<StringIndexType>, IEnumerable<DocumentAnalysisFeature>, IEnumerable<String>, Nullable<ContentFormat>, IEnumerable<AnalyzeOutputOption>, CancellationToken)

Analyzes document with document model.

AnalyzeDocument(WaitUntil, String, Uri, CancellationToken)

Analyzes document with document model.

AnalyzeDocument(WaitUntil, String, BinaryData, CancellationToken)

Analyzes document with document model.

AnalyzeDocument(WaitUntil, AnalyzeDocumentOptions, CancellationToken)

Analyzes document with document model.

AnalyzeDocument(WaitUntil, String, RequestContent, String, String, String, IEnumerable<DocumentAnalysisFeature>, IEnumerable<String>, String, IEnumerable<AnalyzeOutputOption>, RequestContext)

Source:
DocumentIntelligenceClient.cs
Source:
DocumentIntelligenceClient.cs

[Protocol Method] Analyzes document with document model.

public virtual Azure.Operation<BinaryData> AnalyzeDocument (Azure.WaitUntil waitUntil, string modelId, Azure.Core.RequestContent content, string pages = default, string locale = default, string stringIndexType = default, System.Collections.Generic.IEnumerable<Azure.AI.DocumentIntelligence.DocumentAnalysisFeature> features = default, System.Collections.Generic.IEnumerable<string> queryFields = default, string outputContentFormat = default, System.Collections.Generic.IEnumerable<Azure.AI.DocumentIntelligence.AnalyzeOutputOption> output = default, Azure.RequestContext context = default);
abstract member AnalyzeDocument : Azure.WaitUntil * string * Azure.Core.RequestContent * string * string * string * seq<Azure.AI.DocumentIntelligence.DocumentAnalysisFeature> * seq<string> * string * seq<Azure.AI.DocumentIntelligence.AnalyzeOutputOption> * Azure.RequestContext -> Azure.Operation<BinaryData>
override this.AnalyzeDocument : Azure.WaitUntil * string * Azure.Core.RequestContent * string * string * string * seq<Azure.AI.DocumentIntelligence.DocumentAnalysisFeature> * seq<string> * string * seq<Azure.AI.DocumentIntelligence.AnalyzeOutputOption> * Azure.RequestContext -> Azure.Operation<BinaryData>
Public Overridable Function AnalyzeDocument (waitUntil As WaitUntil, modelId As String, content As RequestContent, Optional pages As String = Nothing, Optional locale As String = Nothing, Optional stringIndexType As String = Nothing, Optional features As IEnumerable(Of DocumentAnalysisFeature) = Nothing, Optional queryFields As IEnumerable(Of String) = Nothing, Optional outputContentFormat As String = Nothing, Optional output As IEnumerable(Of AnalyzeOutputOption) = Nothing, Optional context As RequestContext = Nothing) As Operation(Of BinaryData)

Parameters

waitUntil
WaitUntil

Completed if the method should wait to return until the long-running operation has completed on the service; Started if it should return after starting the operation. For more information on long-running operations, please see Azure.Core Long-Running Operation samples.

modelId
String

Unique document model name.

content
RequestContent

The content to send as the body of the request.

pages
String

1-based page numbers to analyze. Ex. "1-3,5,7-9".

locale
String

Locale hint for text recognition and document analysis. Value may contain only the language code (ex. "en", "fr") or BCP 47 language tag (ex. "en-US").

stringIndexType
String

Method used to compute string offset and length. Allowed values: "textElements" | "unicodeCodePoint" | "utf16CodeUnit".

features
IEnumerable<DocumentAnalysisFeature>

List of optional analysis features.

queryFields
IEnumerable<String>

List of additional fields to extract. Ex. "NumberOfGuests,StoreNumber".

outputContentFormat
String

Format of the analyze result top-level content. Allowed values: "text" | "markdown".

output
IEnumerable<AnalyzeOutputOption>

Additional outputs to generate during analysis.

context
RequestContext

The request context, which can override default behaviors of the client pipeline on a per-call basis.

Returns

The Operation representing an asynchronous operation on the service.

Exceptions

modelId is null.

modelId is an empty string, and was expected to be non-empty.

Service returned a non-success status code.

Examples

This sample shows how to call AnalyzeDocument and parse the result.

Uri endpoint = new Uri("<endpoint>");
AzureKeyCredential credential = new AzureKeyCredential("<key>");
DocumentIntelligenceClient client = new DocumentIntelligenceClient(endpoint, credential);

using RequestContent content = RequestContent.Create(new
{
    base64Source = "e2Jhc2U2NEVuY29kZWRQZGZ9",
});
Operation<BinaryData> operation = client.AnalyzeDocument(WaitUntil.Completed, "prebuilt-layout", content);
BinaryData responseData = operation.Value;

JsonElement result = JsonDocument.Parse(responseData.ToStream()).RootElement;
Console.WriteLine(result.GetProperty("apiVersion").ToString());
Console.WriteLine(result.GetProperty("modelId").ToString());
Console.WriteLine(result.GetProperty("stringIndexType").ToString());
Console.WriteLine(result.GetProperty("content").ToString());
Console.WriteLine(result.GetProperty("pages")[0].GetProperty("pageNumber").ToString());
Console.WriteLine(result.GetProperty("pages")[0].GetProperty("spans")[0].GetProperty("offset").ToString());
Console.WriteLine(result.GetProperty("pages")[0].GetProperty("spans")[0].GetProperty("length").ToString());

This sample shows how to call AnalyzeDocument and parse the result.

Uri endpoint = new Uri("<endpoint>");
AzureKeyCredential credential = new AzureKeyCredential("<key>");
DocumentIntelligenceClient client = new DocumentIntelligenceClient(endpoint, credential);

using RequestContent content = RequestContent.Create(new
{
    urlSource = "http://host.com/doc.pdf",
});
Operation<BinaryData> operation = client.AnalyzeDocument(WaitUntil.Completed, "customModel", content);
BinaryData responseData = operation.Value;

JsonElement result = JsonDocument.Parse(responseData.ToStream()).RootElement;
Console.WriteLine(result.GetProperty("apiVersion").ToString());
Console.WriteLine(result.GetProperty("modelId").ToString());
Console.WriteLine(result.GetProperty("stringIndexType").ToString());
Console.WriteLine(result.GetProperty("content").ToString());
Console.WriteLine(result.GetProperty("pages")[0].GetProperty("pageNumber").ToString());
Console.WriteLine(result.GetProperty("pages")[0].GetProperty("spans")[0].GetProperty("offset").ToString());
Console.WriteLine(result.GetProperty("pages")[0].GetProperty("spans")[0].GetProperty("length").ToString());

Applies to

AnalyzeDocument(WaitUntil, String, AnalyzeDocumentContent, String, String, Nullable<StringIndexType>, IEnumerable<DocumentAnalysisFeature>, IEnumerable<String>, Nullable<ContentFormat>, IEnumerable<AnalyzeOutputOption>, CancellationToken)

Source:
DocumentIntelligenceClient.cs

Analyzes document with document model.

public virtual Azure.Operation<Azure.AI.DocumentIntelligence.AnalyzeResult> AnalyzeDocument (Azure.WaitUntil waitUntil, string modelId, Azure.AI.DocumentIntelligence.AnalyzeDocumentContent analyzeRequest = default, string pages = default, string locale = default, Azure.AI.DocumentIntelligence.StringIndexType? stringIndexType = default, System.Collections.Generic.IEnumerable<Azure.AI.DocumentIntelligence.DocumentAnalysisFeature> features = default, System.Collections.Generic.IEnumerable<string> queryFields = default, Azure.AI.DocumentIntelligence.ContentFormat? outputContentFormat = default, System.Collections.Generic.IEnumerable<Azure.AI.DocumentIntelligence.AnalyzeOutputOption> output = default, System.Threading.CancellationToken cancellationToken = default);
abstract member AnalyzeDocument : Azure.WaitUntil * string * Azure.AI.DocumentIntelligence.AnalyzeDocumentContent * string * string * Nullable<Azure.AI.DocumentIntelligence.StringIndexType> * seq<Azure.AI.DocumentIntelligence.DocumentAnalysisFeature> * seq<string> * Nullable<Azure.AI.DocumentIntelligence.ContentFormat> * seq<Azure.AI.DocumentIntelligence.AnalyzeOutputOption> * System.Threading.CancellationToken -> Azure.Operation<Azure.AI.DocumentIntelligence.AnalyzeResult>
override this.AnalyzeDocument : Azure.WaitUntil * string * Azure.AI.DocumentIntelligence.AnalyzeDocumentContent * string * string * Nullable<Azure.AI.DocumentIntelligence.StringIndexType> * seq<Azure.AI.DocumentIntelligence.DocumentAnalysisFeature> * seq<string> * Nullable<Azure.AI.DocumentIntelligence.ContentFormat> * seq<Azure.AI.DocumentIntelligence.AnalyzeOutputOption> * System.Threading.CancellationToken -> Azure.Operation<Azure.AI.DocumentIntelligence.AnalyzeResult>
Public Overridable Function AnalyzeDocument (waitUntil As WaitUntil, modelId As String, Optional analyzeRequest As AnalyzeDocumentContent = Nothing, Optional pages As String = Nothing, Optional locale As String = Nothing, Optional stringIndexType As Nullable(Of StringIndexType) = Nothing, Optional features As IEnumerable(Of DocumentAnalysisFeature) = Nothing, Optional queryFields As IEnumerable(Of String) = Nothing, Optional outputContentFormat As Nullable(Of ContentFormat) = Nothing, Optional output As IEnumerable(Of AnalyzeOutputOption) = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Operation(Of AnalyzeResult)

Parameters

waitUntil
WaitUntil

Completed if the method should wait to return until the long-running operation has completed on the service; Started if it should return after starting the operation. For more information on long-running operations, please see Azure.Core Long-Running Operation samples.

modelId
String

Unique document model name.

analyzeRequest
AnalyzeDocumentContent

Analyze request parameters.

pages
String

List of 1-based page numbers to analyze. Ex. "1-3,5,7-9".

locale
String

Locale hint for text recognition and document analysis. Value may contain only the language code (ex. "en", "fr") or BCP 47 language tag (ex. "en-US").

stringIndexType
Nullable<StringIndexType>

Method used to compute string offset and length.

features
IEnumerable<DocumentAnalysisFeature>

List of optional analysis features.

queryFields
IEnumerable<String>

List of additional fields to extract. Ex. "NumberOfGuests,StoreNumber".

outputContentFormat
Nullable<ContentFormat>

Format of the analyze result top-level content.

output
IEnumerable<AnalyzeOutputOption>

Additional outputs to generate during analysis.

cancellationToken
CancellationToken

The cancellation token to use.

Returns

Exceptions

modelId is null.

modelId is an empty string, and was expected to be non-empty.

Examples

This sample shows how to call AnalyzeDocument.

Uri endpoint = new Uri("<https://my-service.azure.com>");
AzureKeyCredential credential = new AzureKeyCredential("<key>");
DocumentIntelligenceClient client = new DocumentIntelligenceClient(endpoint, credential);

Operation<AnalyzeResult> operation = client.AnalyzeDocument(WaitUntil.Completed, "<modelId>");
AnalyzeResult responseData = operation.Value;

This sample shows how to call AnalyzeDocument with all parameters.

Uri endpoint = new Uri("<https://my-service.azure.com>");
AzureKeyCredential credential = new AzureKeyCredential("<key>");
DocumentIntelligenceClient client = new DocumentIntelligenceClient(endpoint, credential);

AnalyzeDocumentContent analyzeRequest = new AnalyzeDocumentContent
{
    UrlSource = new Uri("http://localhost:3000"),
    Base64Source = BinaryData.FromObjectAsJson(new object()),
};
Operation<AnalyzeResult> operation = client.AnalyzeDocument(WaitUntil.Completed, "<modelId>", analyzeRequest: analyzeRequest, pages: "<pages>", locale: "<locale>", stringIndexType: StringIndexType.TextElements, features: new DocumentAnalysisFeature[] { DocumentAnalysisFeature.OcrHighResolution }, queryFields: new string[] { "<queryFields>" }, outputContentFormat: ContentFormat.Text, output: new AnalyzeOutputOption[] { AnalyzeOutputOption.Pdf });
AnalyzeResult responseData = operation.Value;

Applies to

AnalyzeDocument(WaitUntil, String, Uri, CancellationToken)

Source:
DocumentIntelligenceClient.cs

Analyzes document with document model.

public virtual Azure.Operation<Azure.AI.DocumentIntelligence.AnalyzeResult> AnalyzeDocument (Azure.WaitUntil waitUntil, string modelId, Uri uriSource, System.Threading.CancellationToken cancellationToken = default);
abstract member AnalyzeDocument : Azure.WaitUntil * string * Uri * System.Threading.CancellationToken -> Azure.Operation<Azure.AI.DocumentIntelligence.AnalyzeResult>
override this.AnalyzeDocument : Azure.WaitUntil * string * Uri * System.Threading.CancellationToken -> Azure.Operation<Azure.AI.DocumentIntelligence.AnalyzeResult>
Public Overridable Function AnalyzeDocument (waitUntil As WaitUntil, modelId As String, uriSource As Uri, Optional cancellationToken As CancellationToken = Nothing) As Operation(Of AnalyzeResult)

Parameters

waitUntil
WaitUntil

Completed if the method should wait to return until the long-running operation has completed on the service; Started if it should return after starting the operation. For more information on long-running operations, please see Azure.Core Long-Running Operation samples.

modelId
String

Unique document model name.

uriSource
Uri

Document URL to analyze.

cancellationToken
CancellationToken

The cancellation token to use.

Returns

Exceptions

modelId or uriSource is null.

modelId is an empty string, and was expected to be non-empty.

Applies to

AnalyzeDocument(WaitUntil, String, BinaryData, CancellationToken)

Source:
DocumentIntelligenceClient.cs

Analyzes document with document model.

public virtual Azure.Operation<Azure.AI.DocumentIntelligence.AnalyzeResult> AnalyzeDocument (Azure.WaitUntil waitUntil, string modelId, BinaryData bytesSource, System.Threading.CancellationToken cancellationToken = default);
abstract member AnalyzeDocument : Azure.WaitUntil * string * BinaryData * System.Threading.CancellationToken -> Azure.Operation<Azure.AI.DocumentIntelligence.AnalyzeResult>
override this.AnalyzeDocument : Azure.WaitUntil * string * BinaryData * System.Threading.CancellationToken -> Azure.Operation<Azure.AI.DocumentIntelligence.AnalyzeResult>
Public Overridable Function AnalyzeDocument (waitUntil As WaitUntil, modelId As String, bytesSource As BinaryData, Optional cancellationToken As CancellationToken = Nothing) As Operation(Of AnalyzeResult)

Parameters

waitUntil
WaitUntil

Completed if the method should wait to return until the long-running operation has completed on the service; Started if it should return after starting the operation. For more information on long-running operations, please see Azure.Core Long-Running Operation samples.

modelId
String

Unique document model name.

bytesSource
BinaryData

Bytes of the document to analyze.

To assign a byte[] to this property use FromBytes(Byte[]). The byte[] will be serialized to a Base64 encoded string.

Examples:

  • BinaryData.FromBytes(new byte[] { 1, 2, 3 }): Creates a payload of "AQID".

cancellationToken
CancellationToken

The cancellation token to use.

Returns

Exceptions

modelId or bytesSource is null.

modelId is an empty string, and was expected to be non-empty.

Applies to

AnalyzeDocument(WaitUntil, AnalyzeDocumentOptions, CancellationToken)

Source:
DocumentIntelligenceClient.cs

Analyzes document with document model.

public virtual Azure.Operation<Azure.AI.DocumentIntelligence.AnalyzeResult> AnalyzeDocument (Azure.WaitUntil waitUntil, Azure.AI.DocumentIntelligence.AnalyzeDocumentOptions options, System.Threading.CancellationToken cancellationToken = default);
abstract member AnalyzeDocument : Azure.WaitUntil * Azure.AI.DocumentIntelligence.AnalyzeDocumentOptions * System.Threading.CancellationToken -> Azure.Operation<Azure.AI.DocumentIntelligence.AnalyzeResult>
override this.AnalyzeDocument : Azure.WaitUntil * Azure.AI.DocumentIntelligence.AnalyzeDocumentOptions * System.Threading.CancellationToken -> Azure.Operation<Azure.AI.DocumentIntelligence.AnalyzeResult>
Public Overridable Function AnalyzeDocument (waitUntil As WaitUntil, options As AnalyzeDocumentOptions, Optional cancellationToken As CancellationToken = Nothing) As Operation(Of AnalyzeResult)

Parameters

waitUntil
WaitUntil

Completed if the method should wait to return until the long-running operation has completed on the service; Started if it should return after starting the operation. For more information on long-running operations, please see Azure.Core Long-Running Operation samples.

options
AnalyzeDocumentOptions

Analyze request options.

cancellationToken
CancellationToken

The cancellation token to use.

Returns

Exceptions

options is null.

Examples

This sample shows how to call AnalyzeDocument.

Uri endpoint = new Uri("<endpoint>");
AzureKeyCredential credential = new AzureKeyCredential("<key>");
DocumentIntelligenceClient client = new DocumentIntelligenceClient(endpoint, credential);

AnalyzeDocumentOptions analyzeRequest = new AnalyzeDocumentOptions();
Operation<AnalyzeResult> operation = client.AnalyzeDocument(WaitUntil.Completed, "prebuilt-layout", analyzeRequest);
AnalyzeResult responseData = operation.Value;

This sample shows how to call AnalyzeDocument.

Uri endpoint = new Uri("<endpoint>");
AzureKeyCredential credential = new AzureKeyCredential("<key>");
DocumentIntelligenceClient client = new DocumentIntelligenceClient(endpoint, credential);

AnalyzeDocumentOptions analyzeRequest = new AnalyzeDocumentOptions();
Operation<AnalyzeResult> operation = client.AnalyzeDocument(WaitUntil.Completed, "customModel", analyzeRequest);
AnalyzeResult responseData = operation.Value;

Applies to