TextAnalysisClient.AnalyzeTextAsync Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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.
(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.
- This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
- Please try the simpler AnalyzeTextAsync(AnalyzeTextInput, Nullable<Boolean>, CancellationToken) convenience overload with strongly typed models first.
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.
(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
Azure SDK for .NET