Skip to content

Commit

Permalink
Merge pull request Azure#2 from ZulaMostafa/CLU-Samples
Browse files Browse the repository at this point in the history
CLU Samples Markdowns
  • Loading branch information
AhmedLeithy committed Sep 22, 2021
2 parents 375c8c4 + 05b757f commit cc6da47
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 3 deletions.
@@ -0,0 +1,32 @@
# Ask a question

This sample demonstrates how to analyze an utterance. To get started, you'll need to create a Cognitive Language service endpoint and an API key. See the [README](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/cognitivelanguage/Azure.AI.Language.Conversations/README.md) for links and instructions.

To analyze an utterance, you need to first create a `ConversationAnalysisClient` using an endpoint and API key. These can be stored in an environment variable, configuration setting, or any way that works for your application.

```C# Snippet:ConversationAnalysisClient_Create
Uri endpoint = new Uri("https://myaccount.api.cognitive.microsoft.com");
AzureKeyCredential credential = new AzureKeyCredential("{api-key}");

ConversationAnalysisClient client = new ConversationAnalysisClient(endpoint, credential);
```

Once you have created a client, you can call synchronous or asynchronous methods.

## Synchronous

```C# Snippet:ConversationAnalysis_AnalyzeConversationWithOptions
AnalyzeConversationOptions options = new AnalyzeConversationOptions("Menu", "production", "We'll have 2 plates of seared salmon nigiri.");
Response<AnalyzeConversationResult> response = client.AnalyzeConversation(options);

Console.WriteLine($"Top intent: {response.Value.Prediction.TopIntent}");
```

## Asynchronous

```C# Snippet:ConversationAnalysis_AnalyzeConversationWithOptionsAsync
AnalyzeConversationOptions options = new AnalyzeConversationOptions("Menu", "production", "We'll have 2 plates of seared salmon nigiri.");
Response<AnalyzeConversationResult> response = await client.AnalyzeConversationAsync(options);

Console.WriteLine($"Top intent: {response.Value.Prediction.TopIntent}");
```
@@ -0,0 +1,38 @@
# Ask a question

This sample demonstrates how to analyze an utterance. To get started, you'll need to create a Cognitive Language service endpoint and an API key. See the [README](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/cognitivelanguage/Azure.AI.Language.Conversations/README.md) for links and instructions.

To analyze an utterance, you need to first create a `ConversationAnalysisClient` using an endpoint and API key. These can be stored in an environment variable, configuration setting, or any way that works for your application.

```C# Snippet:ConversationAnalysisClient_Create
Uri endpoint = new Uri("https://myaccount.api.cognitive.microsoft.com");
AzureKeyCredential credential = new AzureKeyCredential("{api-key}");

ConversationAnalysisClient client = new ConversationAnalysisClient(endpoint, credential);
```

Once you have created a client, you can call synchronous or asynchronous methods.

## Synchronous

```C# Snippet:ConversationAnalysis_AnalyzeConversationWithLanguage
AnalyzeConversationOptions options = new AnalyzeConversationOptions("Menu", "production", "Tendremos 2 platos de nigiri de salmón braseado.")
{
anguage = "es"
};
Response<AnalyzeConversationResult> response = client.AnalyzeConversation(options);

Console.WriteLine($"Top intent: {response.Value.Prediction.TopIntent}");
```

## Asynchronous

```C# Snippet:ConversationAnalysis_AnalyzeConversationAsync
AnalyzeConversationOptions options = new AnalyzeConversationOptions("Menu", "production", "Tendremos 2 platos de nigiri de salmón braseado.")
{
anguage = "es"
};
Response<AnalyzeConversationResult> response = await client.AnalyzeConversationAsync(options);

Console.WriteLine($"Top intent: {response.Value.Prediction.TopIntent}");
```
@@ -0,0 +1,76 @@
# Ask a question

This sample demonstrates how to analyze an utterance. To get started, you'll need to create a Cognitive Language service endpoint and an API key. See the [README](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/cognitivelanguage/Azure.AI.Language.Conversations/README.md) for links and instructions.

To analyze an utterance, you need to first create a `ConversationAnalysisClient` using an endpoint and API key. These can be stored in an environment variable, configuration setting, or any way that works for your application.

```C# Snippet:ConversationAnalysisClient_Create
Uri endpoint = new Uri("https://myaccount.api.cognitive.microsoft.com");
AzureKeyCredential credential = new AzureKeyCredential("{api-key}");

ConversationAnalysisClient client = new ConversationAnalysisClient(endpoint, credential);
```

Once you have created a client, you can call synchronous or asynchronous methods.

## Synchronous

```C# Snippet:ConversationAnalysis_AnalyzeConversationDeepstack
Response<AnalyzeConversationResult> response = client.AnalyzeConversation(
"Menu",
"production",
"We'll have 2 plates of seared salmon nigiri.");

DeepstackPrediction deepstackPrediction = response.Value.Prediction as DeepstackPrediction;

Console.WriteLine("Intents:");
foreach (DeepstackIntent intent in deepstackPrediction.Intents)
{
Console.WriteLine($"Category:{intent.Category}");
Console.WriteLine($"Confidence Score:{intent.ConfidenceScore}");
Console.WriteLine();
}

Console.WriteLine("Entities:");
foreach (DeepstackEntity entity in deepstackPrediction.Entities)
{
Console.WriteLine($"Category: {entity.Category}");
Console.WriteLine($"Text: {entity.Text}");
Console.WriteLine($"Offset: {entity.Offset}");
Console.WriteLine($"Length: {entity.Length}");
Console.WriteLine($"Confidence Score: {entity.ConfidenceScore}");
Console.WriteLine();
}
```

## Asynchronous

```C# Snippet:ConversationAnalysis_AnalyzeConversationDeepstackAsync
AnalyzeConversationOptions options = new AnalyzeConversationOptions("We'll have 2 plates of seared salmon nigiri.");

Response<AnalyzeConversationResult> response = await client.AnalyzeConversationAsync(
"Menu",
"production",
"We'll have 2 plates of seared salmon nigiri.");

DeepstackPrediction deepstackPrediction = response.Value.Prediction as DeepstackPrediction;

Console.WriteLine("Intents:");
foreach (DeepstackIntent intent in deepstackPrediction.Intents)
{
Console.WriteLine($"Category:{intent.Category}");
Console.WriteLine($"Confidence Score:{intent.ConfidenceScore}");
Console.WriteLine();
}

Console.WriteLine("Entities:");
foreach (DeepstackEntity entity in deepstackPrediction.Entities)
{
Console.WriteLine($"Category: {entity.Category}");
Console.WriteLine($"Text: {entity.Text}");
Console.WriteLine($"Offset: {entity.Offset}");
Console.WriteLine($"Length: {entity.Length}");
Console.WriteLine($"Confidence Score: {entity.ConfidenceScore}");
Console.WriteLine();
}
```
Expand Up @@ -47,7 +47,7 @@ public async Task AnalyzeConversationWithOptionsAsync()
#if SNIPPET
AnalyzeConversationOptions options = new AnalyzeConversationOptions("Menu",
"production", "We'll have 2 plates of seared salmon nigiri.");
Response<AnalyzeConversationResult> response = client.AnalyzeConversation(options);
Response<AnalyzeConversationResult> response = await client.AnalyzeConversationAsync(options);
#else
AnalyzeConversationOptions options = new AnalyzeConversationOptions(TestEnvironment.ProjectName,
TestEnvironment.DeploymentName, "We'll have 2 plates of seared salmon nigiri.");
Expand Down
Expand Up @@ -56,7 +56,7 @@ public async Task AnalyzeConversationWithLanguageAsync()
{
Language = "es"
};
Response<AnalyzeConversationResult> response = client.AnalyzeConversation(options);
Response<AnalyzeConversationResult> response = await client.AnalyzeConversationAsync(options);
#else
AnalyzeConversationOptions options = new AnalyzeConversationOptions(TestEnvironment.ProjectName,
TestEnvironment.DeploymentName, "Tendremos 2 platos de nigiri de salmón braseado.")
Expand Down
Expand Up @@ -66,7 +66,7 @@ public async Task AnalyzeConversationDeepstackAsync()
#region Snippet:ConversationAnalysis_AnalyzeConversationDeepstackAsync

#if SNIPPET
Response<AnalyzeConversationResult> response = client.AnalyzeConversation(
Response<AnalyzeConversationResult> response = await client.AnalyzeConversationAsync(
"Menu",
"production",
"We'll have 2 plates of seared salmon nigiri.");
Expand Down

0 comments on commit cc6da47

Please sign in to comment.