diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/README.md b/sdk/textanalytics/Azure.AI.TextAnalytics/README.md index bdf3a11f2cf7..c5c11694c844 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/README.md +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/README.md @@ -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, - 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 { 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 + { + documentA, + documentB, + documentC + }; TextAnalyticsActions batchActions = new TextAnalyticsActions() { @@ -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; @@ -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 diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample_AnalyzeOperation.md b/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample_AnalyzeBatchActions.md similarity index 70% rename from sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample_AnalyzeOperation.md rename to sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample_AnalyzeBatchActions.md index ac27f67d482a..bd7367e45219 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample_AnalyzeOperation.md +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample_AnalyzeBatchActions.md @@ -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 { 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 + { + documentA, + documentB, + documentC + }; TextAnalyticsActions batchActions = new TextAnalyticsActions() { @@ -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; @@ -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 \ No newline at end of file diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample_LROPolling.md b/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample_LROPolling.md index db0928d4c3cd..3734064e8324 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample_LROPolling.md +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample_LROPolling.md @@ -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) * [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) diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample_AnalyzeOperation.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample_AnalyzeOperation.cs index 859353df2596..a3a7f2a3fb76 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample_AnalyzeOperation.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample_AnalyzeOperation.cs @@ -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; @@ -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 { - new TextDocumentInput("1", document) + new TextDocumentInput("1", documentA) + { + Language = "en", + }, + new TextDocumentInput("2", documentB) + { + Language = "en", + }, + new TextDocumentInput("3", documentC) { Language = "en", } @@ -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()) diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample_AnalyzeOperationAsync.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample_AnalyzeOperationAsync.cs index b583324f7e88..9924f58531cf 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample_AnalyzeOperationAsync.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample_AnalyzeOperationAsync.cs @@ -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 { - new TextDocumentInput("1", document) + new TextDocumentInput("1", documentA) + { + Language = "en", + }, + new TextDocumentInput("2", documentB) + { + Language = "en", + }, + new TextDocumentInput("3", documentC) { Language = "en", } diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample_AnalyzeOperationAsync_AutomaticPolling.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample_AnalyzeOperationAsync_AutomaticPolling.cs deleted file mode 100644 index 78c102814d85..000000000000 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample_AnalyzeOperationAsync_AutomaticPolling.cs +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Azure.AI.TextAnalytics.Models; -using Azure.AI.TextAnalytics.Tests; -using Azure.Core.TestFramework; -using NUnit.Framework; - -namespace Azure.AI.TextAnalytics.Samples -{ - [LiveOnly] - public partial class TextAnalyticsSamples: SamplesBase - { - [Test] - public async Task AnalyzeOperationAsync_AutomaticPollingWithSetInterval() - { - string endpoint = TestEnvironment.Endpoint; - string apiKey = TestEnvironment.ApiKey; - - var client = new TextAnalyticsClient(new Uri(endpoint), new AzureKeyCredential(apiKey)); - - #region Snippet:AnalyzeOperationBatchAsyncAutomaticPolling - 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 - { - new TextDocumentInput("1", document) - { - Language = "en", - } - }; - - TextAnalyticsActions batchActions = new TextAnalyticsActions() - { - ExtractKeyPhrasesOptions = new List() { new ExtractKeyPhrasesOptions() }, - RecognizeEntitiesOptions = new List() { new RecognizeEntitiesOptions() }, - RecognizePiiEntitiesOptions = new List() { new RecognizePiiEntitiesOptions() }, - DisplayName = "AnalyzeOperationSample" - }; - - AnalyzeBatchActionsOperation operation = await client.StartAnalyzeBatchActionsAsync(batchDocuments, batchActions); - - TimeSpan pollingInterval = new TimeSpan(1000); - - await operation.WaitForCompletionAsync(pollingInterval); - - await foreach (AnalyzeBatchActionsResult documentsInPage in operation.Value) - { - RecognizeEntitiesResultCollection entitiesResult = documentsInPage.RecognizeEntitiesActionsResults.FirstOrDefault().Result; - - ExtractKeyPhrasesResultCollection keyPhrasesResult = documentsInPage.ExtractKeyPhrasesActionsResults.FirstOrDefault().Result; - - RecognizePiiEntitiesResultCollection piiResult = documentsInPage.RecognizePiiEntitiesActionsResults.FirstOrDefault().Result; - - Console.WriteLine("Recognized Entities"); - - foreach (RecognizeEntitiesResult result in entitiesResult) - { - Console.WriteLine($" Recognized the following {result.Entities.Count} entities:"); - - foreach (CategorizedEntity entity in result.Entities) - { - Console.WriteLine($" Entity: {entity.Text}"); - Console.WriteLine($" Category: {entity.Category}"); - Console.WriteLine($" Offset: {entity.Offset}"); - Console.WriteLine($" ConfidenceScore: {entity.ConfidenceScore}"); - Console.WriteLine($" SubCategory: {entity.SubCategory}"); - } - Console.WriteLine(""); - } - - Console.WriteLine("Recognized PII Entities"); - - foreach (RecognizePiiEntitiesResult result in piiResult) - { - Console.WriteLine($" Recognized the following {result.Entities.Count} PII entities:"); - - foreach (PiiEntity entity in result.Entities) - { - Console.WriteLine($" Entity: {entity.Text}"); - Console.WriteLine($" Category: {entity.Category}"); - Console.WriteLine($" Offset: {entity.Offset}"); - Console.WriteLine($" ConfidenceScore: {entity.ConfidenceScore}"); - Console.WriteLine($" SubCategory: {entity.SubCategory}"); - } - Console.WriteLine(""); - } - - Console.WriteLine("Key Phrases"); - - foreach (ExtractKeyPhrasesResult result in keyPhrasesResult) - { - Console.WriteLine($" Recognized the following {result.KeyPhrases.Count} Keyphrases:"); - - foreach (string keyphrase in result.KeyPhrases) - { - Console.WriteLine($" {keyphrase}"); - } - Console.WriteLine(""); - } - } - } - - #endregion - } -} diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample_AnalyzeOperationAsync_ManualPolling.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample_AnalyzeOperationAsync_ManualPolling.cs deleted file mode 100644 index 910222a141c0..000000000000 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample_AnalyzeOperationAsync_ManualPolling.cs +++ /dev/null @@ -1,125 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Azure.AI.TextAnalytics.Tests; -using Azure.Core.TestFramework; -using NUnit.Framework; - -namespace Azure.AI.TextAnalytics.Samples -{ - [LiveOnly] - public partial class TextAnalyticsSamples: SamplesBase - { - [Test] - public async Task AnalyzeOperationAsync_ManualPolling() - { - string endpoint = TestEnvironment.Endpoint; - string apiKey = TestEnvironment.ApiKey; - - var client = new TextAnalyticsClient(new Uri(endpoint), new AzureKeyCredential(apiKey)); - - #region Snippet:AnalyzeOperationBatchAsyncManualPolling - 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 - { - new TextDocumentInput("1", document) - { - Language = "en", - } - }; - - TextAnalyticsActions batchActions = new TextAnalyticsActions() - { - ExtractKeyPhrasesOptions = new List() { new ExtractKeyPhrasesOptions() }, - RecognizeEntitiesOptions = new List() { new RecognizeEntitiesOptions() }, - RecognizePiiEntitiesOptions = new List() { new RecognizePiiEntitiesOptions() }, - DisplayName = "AnalyzeOperationSample" - }; - - AnalyzeBatchActionsOperation operation = client.StartAnalyzeBatchActions(batchDocuments, batchActions); - - TimeSpan pollingInterval = new TimeSpan(1000); - - while (true) - { - operation.UpdateStatus(); - if (operation.HasCompleted) - { - break; - } - - await Task.Delay(pollingInterval); - } - - await foreach (AnalyzeBatchActionsResult documentsInPage in operation.Value) - { - RecognizeEntitiesResultCollection entitiesResult = documentsInPage.RecognizeEntitiesActionsResults.FirstOrDefault().Result; - - ExtractKeyPhrasesResultCollection keyPhrasesResult = documentsInPage.ExtractKeyPhrasesActionsResults.FirstOrDefault().Result; - - RecognizePiiEntitiesResultCollection piiResult = documentsInPage.RecognizePiiEntitiesActionsResults.FirstOrDefault().Result; - - Console.WriteLine("Recognized Entities"); - - foreach (RecognizeEntitiesResult result in entitiesResult) - { - Console.WriteLine($" Recognized the following {result.Entities.Count} entities:"); - - foreach (CategorizedEntity entity in result.Entities) - { - Console.WriteLine($" Entity: {entity.Text}"); - Console.WriteLine($" Category: {entity.Category}"); - Console.WriteLine($" Offset: {entity.Offset}"); - Console.WriteLine($" ConfidenceScore: {entity.ConfidenceScore}"); - Console.WriteLine($" SubCategory: {entity.SubCategory}"); - } - Console.WriteLine(""); - } - - Console.WriteLine("Recognized PII Entities"); - - foreach (RecognizePiiEntitiesResult result in piiResult) - { - Console.WriteLine($" Recognized the following {result.Entities.Count} PII entities:"); - - foreach (PiiEntity entity in result.Entities) - { - Console.WriteLine($" Entity: {entity.Text}"); - Console.WriteLine($" Category: {entity.Category}"); - Console.WriteLine($" Offset: {entity.Offset}"); - Console.WriteLine($" ConfidenceScore: {entity.ConfidenceScore}"); - Console.WriteLine($" SubCategory: {entity.SubCategory}"); - } - Console.WriteLine(""); - } - - Console.WriteLine("Key Phrases"); - - foreach (ExtractKeyPhrasesResult result in keyPhrasesResult) - { - Console.WriteLine($" Recognized the following {result.KeyPhrases.Count} Keyphrases:"); - - foreach (string keyphrase in result.KeyPhrases) - { - Console.WriteLine($" {keyphrase}"); - } - Console.WriteLine(""); - } - } - } - - #endregion - } -} diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample_AnalyzeOperationBatchConvenience.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample_AnalyzeOperationBatchConvenience.cs index cf09b40adaf5..c1d7c5a00e95 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample_AnalyzeOperationBatchConvenience.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample_AnalyzeOperationBatchConvenience.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading; using System.Threading.Tasks; using Azure.AI.TextAnalytics.Models; using Azure.AI.TextAnalytics.Tests; @@ -16,7 +17,7 @@ namespace Azure.AI.TextAnalytics.Samples public partial class TextAnalyticsSamples: SamplesBase { [Test] - public async Task AnalyzeOperationBatchConvenience() + public void AnalyzeOperationBatchConvenience() { string endpoint = TestEnvironment.Endpoint; string apiKey = TestEnvironment.ApiKey; @@ -24,16 +25,29 @@ public async Task AnalyzeOperationBatchConvenience() var client = new TextAnalyticsClient(new Uri(endpoint), new AzureKeyCredential(apiKey)); #region 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 { document }; + 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 + { + documentA, + documentB, + documentC + }; TextAnalyticsActions batchActions = new TextAnalyticsActions() { @@ -45,7 +59,13 @@ call 312-555-0176 or send email to order@contososteakhouse.com! The only complai AnalyzeBatchActionsOperation operation = client.StartAnalyzeBatchActions(batchDocuments, batchActions); - await operation.WaitForCompletionAsync(); + TimeSpan pollingInterval = new TimeSpan(1000); + + while (!operation.HasCompleted) + { + Thread.Sleep(pollingInterval); + operation.UpdateStatus(); + } foreach (AnalyzeBatchActionsResult documentsInPage in operation.GetValues()) { diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample_AnalyzeOperationBatchConvenienceAsync.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample_AnalyzeOperationBatchConvenienceAsync.cs index e2cc98e737f0..3da88e99e4b1 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample_AnalyzeOperationBatchConvenienceAsync.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample_AnalyzeOperationBatchConvenienceAsync.cs @@ -23,17 +23,30 @@ public async Task AnalyzeOperationBatchConvenienceAsync() var client = new TextAnalyticsClient(new Uri(endpoint), new AzureKeyCredential(apiKey)); - #region Snippet:Sample_AnalyzeOperationBatchConvenienceAsync - 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 { document }; + #region 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 + { + documentA, + documentB, + documentC + }; TextAnalyticsActions batchActions = new TextAnalyticsActions() {