Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #17811 Improve samples for Analyze #18524

Merged
merged 4 commits into from
Feb 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 27 additions & 14 deletions sdk/textanalytics/Azure.AI.TextAnalytics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -484,17 +484,30 @@ Text Analytics for health is a containerized service that extracts and labels re
### Run Analyze Operation Asynchronously
The Analyze functionality allows to choose which of the supported Text Analytics features to execute in the same set of documents. Currently the supported features are: entity recognition, key phrase extraction, and Personally Identifiable Information (PII) Recognition. For more information see [How to: Use Text Analytics for analyze operation][analyze_operation_howto].

```C# Snippet:AnalyzeOperationBatchConvenience
string document = @"We went to Contoso Steakhouse located at midtown NYC last week for a dinner party,
maririos marked this conversation as resolved.
Show resolved Hide resolved
and we adore the spot! They provide marvelous food and they have a great menu. The
chief cook happens to be the owner (I think his name is John Doe) and he is super
nice, coming out of the kitchen and greeted us all. We enjoyed very much dining in
the place! The Sirloin steak I ordered was tender and juicy, and the place was impeccably
clean. You can even pre-order from their online menu at www.contososteakhouse.com,
call 312-555-0176 or send email to order@contososteakhouse.com! The only complaint
I have is the food didn't come fast enough. Overall I highly recommend it!";

var batchDocuments = new List<string> { document };
```C# Snippet:AnalyzeOperationBatchConvenienceAsync
string documentA = @"We love this trail and make the trip every year. The views are breathtaking and well
worth the hike! Yesterday was foggy though, so we missed the spectacular views.
We tried again today and it was amazing. Everyone in my family liked the trail although
it was too challenging for the less athletic among us.
Not necessarily recommended for small children.
A hotel close to the trail offers services for childcare in case you want that.";

string documentB = @"Last week we stayed at Hotel Foo to celebrate our anniversary. The staff knew about
our anniversary so they helped me organize a little surprise for my partner.
The room was clean and with the decoration I requested. It was perfect!";

string documentC = @"That was the best day of my life! We went on a 4 day trip where we stayed at Hotel Foo.
They had great amenities that included an indoor pool, a spa, and a bar.
The spa offered couples massages which were really good.
The spa was clean and felt very peaceful. Overall the whole experience was great.
We will definitely come back.";

var batchDocuments = new List<string>
{
documentA,
documentB,
documentC
};

TextAnalyticsActions batchActions = new TextAnalyticsActions()
{
Expand All @@ -504,11 +517,11 @@ The Analyze functionality allows to choose which of the supported Text Analytics
DisplayName = "AnalyzeOperationSample"
};

AnalyzeBatchActionsOperation operation = client.StartAnalyzeBatchActions(batchDocuments, batchActions);
AnalyzeBatchActionsOperation operation = await client.StartAnalyzeBatchActionsAsync(batchDocuments, batchActions);

await operation.WaitForCompletionAsync();

foreach (AnalyzeBatchActionsResult documentsInPage in operation.GetValues())
await foreach (AnalyzeBatchActionsResult documentsInPage in operation.Value)
{
RecognizeEntitiesResultCollection entitiesResult = documentsInPage.RecognizeEntitiesActionsResults.FirstOrDefault().Result;

Expand Down Expand Up @@ -658,7 +671,7 @@ This project has adopted the [Microsoft Open Source Code of Conduct][code_of_con
[dotnet_lro_guidelines]: https://azure.github.io/azure-sdk/dotnet_introduction.html#dotnet-longrunning

[recognize_healthcare_sample]: https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample_RecognizeHealthcareEntities.md
[analyze_operation_sample]: https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample_AnalyzeOperation.md
[analyze_operation_sample]: https://github.com/Azure/azure-sdk-for-net/tree/master/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample_AnalyzeBatchActions.md
[analyze_operation_howto]: https://docs.microsoft.com/azure/cognitive-services/text-analytics/how-tos/text-analytics-how-to-call-api?tabs=analyze
[healthcare]: https://docs.microsoft.com/azure/cognitive-services/text-analytics/how-tos/text-analytics-for-health?tabs=ner
[language_detection]: https://docs.microsoft.com/azure/cognitive-services/Text-Analytics/how-tos/text-analytics-how-to-language-detection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,30 @@ var client = new TextAnalyticsClient(new Uri(endpoint), new AzureKeyCredential(a

To run analyze operation in multiple documents, call `StartAnalyzeOperationBatchAsync` on an `IEnumerable` of strings. The result is a Long Running operation of type `AnalyzeOperation` which polls for the results from the API.

```C# Snippet:AnalyzeOperationBatchConvenience
string document = @"We went to Contoso Steakhouse located at midtown NYC last week for a dinner party,
and we adore the spot! They provide marvelous food and they have a great menu. The
chief cook happens to be the owner (I think his name is John Doe) and he is super
nice, coming out of the kitchen and greeted us all. We enjoyed very much dining in
the place! The Sirloin steak I ordered was tender and juicy, and the place was impeccably
clean. You can even pre-order from their online menu at www.contososteakhouse.com,
call 312-555-0176 or send email to order@contososteakhouse.com! The only complaint
I have is the food didn't come fast enough. Overall I highly recommend it!";

var batchDocuments = new List<string> { document };
```C# Snippet:AnalyzeOperationBatchConvenienceAsync
string documentA = @"We love this trail and make the trip every year. The views are breathtaking and well
worth the hike! Yesterday was foggy though, so we missed the spectacular views.
We tried again today and it was amazing. Everyone in my family liked the trail although
it was too challenging for the less athletic among us.
Not necessarily recommended for small children.
A hotel close to the trail offers services for childcare in case you want that.";

string documentB = @"Last week we stayed at Hotel Foo to celebrate our anniversary. The staff knew about
our anniversary so they helped me organize a little surprise for my partner.
The room was clean and with the decoration I requested. It was perfect!";

string documentC = @"That was the best day of my life! We went on a 4 day trip where we stayed at Hotel Foo.
They had great amenities that included an indoor pool, a spa, and a bar.
The spa offered couples massages which were really good.
The spa was clean and felt very peaceful. Overall the whole experience was great.
We will definitely come back.";

var batchDocuments = new List<string>
{
documentA,
documentB,
documentC
};

TextAnalyticsActions batchActions = new TextAnalyticsActions()
{
Expand All @@ -37,11 +50,11 @@ To run analyze operation in multiple documents, call `StartAnalyzeOperationBatch
DisplayName = "AnalyzeOperationSample"
};

AnalyzeBatchActionsOperation operation = client.StartAnalyzeBatchActions(batchDocuments, batchActions);
AnalyzeBatchActionsOperation operation = await client.StartAnalyzeBatchActionsAsync(batchDocuments, batchActions);

await operation.WaitForCompletionAsync();

foreach (AnalyzeBatchActionsResult documentsInPage in operation.GetValues())
await foreach (AnalyzeBatchActionsResult documentsInPage in operation.Value)
{
RecognizeEntitiesResultCollection entitiesResult = documentsInPage.RecognizeEntitiesActionsResults.FirstOrDefault().Result;

Expand Down Expand Up @@ -103,8 +116,8 @@ To see the full example source files, see:

* [Synchronously AnalyzeOperationBatch ](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample_AnalyzeOperation.cs)
* [Asynchronously AnalyzeOperationBatch ](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample_AnalyzeOperationAsync.cs)
* [Automatic Polling AnalyzeOperation ](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample_AnalyzeOperationAsync_AutomaticPolling.cs)
* [Manual Polling AnalyzeOperation ](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample_AnalyzeOperationAsync_ManualPolling.cs)
* [Synchronously AnalyzeBathActionsConvenience ](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample_AnalyzeOperationBatchConvenience.cs)
* [Asynchronously AnalyzeBathActionsConvenience ](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample_AnalyzeOperationBatchConvenienceAsync.cs)

[DefaultAzureCredential]: https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/identity/Azure.Identity/README.md
[README]: https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/textanalytics/Azure.AI.TextAnalytics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ This method is for users who want to have intermittent code paths during the pol

To see the full example source files, see:

* [Automatic Polling AnalyzeOperation ](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample_AnalyzeOperationAsync_AutomaticPolling.cs)
* [Manual Polling AnalyzeOperation ](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample_AnalyzeOperationAsync_ManualPolling.cs)
* [Automatic Polling AnalyzeOperation ](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample_AnalyzeOperationAsync.cs)
* [Manual Polling AnalyzeOperation ](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample_AnalyzeOperation.cs)
maririos marked this conversation as resolved.
Show resolved Hide resolved
* [Automatic Polling HealthcareOperation ](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample_HealthcareAsync_AutomaticPolling.cs)
* [Manual Polling HealthcareOperation ](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample_HealthcareAsync_ManualPolling.cs)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Threading;
using Azure.AI.TextAnalytics.Tests;
using Azure.Core.TestFramework;
using NUnit.Framework;
Expand All @@ -24,17 +24,34 @@ public void AnalyzeOperation()

#region Snippet:TextAnalyticsAnalyzeOperation

string document = @"We went to Contoso Steakhouse located at midtown NYC last week for a dinner party,
and we adore the spot! They provide marvelous food and they have a great menu. The
chief cook happens to be the owner (I think his name is John Doe) and he is super
nice, coming out of the kitchen and greeted us all. We enjoyed very much dining in
the place! The Sirloin steak I ordered was tender and juicy, and the place was impeccably
clean. You can even pre-order from their online menu at www.contososteakhouse.com,
call 312-555-0176 or send email to order@contososteakhouse.com! The only complaint
I have is the food didn't come fast enough. Overall I highly recommend it!";
string documentA = @"We love this trail and make the trip every year. The views are breathtaking and well
worth the hike! Yesterday was foggy though, so we missed the spectacular views.
We tried again today and it was amazing. Everyone in my family liked the trail although
it was too challenging for the less athletic among us.
Not necessarily recommended for small children.
A hotel close to the trail offers services for childcare in case you want that.";

string documentB = @"Last week we stayed at Hotel Foo to celebrate our anniversary. The staff knew about
our anniversary so they helped me organize a little surprise for my partner.
The room was clean and with the decoration I requested. It was perfect!";

string documentC = @"That was the best day of my life! We went on a 4 day trip where we stayed at Hotel Foo.
They had great amenities that included an indoor pool, a spa, and a bar.
The spa offered couples massages which were really good.
The spa was clean and felt very peaceful. Overall the whole experience was great.
We will definitely come back.";

var batchDocuments = new List<TextDocumentInput>
{
new TextDocumentInput("1", document)
new TextDocumentInput("1", documentA)
{
Language = "en",
},
new TextDocumentInput("2", documentB)
{
Language = "en",
},
new TextDocumentInput("3", documentC)
{
Language = "en",
}
Expand All @@ -52,15 +69,10 @@ call 312-555-0176 or send email to order@contososteakhouse.com! The only complai

TimeSpan pollingInterval = new TimeSpan(1000);

while (true)
while (!operation.HasCompleted)
{
Thread.Sleep(pollingInterval);
operation.UpdateStatus();
if (operation.HasCompleted)
{
break;
}

Task.Delay(pollingInterval);
}

foreach (AnalyzeBatchActionsResult documentsInPage in operation.GetValues())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,34 @@ public async Task AnalyzeOperationAsync()
var client = new TextAnalyticsClient(new Uri(endpoint), new AzureKeyCredential(apiKey));

#region Snippet:AnalyzeOperationBatchAsync
string document = @"We went to Contoso Steakhouse located at midtown NYC last week for a dinner party,
and we adore the spot! They provide marvelous food and they have a great menu. The
chief cook happens to be the owner (I think his name is John Doe) and he is super
nice, coming out of the kitchen and greeted us all. We enjoyed very much dining in
the place! The Sirloin steak I ordered was tender and juicy, and the place was impeccably
clean. You can even pre-order from their online menu at www.contososteakhouse.com,
call 312-555-0176 or send email to order@contososteakhouse.com! The only complaint
I have is the food didn't come fast enough. Overall I highly recommend it!";
string documentA = @"We love this trail and make the trip every year. The views are breathtaking and well
worth the hike! Yesterday was foggy though, so we missed the spectacular views.
We tried again today and it was amazing. Everyone in my family liked the trail although
it was too challenging for the less athletic among us.
Not necessarily recommended for small children.
A hotel close to the trail offers services for childcare in case you want that.";

string documentB = @"Last week we stayed at Hotel Foo to celebrate our anniversary. The staff knew about
our anniversary so they helped me organize a little surprise for my partner.
The room was clean and with the decoration I requested. It was perfect!";

string documentC = @"That was the best day of my life! We went on a 4 day trip where we stayed at Hotel Foo.
They had great amenities that included an indoor pool, a spa, and a bar.
The spa offered couples massages which were really good.
The spa was clean and felt very peaceful. Overall the whole experience was great.
We will definitely come back.";

var batchDocuments = new List<TextDocumentInput>
{
new TextDocumentInput("1", document)
new TextDocumentInput("1", documentA)
{
Language = "en",
},
new TextDocumentInput("2", documentB)
{
Language = "en",
},
new TextDocumentInput("3", documentC)
{
Language = "en",
}
Expand Down
Loading