Compartilhar via


TextAnalysisClient.AnalyzeTextAsync Method

Definition

Overloads

AnalyzeTextAsync(AnalyzeTextInput, Nullable<Boolean>, CancellationToken)

Request text analysis over a collection of documents.

AnalyzeTextAsync(RequestContent, Nullable<Boolean>, RequestContext)

[Protocol Method] Request text analysis over a collection of documents.

AnalyzeTextAsync(AnalyzeTextInput, Nullable<Boolean>, CancellationToken)

Source:
TextAnalysisClient.cs

Request text analysis over a collection of documents.

public virtual System.Threading.Tasks.Task<Azure.Response<Azure.AI.Language.Text.AnalyzeTextResult>> AnalyzeTextAsync (Azure.AI.Language.Text.AnalyzeTextInput analyzeTextInput, bool? showStatistics = default, System.Threading.CancellationToken cancellationToken = default);
abstract member AnalyzeTextAsync : Azure.AI.Language.Text.AnalyzeTextInput * Nullable<bool> * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Azure.Response<Azure.AI.Language.Text.AnalyzeTextResult>>
override this.AnalyzeTextAsync : Azure.AI.Language.Text.AnalyzeTextInput * Nullable<bool> * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Azure.Response<Azure.AI.Language.Text.AnalyzeTextResult>>
Public Overridable Function AnalyzeTextAsync (analyzeTextInput As AnalyzeTextInput, Optional showStatistics As Nullable(Of Boolean) = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of Response(Of AnalyzeTextResult))

Parameters

analyzeTextInput
AnalyzeTextInput

The input documents to analyze.

showStatistics
Nullable<Boolean>

(Optional) if set to true, response will contain request and document level statistics.

cancellationToken
CancellationToken

The cancellation token to use.

Returns

Exceptions

analyzeTextInput is null.

Examples

This sample shows how to call AnalyzeTextAsync.

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

AnalyzeTextInput analyzeTextInput = new TextDynamicClassificationInput();
Response<AnalyzeTextResult> response = await client.AnalyzeTextAsync(analyzeTextInput);

This sample shows how to call AnalyzeTextAsync with all parameters.

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

AnalyzeTextInput analyzeTextInput = new TextDynamicClassificationInput
{
    TextInput = new MultiLanguageTextInput
    {
        MultiLanguageInputs = {new MultiLanguageInput("<id>", "<text>")
        {
            Language = "<language>",
        }},
    },
    ActionContent = new DynamicClassificationActionContent(new string[] { "<categories>" })
    {
        LoggingOptOut = true,
        ModelVersion = "<modelVersion>",
        ClassificationType = ClassificationType.Multi,
    },
};
Response<AnalyzeTextResult> response = await client.AnalyzeTextAsync(analyzeTextInput, showStatistics: true);

Applies to

AnalyzeTextAsync(RequestContent, Nullable<Boolean>, RequestContext)

Source:
TextAnalysisClient.cs

[Protocol Method] Request text analysis over a collection of documents.

public virtual System.Threading.Tasks.Task<Azure.Response> AnalyzeTextAsync (Azure.Core.RequestContent content, bool? showStatistics = default, Azure.RequestContext context = default);
abstract member AnalyzeTextAsync : Azure.Core.RequestContent * Nullable<bool> * Azure.RequestContext -> System.Threading.Tasks.Task<Azure.Response>
override this.AnalyzeTextAsync : Azure.Core.RequestContent * Nullable<bool> * Azure.RequestContext -> System.Threading.Tasks.Task<Azure.Response>
Public Overridable Function AnalyzeTextAsync (content As RequestContent, Optional showStatistics As Nullable(Of Boolean) = Nothing, Optional context As RequestContext = Nothing) As Task(Of Response)

Parameters

content
RequestContent

The content to send as the body of the request.

showStatistics
Nullable<Boolean>

(Optional) if set to true, response will contain request and document level statistics.

context
RequestContext

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

Returns

The response returned from the service.

Exceptions

content is null.

Service returned a non-success status code.

Examples

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

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

using RequestContent content = RequestContent.Create(new
{
    kind = "DynamicClassification",
});
Response response = await client.AnalyzeTextAsync(content);

JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement;
Console.WriteLine(result.GetProperty("kind").ToString());

This sample shows how to call AnalyzeTextAsync with all parameters and request content and parse the result.

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

using RequestContent content = RequestContent.Create(new
{
    kind = "DynamicClassification",
    analysisInput = new
    {
        documents = new object[]
        {
            new
            {
                id = "<id>",
                text = "<text>",
                language = "<language>",
            }
        },
    },
    parameters = new
    {
        loggingOptOut = true,
        modelVersion = "<modelVersion>",
        classificationType = "Multi",
        categories = new object[]
        {
            "<categories>"
        },
    },
});
Response response = await client.AnalyzeTextAsync(content, showStatistics: true);

JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement;
Console.WriteLine(result.GetProperty("kind").ToString());

Applies to