Compartir a través de


ContentSafetyClient.AnalyzeTextAsync Método

Definición

Sobrecargas

AnalyzeTextAsync(AnalyzeTextOptions, CancellationToken)

Analizar texto.

AnalyzeTextAsync(RequestContent, RequestContext)

[Método Protocol] Analizar texto

AnalyzeTextAsync(AnalyzeTextOptions, CancellationToken)

Analizar texto.

public virtual System.Threading.Tasks.Task<Azure.Response<Azure.AI.ContentSafety.AnalyzeTextResult>> AnalyzeTextAsync (Azure.AI.ContentSafety.AnalyzeTextOptions body, System.Threading.CancellationToken cancellationToken = default);
abstract member AnalyzeTextAsync : Azure.AI.ContentSafety.AnalyzeTextOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Azure.Response<Azure.AI.ContentSafety.AnalyzeTextResult>>
override this.AnalyzeTextAsync : Azure.AI.ContentSafety.AnalyzeTextOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Azure.Response<Azure.AI.ContentSafety.AnalyzeTextResult>>
Public Overridable Function AnalyzeTextAsync (body As AnalyzeTextOptions, Optional cancellationToken As CancellationToken = Nothing) As Task(Of Response(Of AnalyzeTextResult))

Parámetros

body
AnalyzeTextOptions

Solicitud de análisis de texto.

cancellationToken
CancellationToken

Token de cancelación que se va a usar.

Devoluciones

Excepciones

body es null.

Ejemplos

En este ejemplo se muestra cómo llamar a AnalyzeTextAsync con parámetros necesarios.

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

var body = new AnalyzeTextOptions("<text>")
{
    Categories = 
{
        TextCategory.Hate
    },
    BlocklistNames = 
{
        "<null>"
    },
    BreakByBlocklists = true,
};
var result = await client.AnalyzeTextAsync(body);

Comentarios

Una API de sincronización para el análisis de contenido perjudicial para texto. Actualmente, apoyamos cuatro categorías: Odio, SelfHarm, Sexual, Violencia.

Se aplica a

AnalyzeTextAsync(RequestContent, RequestContext)

[Método Protocol] Analizar texto

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

Parámetros

content
RequestContent

Contenido que se va a enviar como el cuerpo de la solicitud.

context
RequestContext

Contexto de solicitud, que puede invalidar los comportamientos predeterminados de la canalización de cliente por llamada.

Devoluciones

Respuesta devuelta por el servicio.

Excepciones

content es null.

El servicio devolvió un código de estado no correcto.

Ejemplos

En este ejemplo se muestra cómo llamar a AnalyzeTextAsync con el contenido de la solicitud necesario y cómo analizar el resultado.

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

var data = new {
    text = "<text>",
};

Response response = await client.AnalyzeTextAsync(RequestContent.Create(data));

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

En este ejemplo se muestra cómo llamar a AnalyzeTextAsync con todo el contenido de la solicitud y cómo analizar el resultado.

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

var data = new {
    text = "<text>",
    categories = new[] {
        "Hate"
    },
    blocklistNames = new[] {
        "<String>"
    },
    breakByBlocklists = true,
};

Response response = await client.AnalyzeTextAsync(RequestContent.Create(data), new RequestContext());

JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement;
Console.WriteLine(result.GetProperty("blocklistsMatchResults")[0].GetProperty("blocklistName").ToString());
Console.WriteLine(result.GetProperty("blocklistsMatchResults")[0].GetProperty("blockItemId").ToString());
Console.WriteLine(result.GetProperty("blocklistsMatchResults")[0].GetProperty("blockItemText").ToString());
Console.WriteLine(result.GetProperty("blocklistsMatchResults")[0].GetProperty("offset").ToString());
Console.WriteLine(result.GetProperty("blocklistsMatchResults")[0].GetProperty("length").ToString());
Console.WriteLine(result.GetProperty("hateResult").GetProperty("category").ToString());
Console.WriteLine(result.GetProperty("hateResult").GetProperty("severity").ToString());
Console.WriteLine(result.GetProperty("selfHarmResult").GetProperty("category").ToString());
Console.WriteLine(result.GetProperty("selfHarmResult").GetProperty("severity").ToString());
Console.WriteLine(result.GetProperty("sexualResult").GetProperty("category").ToString());
Console.WriteLine(result.GetProperty("sexualResult").GetProperty("severity").ToString());
Console.WriteLine(result.GetProperty("violenceResult").GetProperty("category").ToString());
Console.WriteLine(result.GetProperty("violenceResult").GetProperty("severity").ToString());

Se aplica a