From 76de6244c684ca4268287c61431e24466319717b Mon Sep 17 00:00:00 2001 From: Caio Saldanha Date: Wed, 4 Aug 2021 07:14:24 -0700 Subject: [PATCH 1/7] Added Async summarization sample --- .../samples/Sample8_ExtractSummaryAsync.cs | 107 ++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample8_ExtractSummaryAsync.cs diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample8_ExtractSummaryAsync.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample8_ExtractSummaryAsync.cs new file mode 100644 index 0000000000000..0766487e8331b --- /dev/null +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample8_ExtractSummaryAsync.cs @@ -0,0 +1,107 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +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 ExtractSummaryAsync() + { + // create a text analytics client + string endpoint = TestEnvironment.Endpoint; + string apiKey = TestEnvironment.ApiKey; + var client = new TextAnalyticsClient(new Uri(endpoint), new AzureKeyCredential(apiKey)); + + // get input document + string document = @"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."; + + // prepare analyze operation input + var batchDocuments = new List + { + new TextDocumentInput("1", document) + { + Language = "en", + } + }; + + var summaryAction = new ExtractSummaryAction() + { + MaxSentenceCount = 5, + OrderBy = SummarySentencesOrder.Rank + }; + + TextAnalyticsActions actions = new TextAnalyticsActions() + { + ExtractSummaryActions = new List() { summaryAction } + }; + + // start analysis process + AnalyzeActionsOperation operation = await client.StartAnalyzeActionsAsync(batchDocuments, actions); + + await operation.WaitForCompletionAsync(); + + // view operation status + Console.WriteLine($"AnalyzeActions operation has completed"); + Console.WriteLine(); + + Console.WriteLine($"Created On : {operation.CreatedOn}"); + Console.WriteLine($"Expires On : {operation.ExpiresOn}"); + Console.WriteLine($"Id : {operation.Id}"); + Console.WriteLine($"Status : {operation.Status}"); + Console.WriteLine($"Last Modified: {operation.LastModified}"); + Console.WriteLine(); + + // view operation results + await foreach (AnalyzeActionsResult documentsInPage in operation.Value) + { + IReadOnlyCollection summaryResults = documentsInPage.ExtractSummaryResults; + + foreach (ExtractSummaryActionResult summaryActionResults in summaryResults) + { + if (summaryActionResults.HasError) + { + Console.WriteLine($" Error!"); + Console.WriteLine($" Action error code: {summaryActionResults.Error.ErrorCode}."); + Console.WriteLine($" Message: {summaryActionResults.Error.Message}"); + continue; + } + + foreach (ExtractSummaryResult documentResults in summaryActionResults.DocumentsResults) + { + if (documentResults.HasError) + { + Console.WriteLine($" Error!"); + Console.WriteLine($" Document error code: {documentResults.Error.ErrorCode}."); + Console.WriteLine($" Message: {documentResults.Error.Message}"); + continue; + } + + Console.WriteLine($" Extracted the following {documentResults.Sentences.Count} sentence(s):"); + Console.WriteLine(); + + foreach (SummarySentence sentence in documentResults.Sentences) + { + Console.WriteLine($" Sentence: {sentence.Text}"); + Console.WriteLine($" Rank Score: {sentence.RankScore}"); + Console.WriteLine($" Offset: {sentence.Offset}"); + Console.WriteLine($" Length: {sentence.Length}"); + Console.WriteLine(); + } + } + } + } + } + } +} From 28f2e5acbba900b5318e38c933f857060994b2af Mon Sep 17 00:00:00 2001 From: Caio Saldanha Date: Wed, 4 Aug 2021 07:39:10 -0700 Subject: [PATCH 2/7] Added samples for all scenarios --- .../tests/samples/Sample8_ExtractSummary.cs | 126 ++++++++++++++++++ .../samples/Sample8_ExtractSummaryAsync.cs | 14 +- .../Sample8_ExtractSummaryConvenience.cs | 117 ++++++++++++++++ .../Sample8_ExtractSummaryConvenienceAsync.cs | 104 +++++++++++++++ 4 files changed, 357 insertions(+), 4 deletions(-) create mode 100644 sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample8_ExtractSummary.cs create mode 100644 sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample8_ExtractSummaryConvenience.cs create mode 100644 sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample8_ExtractSummaryConvenienceAsync.cs diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample8_ExtractSummary.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample8_ExtractSummary.cs new file mode 100644 index 0000000000000..5f85f5d48af01 --- /dev/null +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample8_ExtractSummary.cs @@ -0,0 +1,126 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Threading; +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 void ExtractSummary() + { + // create a text analytics client + string endpoint = TestEnvironment.Endpoint; + string apiKey = TestEnvironment.ApiKey; + var client = new TextAnalyticsClient(new Uri(endpoint), new AzureKeyCredential(apiKey)); + + // get input document + string document = @"Windows 365 was in the works before COVID-19 sent companies around the world on a scramble to secure solutions to support employees suddenly forced to work from home, but “what really put the firecracker behind it was the pandemic, it accelerated everything,” McKelvey said. She explained that customers were asking, “’How do we create an experience for people that makes them still feel connected to the company without the physical presence of being there?” + In this new world of Windows 365, remote workers flip the lid on their laptop, bootup the family workstation or clip a keyboard onto a tablet, launch a native app or modern web browser and login to their Windows 365 account.From there, their Cloud PC appears with their background, apps, settings and content just as they left it when they last were last there – in the office, at home or a coffee shop. + And then, when you’re done, you’re done.You won’t have any issues around security because you’re not saving anything on your device,” McKelvey said, noting that all the data is stored in the cloud. + The ability to login to a Cloud PC from anywhere on any device is part of Microsoft’s larger strategy around tailoring products such as Microsoft Teams and Microsoft 365 for the post-pandemic hybrid workforce of the future, she added. It enables employees accustomed to working from home to continue working from home; it enables companies to hire interns from halfway around the world; it allows startups to scale without requiring IT expertise. + “I think this will be interesting for those organizations who, for whatever reason, have shied away from virtualization.This is giving them an opportunity to try it in a way that their regular, everyday endpoint admin could manage,” McKelvey said. + The simplicity of Windows 365 won over Dean Wells, the corporate chief information officer for the Government of Nunavut. His team previously attempted to deploy a traditional virtual desktop infrastructure and found it inefficient and unsustainable given the limitations of low-bandwidth satellite internet and the constant need for IT staff to manage the network and infrastructure. + We didn’t run it for very long,” he said. “It didn’t turn out the way we had hoped.So, we actually had terminated the project and rolled back out to just regular PCs.” + He re-evaluated this decision after the Government of Nunavut was hit by a ransomware attack in November 2019 that took down everything from the phone system to the government’s servers. Microsoft helped rebuild the system, moving the government to Teams, SharePoint, OneDrive and Microsoft 365. Manchester’s team recruited the Government of Nunavut to pilot Windows 365. Wells was intrigued, especially by the ability to manage the elastic workforce securely and seamlessly. + “The impact that I believe we are finding, and the impact that we’re going to find going forward, is being able to access specialists from outside the territory and organizations outside the territory to come in and help us with our projects, being able to get people on staff with us to help us deliver the day-to-day expertise that we need to run the government,” he said. + “Being able to improve healthcare, being able to improve education, economic development is going to improve the quality of life in the communities.”"; + + // prepare analyze operation input + var batchDocuments = new List + { + new TextDocumentInput("1", document) + { + Language = "en", + } + }; + + var summaryAction = new ExtractSummaryAction() + { + MaxSentenceCount = 5, + OrderBy = SummarySentencesOrder.Rank + }; + + TextAnalyticsActions actions = new TextAnalyticsActions() + { + ExtractSummaryActions = new List() { summaryAction } + }; + + // start analysis process + AnalyzeActionsOperation operation = client.StartAnalyzeActions(batchDocuments, actions); + + // wait for completion with manual polling + TimeSpan pollingInterval = new TimeSpan(1000); + + while (true) + { + Console.WriteLine($"Status: {operation.Status}"); + operation.UpdateStatus(); + if (operation.HasCompleted) + { + break; + } + + Thread.Sleep(pollingInterval); + } + + // view operation status + Console.WriteLine($"AnalyzeActions operation has completed"); + Console.WriteLine(); + + Console.WriteLine($"Created On : {operation.CreatedOn}"); + Console.WriteLine($"Expires On : {operation.ExpiresOn}"); + Console.WriteLine($"Id : {operation.Id}"); + Console.WriteLine($"Status : {operation.Status}"); + Console.WriteLine($"Last Modified: {operation.LastModified}"); + Console.WriteLine(); + + // view operation results + foreach (AnalyzeActionsResult documentsInPage in operation.GetValues()) + { + IReadOnlyCollection summaryResults = documentsInPage.ExtractSummaryResults; + + foreach (ExtractSummaryActionResult summaryActionResults in summaryResults) + { + if (summaryActionResults.HasError) + { + Console.WriteLine($" Error!"); + Console.WriteLine($" Action error code: {summaryActionResults.Error.ErrorCode}."); + Console.WriteLine($" Message: {summaryActionResults.Error.Message}"); + continue; + } + + foreach (ExtractSummaryResult documentResults in summaryActionResults.DocumentsResults) + { + if (documentResults.HasError) + { + Console.WriteLine($" Error!"); + Console.WriteLine($" Document error code: {documentResults.Error.ErrorCode}."); + Console.WriteLine($" Message: {documentResults.Error.Message}"); + continue; + } + + Console.WriteLine($" Extracted the following {documentResults.Sentences.Count} sentence(s):"); + Console.WriteLine(); + + foreach (SummarySentence sentence in documentResults.Sentences) + { + Console.WriteLine($" Sentence: {sentence.Text}"); + Console.WriteLine($" Rank Score: {sentence.RankScore}"); + Console.WriteLine($" Offset: {sentence.Offset}"); + Console.WriteLine($" Length: {sentence.Length}"); + Console.WriteLine(); + } + } + } + } + } + } +} diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample8_ExtractSummaryAsync.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample8_ExtractSummaryAsync.cs index 0766487e8331b..6a88c05000db7 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample8_ExtractSummaryAsync.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample8_ExtractSummaryAsync.cs @@ -22,10 +22,16 @@ public async Task ExtractSummaryAsync() var client = new TextAnalyticsClient(new Uri(endpoint), new AzureKeyCredential(apiKey)); // get input document - string document = @"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."; + string document = @"Windows 365 was in the works before COVID-19 sent companies around the world on a scramble to secure solutions to support employees suddenly forced to work from home, but “what really put the firecracker behind it was the pandemic, it accelerated everything,” McKelvey said. She explained that customers were asking, “’How do we create an experience for people that makes them still feel connected to the company without the physical presence of being there?” + In this new world of Windows 365, remote workers flip the lid on their laptop, bootup the family workstation or clip a keyboard onto a tablet, launch a native app or modern web browser and login to their Windows 365 account.From there, their Cloud PC appears with their background, apps, settings and content just as they left it when they last were last there – in the office, at home or a coffee shop. + And then, when you’re done, you’re done.You won’t have any issues around security because you’re not saving anything on your device,” McKelvey said, noting that all the data is stored in the cloud. + The ability to login to a Cloud PC from anywhere on any device is part of Microsoft’s larger strategy around tailoring products such as Microsoft Teams and Microsoft 365 for the post-pandemic hybrid workforce of the future, she added. It enables employees accustomed to working from home to continue working from home; it enables companies to hire interns from halfway around the world; it allows startups to scale without requiring IT expertise. + “I think this will be interesting for those organizations who, for whatever reason, have shied away from virtualization.This is giving them an opportunity to try it in a way that their regular, everyday endpoint admin could manage,” McKelvey said. + The simplicity of Windows 365 won over Dean Wells, the corporate chief information officer for the Government of Nunavut. His team previously attempted to deploy a traditional virtual desktop infrastructure and found it inefficient and unsustainable given the limitations of low-bandwidth satellite internet and the constant need for IT staff to manage the network and infrastructure. + We didn’t run it for very long,” he said. “It didn’t turn out the way we had hoped.So, we actually had terminated the project and rolled back out to just regular PCs.” + He re-evaluated this decision after the Government of Nunavut was hit by a ransomware attack in November 2019 that took down everything from the phone system to the government’s servers. Microsoft helped rebuild the system, moving the government to Teams, SharePoint, OneDrive and Microsoft 365. Manchester’s team recruited the Government of Nunavut to pilot Windows 365. Wells was intrigued, especially by the ability to manage the elastic workforce securely and seamlessly. + “The impact that I believe we are finding, and the impact that we’re going to find going forward, is being able to access specialists from outside the territory and organizations outside the territory to come in and help us with our projects, being able to get people on staff with us to help us deliver the day-to-day expertise that we need to run the government,” he said. + “Being able to improve healthcare, being able to improve education, economic development is going to improve the quality of life in the communities.”"; // prepare analyze operation input var batchDocuments = new List diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample8_ExtractSummaryConvenience.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample8_ExtractSummaryConvenience.cs new file mode 100644 index 0000000000000..a5aa4fb90648b --- /dev/null +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample8_ExtractSummaryConvenience.cs @@ -0,0 +1,117 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Threading; +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 void ExtractSummaryConvenience() + { + // create a text analytics client + string endpoint = TestEnvironment.Endpoint; + string apiKey = TestEnvironment.ApiKey; + var client = new TextAnalyticsClient(new Uri(endpoint), new AzureKeyCredential(apiKey)); + + // get input document + string document = @"Windows 365 was in the works before COVID-19 sent companies around the world on a scramble to secure solutions to support employees suddenly forced to work from home, but “what really put the firecracker behind it was the pandemic, it accelerated everything,” McKelvey said. She explained that customers were asking, “’How do we create an experience for people that makes them still feel connected to the company without the physical presence of being there?” + In this new world of Windows 365, remote workers flip the lid on their laptop, bootup the family workstation or clip a keyboard onto a tablet, launch a native app or modern web browser and login to their Windows 365 account.From there, their Cloud PC appears with their background, apps, settings and content just as they left it when they last were last there – in the office, at home or a coffee shop. + And then, when you’re done, you’re done.You won’t have any issues around security because you’re not saving anything on your device,” McKelvey said, noting that all the data is stored in the cloud. + The ability to login to a Cloud PC from anywhere on any device is part of Microsoft’s larger strategy around tailoring products such as Microsoft Teams and Microsoft 365 for the post-pandemic hybrid workforce of the future, she added. It enables employees accustomed to working from home to continue working from home; it enables companies to hire interns from halfway around the world; it allows startups to scale without requiring IT expertise. + “I think this will be interesting for those organizations who, for whatever reason, have shied away from virtualization.This is giving them an opportunity to try it in a way that their regular, everyday endpoint admin could manage,” McKelvey said. + The simplicity of Windows 365 won over Dean Wells, the corporate chief information officer for the Government of Nunavut. His team previously attempted to deploy a traditional virtual desktop infrastructure and found it inefficient and unsustainable given the limitations of low-bandwidth satellite internet and the constant need for IT staff to manage the network and infrastructure. + We didn’t run it for very long,” he said. “It didn’t turn out the way we had hoped.So, we actually had terminated the project and rolled back out to just regular PCs.” + He re-evaluated this decision after the Government of Nunavut was hit by a ransomware attack in November 2019 that took down everything from the phone system to the government’s servers. Microsoft helped rebuild the system, moving the government to Teams, SharePoint, OneDrive and Microsoft 365. Manchester’s team recruited the Government of Nunavut to pilot Windows 365. Wells was intrigued, especially by the ability to manage the elastic workforce securely and seamlessly. + “The impact that I believe we are finding, and the impact that we’re going to find going forward, is being able to access specialists from outside the territory and organizations outside the territory to come in and help us with our projects, being able to get people on staff with us to help us deliver the day-to-day expertise that we need to run the government,” he said. + “Being able to improve healthcare, being able to improve education, economic development is going to improve the quality of life in the communities.”"; + + // prepare analyze operation input + var batchInput = new List + { + document + }; + + TextAnalyticsActions actions = new TextAnalyticsActions() + { + ExtractSummaryActions = new List() { new ExtractSummaryAction() } + }; + + // start analysis process + AnalyzeActionsOperation operation = client.StartAnalyzeActions(batchInput, actions); + + // wait for completion with manual polling + TimeSpan pollingInterval = new TimeSpan(1000); + + while (true) + { + Console.WriteLine($"Status: {operation.Status}"); + operation.UpdateStatus(); + if (operation.HasCompleted) + { + break; + } + + Thread.Sleep(pollingInterval); + } + + // view operation status + Console.WriteLine($"AnalyzeActions operation has completed"); + Console.WriteLine(); + + Console.WriteLine($"Created On : {operation.CreatedOn}"); + Console.WriteLine($"Expires On : {operation.ExpiresOn}"); + Console.WriteLine($"Id : {operation.Id}"); + Console.WriteLine($"Status : {operation.Status}"); + Console.WriteLine($"Last Modified: {operation.LastModified}"); + Console.WriteLine(); + + // view operation results + foreach (AnalyzeActionsResult documentsInPage in operation.GetValues()) + { + IReadOnlyCollection summaryResults = documentsInPage.ExtractSummaryResults; + + foreach (ExtractSummaryActionResult summaryActionResults in summaryResults) + { + if (summaryActionResults.HasError) + { + Console.WriteLine($" Error!"); + Console.WriteLine($" Action error code: {summaryActionResults.Error.ErrorCode}."); + Console.WriteLine($" Message: {summaryActionResults.Error.Message}"); + continue; + } + + foreach (ExtractSummaryResult documentResults in summaryActionResults.DocumentsResults) + { + if (documentResults.HasError) + { + Console.WriteLine($" Error!"); + Console.WriteLine($" Document error code: {documentResults.Error.ErrorCode}."); + Console.WriteLine($" Message: {documentResults.Error.Message}"); + continue; + } + + Console.WriteLine($" Extracted the following {documentResults.Sentences.Count} sentence(s):"); + Console.WriteLine(); + + foreach (SummarySentence sentence in documentResults.Sentences) + { + Console.WriteLine($" Sentence: {sentence.Text}"); + Console.WriteLine($" Rank Score: {sentence.RankScore}"); + Console.WriteLine($" Offset: {sentence.Offset}"); + Console.WriteLine($" Length: {sentence.Length}"); + Console.WriteLine(); + } + } + } + } + } + } +} diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample8_ExtractSummaryConvenienceAsync.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample8_ExtractSummaryConvenienceAsync.cs new file mode 100644 index 0000000000000..47ef93d8121bb --- /dev/null +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample8_ExtractSummaryConvenienceAsync.cs @@ -0,0 +1,104 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +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 ExtractSummaryConvenienceAsync() + { + // create a text analytics client + string endpoint = TestEnvironment.Endpoint; + string apiKey = TestEnvironment.ApiKey; + var client = new TextAnalyticsClient(new Uri(endpoint), new AzureKeyCredential(apiKey)); + + // get input document + string document = @"Windows 365 was in the works before COVID-19 sent companies around the world on a scramble to secure solutions to support employees suddenly forced to work from home, but “what really put the firecracker behind it was the pandemic, it accelerated everything,” McKelvey said. She explained that customers were asking, “’How do we create an experience for people that makes them still feel connected to the company without the physical presence of being there?” + In this new world of Windows 365, remote workers flip the lid on their laptop, bootup the family workstation or clip a keyboard onto a tablet, launch a native app or modern web browser and login to their Windows 365 account.From there, their Cloud PC appears with their background, apps, settings and content just as they left it when they last were last there – in the office, at home or a coffee shop. + And then, when you’re done, you’re done.You won’t have any issues around security because you’re not saving anything on your device,” McKelvey said, noting that all the data is stored in the cloud. + The ability to login to a Cloud PC from anywhere on any device is part of Microsoft’s larger strategy around tailoring products such as Microsoft Teams and Microsoft 365 for the post-pandemic hybrid workforce of the future, she added. It enables employees accustomed to working from home to continue working from home; it enables companies to hire interns from halfway around the world; it allows startups to scale without requiring IT expertise. + “I think this will be interesting for those organizations who, for whatever reason, have shied away from virtualization.This is giving them an opportunity to try it in a way that their regular, everyday endpoint admin could manage,” McKelvey said. + The simplicity of Windows 365 won over Dean Wells, the corporate chief information officer for the Government of Nunavut. His team previously attempted to deploy a traditional virtual desktop infrastructure and found it inefficient and unsustainable given the limitations of low-bandwidth satellite internet and the constant need for IT staff to manage the network and infrastructure. + We didn’t run it for very long,” he said. “It didn’t turn out the way we had hoped.So, we actually had terminated the project and rolled back out to just regular PCs.” + He re-evaluated this decision after the Government of Nunavut was hit by a ransomware attack in November 2019 that took down everything from the phone system to the government’s servers. Microsoft helped rebuild the system, moving the government to Teams, SharePoint, OneDrive and Microsoft 365. Manchester’s team recruited the Government of Nunavut to pilot Windows 365. Wells was intrigued, especially by the ability to manage the elastic workforce securely and seamlessly. + “The impact that I believe we are finding, and the impact that we’re going to find going forward, is being able to access specialists from outside the territory and organizations outside the territory to come in and help us with our projects, being able to get people on staff with us to help us deliver the day-to-day expertise that we need to run the government,” he said. + “Being able to improve healthcare, being able to improve education, economic development is going to improve the quality of life in the communities.”"; + + // prepare analyze operation input + var batchInput = new List + { + document + }; + + TextAnalyticsActions actions = new TextAnalyticsActions() + { + ExtractSummaryActions = new List() { new ExtractSummaryAction() } + }; + + // start analysis process + AnalyzeActionsOperation operation = await client.StartAnalyzeActionsAsync(batchInput, actions); + + await operation.WaitForCompletionAsync(); + + // view operation status + Console.WriteLine($"AnalyzeActions operation has completed"); + Console.WriteLine(); + + Console.WriteLine($"Created On : {operation.CreatedOn}"); + Console.WriteLine($"Expires On : {operation.ExpiresOn}"); + Console.WriteLine($"Id : {operation.Id}"); + Console.WriteLine($"Status : {operation.Status}"); + Console.WriteLine($"Last Modified: {operation.LastModified}"); + Console.WriteLine(); + + // view operation results + foreach (AnalyzeActionsResult documentsInPage in operation.GetValues()) + { + IReadOnlyCollection summaryResults = documentsInPage.ExtractSummaryResults; + + foreach (ExtractSummaryActionResult summaryActionResults in summaryResults) + { + if (summaryActionResults.HasError) + { + Console.WriteLine($" Error!"); + Console.WriteLine($" Action error code: {summaryActionResults.Error.ErrorCode}."); + Console.WriteLine($" Message: {summaryActionResults.Error.Message}"); + continue; + } + + foreach (ExtractSummaryResult documentResults in summaryActionResults.DocumentsResults) + { + if (documentResults.HasError) + { + Console.WriteLine($" Error!"); + Console.WriteLine($" Document error code: {documentResults.Error.ErrorCode}."); + Console.WriteLine($" Message: {documentResults.Error.Message}"); + continue; + } + + Console.WriteLine($" Extracted the following {documentResults.Sentences.Count} sentence(s):"); + Console.WriteLine(); + + foreach (SummarySentence sentence in documentResults.Sentences) + { + Console.WriteLine($" Sentence: {sentence.Text}"); + Console.WriteLine($" Rank Score: {sentence.RankScore}"); + Console.WriteLine($" Offset: {sentence.Offset}"); + Console.WriteLine($" Length: {sentence.Length}"); + Console.WriteLine(); + } + } + } + } + } + } +} From c4a0b3d11b73a4f2146fd747c689d5ed47da5b24 Mon Sep 17 00:00:00 2001 From: Caio Saldanha Date: Wed, 4 Aug 2021 08:21:01 -0700 Subject: [PATCH 3/7] Added new sample file for extractive summarization --- .../samples/Sample8_ExtractSummary.md | 41 +++++++++++++++++++ .../samples/Sample_AnalyzeActions.md | 2 +- .../tests/samples/Sample8_ExtractSummary.cs | 15 +++---- .../samples/Sample8_ExtractSummaryAsync.cs | 13 +++--- .../Sample8_ExtractSummaryConvenience.cs | 15 +++---- .../Sample8_ExtractSummaryConvenienceAsync.cs | 19 ++++++--- 6 files changed, 78 insertions(+), 27 deletions(-) create mode 100644 sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample8_ExtractSummary.md diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample8_ExtractSummary.md b/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample8_ExtractSummary.md new file mode 100644 index 0000000000000..0b0435ab0edb4 --- /dev/null +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample8_ExtractSummary.md @@ -0,0 +1,41 @@ +# Perform Extractive Text Summarization in Documents +This sample demonstrates how to run an Extractive Text Summarization action in one or more documents. To get started you will need a Text Analytics endpoint and credentials. See [README][README] for links and instructions. + +## Creating a `TextAnalyticsClient` + +To create a new `TextAnalyticsClient` to recognize healthcare entities in a document, you need a Text Analytics endpoint and credentials. You can use the [DefaultAzureCredential][DefaultAzureCredential] to try a number of common authentication methods optimized for both running as a service and development. In the sample below, however, you'll use a Text Analytics API key credential by creating an `AzureKeyCredential` object, that if needed, will allow you to update the API key without creating a new client. + +You can set `endpoint` and `apiKey` based on an environment variable, a configuration setting, or any way that works for your application. + +```C# Snippet:CreateTextAnalyticsClient +string endpoint = ""; +string apiKey = ""; +var client = new TextAnalyticsClient(new Uri(endpoint), new AzureKeyCredential(apiKey)); +``` + +## Performing extractive text summarization in one or multiple documents + +To perform extractive text summarization in one or multiple documents, set up an `ExtractSummaryAction` and call `StartAnalyzeActionsAsync` on the documents. The result is a Long Running operation of type `AnalyzeActionsOperation` which polls for the results from the API. + +```C# Snippet:TextAnalyticsExtractSummaryAsync +``` + +The returned `AnalyzeActionsOperation` contains general information about the status of the operation. It can be requested while the operation is running or when it has completed. For example: + +```C# Snippet:TextAnalyticsExtractSummaryOperationStatus +``` + +To view the final results of the long-running operation: + +```C# Snippet:TextAnalyticsExtractSummaryAsyncViewResults +``` + +To see the full example source files, see: + +* [Synchronously ExtractSummary](https://github.com/Azure/azure-sdk-for-net/blob/feature/textanalytics/summarization/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample8_ExtractSummary.cs) +* [Asynchronously ExtractSummary](https://github.com/Azure/azure-sdk-for-net/blob/feature/textanalytics/summarization/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample8_ExtractSummaryAsync.cs) +* [Synchronously ExtractSummary Convenience](https://github.com/Azure/azure-sdk-for-net/blob/feature/textanalytics/summarization/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample8_ExtractSummaryConvenience.cs) +* [Asynchronously ExtractSummary Convenience](https://github.com/Azure/azure-sdk-for-net/blob/feature/textanalytics/summarization/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample8_ExtractSummaryConvenienceAsync.cs) + +[DefaultAzureCredential]: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/identity/Azure.Identity/README.md +[README]: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/textanalytics/Azure.AI.TextAnalytics/README.md \ No newline at end of file diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample_AnalyzeActions.md b/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample_AnalyzeActions.md index 0643efbaa40a4..2feb6fcfd14dc 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample_AnalyzeActions.md +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample_AnalyzeActions.md @@ -1,5 +1,5 @@ # Running multiple actions -This sample demonstrates how to run multiple actions in one or more documents. Actions include entity recognition, linked entity recognition, key phrase extraction, Personally Identifiable Information (PII) Recognition, and sentiment analysis. To get started you will need a Text Analytics endpoint and credentials. See [README][README] for links and instructions. +This sample demonstrates how to run multiple actions in one or more documents. Actions include entity recognition, linked entity recognition, key phrase extraction, Personally Identifiable Information (PII) Recognition, sentiment analysis, and extractive text summarization. To get started you will need a Text Analytics endpoint and credentials. See [README][README] for links and instructions. ## Creating a `TextAnalyticsClient` diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample8_ExtractSummary.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample8_ExtractSummary.cs index 5f85f5d48af01..ff09836718ce6 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample8_ExtractSummary.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample8_ExtractSummary.cs @@ -16,12 +16,12 @@ public partial class TextAnalyticsSamples : SamplesBase { new TextDocumentInput("1", document) @@ -53,10 +54,10 @@ public void ExtractSummary() ExtractSummaryActions = new List() { summaryAction } }; - // start analysis process + // Start analysis process. AnalyzeActionsOperation operation = client.StartAnalyzeActions(batchDocuments, actions); - // wait for completion with manual polling + // Wait for completion with manual polling. TimeSpan pollingInterval = new TimeSpan(1000); while (true) @@ -71,7 +72,7 @@ public void ExtractSummary() Thread.Sleep(pollingInterval); } - // view operation status + // View operation status. Console.WriteLine($"AnalyzeActions operation has completed"); Console.WriteLine(); @@ -82,7 +83,7 @@ public void ExtractSummary() Console.WriteLine($"Last Modified: {operation.LastModified}"); Console.WriteLine(); - // view operation results + // View operation results. foreach (AnalyzeActionsResult documentsInPage in operation.GetValues()) { IReadOnlyCollection summaryResults = documentsInPage.ExtractSummaryResults; diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample8_ExtractSummaryAsync.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample8_ExtractSummaryAsync.cs index 6a88c05000db7..17ded1f13ac9c 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample8_ExtractSummaryAsync.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample8_ExtractSummaryAsync.cs @@ -16,12 +16,12 @@ public partial class TextAnalyticsSamples : SamplesBase { new TextDocumentInput("1", document) @@ -53,12 +54,12 @@ public async Task ExtractSummaryAsync() ExtractSummaryActions = new List() { summaryAction } }; - // start analysis process + // Start analysis process. AnalyzeActionsOperation operation = await client.StartAnalyzeActionsAsync(batchDocuments, actions); await operation.WaitForCompletionAsync(); - // view operation status + // View operation status. Console.WriteLine($"AnalyzeActions operation has completed"); Console.WriteLine(); @@ -69,7 +70,7 @@ public async Task ExtractSummaryAsync() Console.WriteLine($"Last Modified: {operation.LastModified}"); Console.WriteLine(); - // view operation results + // View operation results. await foreach (AnalyzeActionsResult documentsInPage in operation.Value) { IReadOnlyCollection summaryResults = documentsInPage.ExtractSummaryResults; diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample8_ExtractSummaryConvenience.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample8_ExtractSummaryConvenience.cs index a5aa4fb90648b..ac7a542964f08 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample8_ExtractSummaryConvenience.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample8_ExtractSummaryConvenience.cs @@ -16,12 +16,12 @@ public partial class TextAnalyticsSamples : SamplesBase { document @@ -44,10 +45,10 @@ public void ExtractSummaryConvenience() ExtractSummaryActions = new List() { new ExtractSummaryAction() } }; - // start analysis process + // Start analysis process. AnalyzeActionsOperation operation = client.StartAnalyzeActions(batchInput, actions); - // wait for completion with manual polling + // Wait for completion with manual polling. TimeSpan pollingInterval = new TimeSpan(1000); while (true) @@ -62,7 +63,7 @@ public void ExtractSummaryConvenience() Thread.Sleep(pollingInterval); } - // view operation status + // View operation status. Console.WriteLine($"AnalyzeActions operation has completed"); Console.WriteLine(); @@ -73,7 +74,7 @@ public void ExtractSummaryConvenience() Console.WriteLine($"Last Modified: {operation.LastModified}"); Console.WriteLine(); - // view operation results + // View operation results. foreach (AnalyzeActionsResult documentsInPage in operation.GetValues()) { IReadOnlyCollection summaryResults = documentsInPage.ExtractSummaryResults; diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample8_ExtractSummaryConvenienceAsync.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample8_ExtractSummaryConvenienceAsync.cs index 47ef93d8121bb..a9c28325b0a99 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample8_ExtractSummaryConvenienceAsync.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample8_ExtractSummaryConvenienceAsync.cs @@ -16,12 +16,13 @@ public partial class TextAnalyticsSamples : SamplesBase { document @@ -44,12 +46,14 @@ public async Task ExtractSummaryConvenienceAsync() ExtractSummaryActions = new List() { new ExtractSummaryAction() } }; - // start analysis process + // Start analysis process. AnalyzeActionsOperation operation = await client.StartAnalyzeActionsAsync(batchInput, actions); await operation.WaitForCompletionAsync(); + #endregion Snippet:TextAnalyticsExtractSummaryAsync - // view operation status + #region Snippet:TextAnalyticsExtractSummaryOperationStatus + // View operation status. Console.WriteLine($"AnalyzeActions operation has completed"); Console.WriteLine(); @@ -59,8 +63,10 @@ public async Task ExtractSummaryConvenienceAsync() Console.WriteLine($"Status : {operation.Status}"); Console.WriteLine($"Last Modified: {operation.LastModified}"); Console.WriteLine(); + #endregion Snippet:TextAnalyticsExtractSummaryOperationStatus - // view operation results + #region Snippet:TextAnalyticsExtractSummaryAsyncViewResults + // View operation results. foreach (AnalyzeActionsResult documentsInPage in operation.GetValues()) { IReadOnlyCollection summaryResults = documentsInPage.ExtractSummaryResults; @@ -99,6 +105,7 @@ public async Task ExtractSummaryConvenienceAsync() } } } + #endregion Snippet:TextAnalyticsExtractSummaryAsyncViewResults } } } From 9633f14fb59c7423594b7501179e871904aaa301 Mon Sep 17 00:00:00 2001 From: Caio Saldanha Date: Wed, 4 Aug 2021 08:37:13 -0700 Subject: [PATCH 4/7] Updated README --- sdk/textanalytics/Azure.AI.TextAnalytics/README.md | 10 ++++++++++ .../samples/Sample8_ExtractSummaryConvenienceAsync.cs | 2 ++ 2 files changed, 12 insertions(+) diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/README.md b/sdk/textanalytics/Azure.AI.TextAnalytics/README.md index aee89cea522ca..11edab6fabf12 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/README.md +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/README.md @@ -8,6 +8,7 @@ Azure Cognitive Services Text Analytics is a cloud service that provides advance * Linked Entity Recognition * Healthcare Recognition * Running multiple actions in one or more documents +* Extractive Text Summarization [Source code][textanalytics_client_src] | [Package (NuGet)][textanalytics_nuget_package] | [API reference documentation][textanalytics_refdocs] | [Product documentation][textanalytics_docs] | [Samples][textanalytics_samples] @@ -161,6 +162,7 @@ The following section provides several code snippets using the `client` [created * [Recognize Entities Asynchronously](#recognize-entities-asynchronously) * [Analyze Healthcare Entities Asynchronously](#analyze-healthcare-entities-asynchronously) * [Run multiple actions Asynchronously](#run-multiple-actions-asynchronously) +* [Perform Extractive Text Summarization Asynchronously](#perform-extractive-text-summarization-asynchronously) ### Detect Language Run a Text Analytics predictive model to determine the language that the passed-in document or batch of documents are written in. @@ -710,6 +712,12 @@ This functionality allows running multiple actions in one or more documents. Act } ``` +### Perform Extractive Text Summarization Asynchronously +Get a summary for the input documents by extracting their most relevant sentences. Note that this API can only be used as part of an [Analyze Operation](#run-multiple-actions-asynchronously). + +```C# Snippet:TextAnalyticsExtractSummaryConvenienceAsyncAll +``` + ## Troubleshooting ### General @@ -773,6 +781,7 @@ Samples are provided for each main functional area, and for each area, samples a - [Recognize Linked Entities][recognize_linked_entities_sample] - [Recognize Healthcare Entities][analyze_healthcare_sample] - [Run multiple actions][analyze_operation_sample] +- [Perform Extractive Text Summarization][extract_summary_sample] ### Advanced samples - [Analyze Sentiment with Opinion Mining][analyze_sentiment_opinion_mining_sample] @@ -827,6 +836,7 @@ This project has adopted the [Microsoft Open Source Code of Conduct][code_of_con [analyze_sentiment_sample]: https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample2_AnalyzeSentiment.md [analyze_sentiment_opinion_mining_sample]: https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample2.1_AnalyzeSentimentWithOpinionMining.md [extract_key_phrases_sample]: https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample3_ExtractKeyPhrases.md +[extract_summary_sample]: https://github.com/Azure/azure-sdk-for-net/tree/feature/textanalytics/summarization/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample4_RecognizeEntities.md [recognize_entities_sample]: https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample4_RecognizeEntities.md [recognize_pii_entities_sample]: https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample5_RecognizePiiEntities.md [recognize_linked_entities_sample]: https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample6_RecognizeLinkedEntities.md diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample8_ExtractSummaryConvenienceAsync.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample8_ExtractSummaryConvenienceAsync.cs index a9c28325b0a99..aa18cb17e6f0c 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample8_ExtractSummaryConvenienceAsync.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample8_ExtractSummaryConvenienceAsync.cs @@ -21,6 +21,7 @@ public async Task ExtractSummaryConvenienceAsync() string apiKey = TestEnvironment.ApiKey; var client = new TextAnalyticsClient(new Uri(endpoint), new AzureKeyCredential(apiKey)); + #region Snippet:TextAnalyticsExtractSummaryConvenienceAsyncAll #region Snippet:TextAnalyticsExtractSummaryAsync // Get input document. string document = @"Windows 365 was in the works before COVID-19 sent companies around the world on a scramble to secure solutions to support employees suddenly forced to work from home, but “what really put the firecracker behind it was the pandemic, it accelerated everything,” McKelvey said. She explained that customers were asking, “’How do we create an experience for people that makes them still feel connected to the company without the physical presence of being there?” @@ -106,6 +107,7 @@ public async Task ExtractSummaryConvenienceAsync() } } #endregion Snippet:TextAnalyticsExtractSummaryAsyncViewResults + #endregion Snippet:TextAnalyticsExtractSummaryConvenienceAsyncAll } } } From 3c2714c42c33f83539fd7c5196678f23920f2f45 Mon Sep 17 00:00:00 2001 From: Caio Saldanha Date: Wed, 4 Aug 2021 08:38:25 -0700 Subject: [PATCH 5/7] Updated snippets --- .../Azure.AI.TextAnalytics/README.md | 79 +++++++++++++++++++ .../samples/Sample8_ExtractSummary.md | 77 ++++++++++++++++++ 2 files changed, 156 insertions(+) diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/README.md b/sdk/textanalytics/Azure.AI.TextAnalytics/README.md index 11edab6fabf12..d4c34b0121287 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/README.md +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/README.md @@ -716,6 +716,85 @@ This functionality allows running multiple actions in one or more documents. Act Get a summary for the input documents by extracting their most relevant sentences. Note that this API can only be used as part of an [Analyze Operation](#run-multiple-actions-asynchronously). ```C# Snippet:TextAnalyticsExtractSummaryConvenienceAsyncAll +// Get input document. +string document = @"Windows 365 was in the works before COVID-19 sent companies around the world on a scramble to secure solutions to support employees suddenly forced to work from home, but “what really put the firecracker behind it was the pandemic, it accelerated everything,” McKelvey said. She explained that customers were asking, “’How do we create an experience for people that makes them still feel connected to the company without the physical presence of being there?” + In this new world of Windows 365, remote workers flip the lid on their laptop, bootup the family workstation or clip a keyboard onto a tablet, launch a native app or modern web browser and login to their Windows 365 account.From there, their Cloud PC appears with their background, apps, settings and content just as they left it when they last were last there – in the office, at home or a coffee shop. + And then, when you’re done, you’re done.You won’t have any issues around security because you’re not saving anything on your device,” McKelvey said, noting that all the data is stored in the cloud. + The ability to login to a Cloud PC from anywhere on any device is part of Microsoft’s larger strategy around tailoring products such as Microsoft Teams and Microsoft 365 for the post-pandemic hybrid workforce of the future, she added. It enables employees accustomed to working from home to continue working from home; it enables companies to hire interns from halfway around the world; it allows startups to scale without requiring IT expertise. + “I think this will be interesting for those organizations who, for whatever reason, have shied away from virtualization.This is giving them an opportunity to try it in a way that their regular, everyday endpoint admin could manage,” McKelvey said. + The simplicity of Windows 365 won over Dean Wells, the corporate chief information officer for the Government of Nunavut. His team previously attempted to deploy a traditional virtual desktop infrastructure and found it inefficient and unsustainable given the limitations of low-bandwidth satellite internet and the constant need for IT staff to manage the network and infrastructure. + We didn’t run it for very long,” he said. “It didn’t turn out the way we had hoped.So, we actually had terminated the project and rolled back out to just regular PCs.” + He re-evaluated this decision after the Government of Nunavut was hit by a ransomware attack in November 2019 that took down everything from the phone system to the government’s servers. Microsoft helped rebuild the system, moving the government to Teams, SharePoint, OneDrive and Microsoft 365. Manchester’s team recruited the Government of Nunavut to pilot Windows 365. Wells was intrigued, especially by the ability to manage the elastic workforce securely and seamlessly. + “The impact that I believe we are finding, and the impact that we’re going to find going forward, is being able to access specialists from outside the territory and organizations outside the territory to come in and help us with our projects, being able to get people on staff with us to help us deliver the day-to-day expertise that we need to run the government,” he said. + “Being able to improve healthcare, being able to improve education, economic development is going to improve the quality of life in the communities.”"; + +// Prepare analyze operation input. You can add multiple documents to this list and perform the same +// operation to all of them. +var batchInput = new List +{ + document +}; + +TextAnalyticsActions actions = new TextAnalyticsActions() +{ + ExtractSummaryActions = new List() { new ExtractSummaryAction() } +}; + +// Start analysis process. +AnalyzeActionsOperation operation = await client.StartAnalyzeActionsAsync(batchInput, actions); + +await operation.WaitForCompletionAsync(); + +// View operation status. +Console.WriteLine($"AnalyzeActions operation has completed"); +Console.WriteLine(); + +Console.WriteLine($"Created On : {operation.CreatedOn}"); +Console.WriteLine($"Expires On : {operation.ExpiresOn}"); +Console.WriteLine($"Id : {operation.Id}"); +Console.WriteLine($"Status : {operation.Status}"); +Console.WriteLine($"Last Modified: {operation.LastModified}"); +Console.WriteLine(); + +// View operation results. +foreach (AnalyzeActionsResult documentsInPage in operation.GetValues()) +{ + IReadOnlyCollection summaryResults = documentsInPage.ExtractSummaryResults; + + foreach (ExtractSummaryActionResult summaryActionResults in summaryResults) + { + if (summaryActionResults.HasError) + { + Console.WriteLine($" Error!"); + Console.WriteLine($" Action error code: {summaryActionResults.Error.ErrorCode}."); + Console.WriteLine($" Message: {summaryActionResults.Error.Message}"); + continue; + } + + foreach (ExtractSummaryResult documentResults in summaryActionResults.DocumentsResults) + { + if (documentResults.HasError) + { + Console.WriteLine($" Error!"); + Console.WriteLine($" Document error code: {documentResults.Error.ErrorCode}."); + Console.WriteLine($" Message: {documentResults.Error.Message}"); + continue; + } + + Console.WriteLine($" Extracted the following {documentResults.Sentences.Count} sentence(s):"); + Console.WriteLine(); + + foreach (SummarySentence sentence in documentResults.Sentences) + { + Console.WriteLine($" Sentence: {sentence.Text}"); + Console.WriteLine($" Rank Score: {sentence.RankScore}"); + Console.WriteLine($" Offset: {sentence.Offset}"); + Console.WriteLine($" Length: {sentence.Length}"); + Console.WriteLine(); + } + } + } +} ``` ## Troubleshooting diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample8_ExtractSummary.md b/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample8_ExtractSummary.md index 0b0435ab0edb4..c4fa26d1b8389 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample8_ExtractSummary.md +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample8_ExtractSummary.md @@ -18,16 +18,93 @@ var client = new TextAnalyticsClient(new Uri(endpoint), new AzureKeyCredential(a To perform extractive text summarization in one or multiple documents, set up an `ExtractSummaryAction` and call `StartAnalyzeActionsAsync` on the documents. The result is a Long Running operation of type `AnalyzeActionsOperation` which polls for the results from the API. ```C# Snippet:TextAnalyticsExtractSummaryAsync +// Get input document. +string document = @"Windows 365 was in the works before COVID-19 sent companies around the world on a scramble to secure solutions to support employees suddenly forced to work from home, but “what really put the firecracker behind it was the pandemic, it accelerated everything,” McKelvey said. She explained that customers were asking, “’How do we create an experience for people that makes them still feel connected to the company without the physical presence of being there?” + In this new world of Windows 365, remote workers flip the lid on their laptop, bootup the family workstation or clip a keyboard onto a tablet, launch a native app or modern web browser and login to their Windows 365 account.From there, their Cloud PC appears with their background, apps, settings and content just as they left it when they last were last there – in the office, at home or a coffee shop. + And then, when you’re done, you’re done.You won’t have any issues around security because you’re not saving anything on your device,” McKelvey said, noting that all the data is stored in the cloud. + The ability to login to a Cloud PC from anywhere on any device is part of Microsoft’s larger strategy around tailoring products such as Microsoft Teams and Microsoft 365 for the post-pandemic hybrid workforce of the future, she added. It enables employees accustomed to working from home to continue working from home; it enables companies to hire interns from halfway around the world; it allows startups to scale without requiring IT expertise. + “I think this will be interesting for those organizations who, for whatever reason, have shied away from virtualization.This is giving them an opportunity to try it in a way that their regular, everyday endpoint admin could manage,” McKelvey said. + The simplicity of Windows 365 won over Dean Wells, the corporate chief information officer for the Government of Nunavut. His team previously attempted to deploy a traditional virtual desktop infrastructure and found it inefficient and unsustainable given the limitations of low-bandwidth satellite internet and the constant need for IT staff to manage the network and infrastructure. + We didn’t run it for very long,” he said. “It didn’t turn out the way we had hoped.So, we actually had terminated the project and rolled back out to just regular PCs.” + He re-evaluated this decision after the Government of Nunavut was hit by a ransomware attack in November 2019 that took down everything from the phone system to the government’s servers. Microsoft helped rebuild the system, moving the government to Teams, SharePoint, OneDrive and Microsoft 365. Manchester’s team recruited the Government of Nunavut to pilot Windows 365. Wells was intrigued, especially by the ability to manage the elastic workforce securely and seamlessly. + “The impact that I believe we are finding, and the impact that we’re going to find going forward, is being able to access specialists from outside the territory and organizations outside the territory to come in and help us with our projects, being able to get people on staff with us to help us deliver the day-to-day expertise that we need to run the government,” he said. + “Being able to improve healthcare, being able to improve education, economic development is going to improve the quality of life in the communities.”"; + +// Prepare analyze operation input. You can add multiple documents to this list and perform the same +// operation to all of them. +var batchInput = new List +{ + document +}; + +TextAnalyticsActions actions = new TextAnalyticsActions() +{ + ExtractSummaryActions = new List() { new ExtractSummaryAction() } +}; + +// Start analysis process. +AnalyzeActionsOperation operation = await client.StartAnalyzeActionsAsync(batchInput, actions); + +await operation.WaitForCompletionAsync(); ``` The returned `AnalyzeActionsOperation` contains general information about the status of the operation. It can be requested while the operation is running or when it has completed. For example: ```C# Snippet:TextAnalyticsExtractSummaryOperationStatus +// View operation status. +Console.WriteLine($"AnalyzeActions operation has completed"); +Console.WriteLine(); + +Console.WriteLine($"Created On : {operation.CreatedOn}"); +Console.WriteLine($"Expires On : {operation.ExpiresOn}"); +Console.WriteLine($"Id : {operation.Id}"); +Console.WriteLine($"Status : {operation.Status}"); +Console.WriteLine($"Last Modified: {operation.LastModified}"); +Console.WriteLine(); ``` To view the final results of the long-running operation: ```C# Snippet:TextAnalyticsExtractSummaryAsyncViewResults +// View operation results. +foreach (AnalyzeActionsResult documentsInPage in operation.GetValues()) +{ + IReadOnlyCollection summaryResults = documentsInPage.ExtractSummaryResults; + + foreach (ExtractSummaryActionResult summaryActionResults in summaryResults) + { + if (summaryActionResults.HasError) + { + Console.WriteLine($" Error!"); + Console.WriteLine($" Action error code: {summaryActionResults.Error.ErrorCode}."); + Console.WriteLine($" Message: {summaryActionResults.Error.Message}"); + continue; + } + + foreach (ExtractSummaryResult documentResults in summaryActionResults.DocumentsResults) + { + if (documentResults.HasError) + { + Console.WriteLine($" Error!"); + Console.WriteLine($" Document error code: {documentResults.Error.ErrorCode}."); + Console.WriteLine($" Message: {documentResults.Error.Message}"); + continue; + } + + Console.WriteLine($" Extracted the following {documentResults.Sentences.Count} sentence(s):"); + Console.WriteLine(); + + foreach (SummarySentence sentence in documentResults.Sentences) + { + Console.WriteLine($" Sentence: {sentence.Text}"); + Console.WriteLine($" Rank Score: {sentence.RankScore}"); + Console.WriteLine($" Offset: {sentence.Offset}"); + Console.WriteLine($" Length: {sentence.Length}"); + Console.WriteLine(); + } + } + } +} ``` To see the full example source files, see: From 8b39c40be3d1c0d3981abbe253db9419ec54155c Mon Sep 17 00:00:00 2001 From: Caio Saldanha Date: Wed, 4 Aug 2021 09:11:52 -0700 Subject: [PATCH 6/7] Fixed links --- sdk/textanalytics/Azure.AI.TextAnalytics/README.md | 2 +- .../samples/Sample8_ExtractSummary.md | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/README.md b/sdk/textanalytics/Azure.AI.TextAnalytics/README.md index d4c34b0121287..f9b48ec93d0fd 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/README.md +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/README.md @@ -915,7 +915,7 @@ This project has adopted the [Microsoft Open Source Code of Conduct][code_of_con [analyze_sentiment_sample]: https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample2_AnalyzeSentiment.md [analyze_sentiment_opinion_mining_sample]: https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample2.1_AnalyzeSentimentWithOpinionMining.md [extract_key_phrases_sample]: https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample3_ExtractKeyPhrases.md -[extract_summary_sample]: https://github.com/Azure/azure-sdk-for-net/tree/feature/textanalytics/summarization/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample4_RecognizeEntities.md +[extract_summary_sample]: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/textanalytics/Azure.AI.TextAnalytics/README.md [recognize_entities_sample]: https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample4_RecognizeEntities.md [recognize_pii_entities_sample]: https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample5_RecognizePiiEntities.md [recognize_linked_entities_sample]: https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample6_RecognizeLinkedEntities.md diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample8_ExtractSummary.md b/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample8_ExtractSummary.md index c4fa26d1b8389..996bbb6928035 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample8_ExtractSummary.md +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample8_ExtractSummary.md @@ -109,10 +109,10 @@ foreach (AnalyzeActionsResult documentsInPage in operation.GetValues()) To see the full example source files, see: -* [Synchronously ExtractSummary](https://github.com/Azure/azure-sdk-for-net/blob/feature/textanalytics/summarization/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample8_ExtractSummary.cs) -* [Asynchronously ExtractSummary](https://github.com/Azure/azure-sdk-for-net/blob/feature/textanalytics/summarization/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample8_ExtractSummaryAsync.cs) -* [Synchronously ExtractSummary Convenience](https://github.com/Azure/azure-sdk-for-net/blob/feature/textanalytics/summarization/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample8_ExtractSummaryConvenience.cs) -* [Asynchronously ExtractSummary Convenience](https://github.com/Azure/azure-sdk-for-net/blob/feature/textanalytics/summarization/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample8_ExtractSummaryConvenienceAsync.cs) +* [Synchronously ExtractSummary](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/textanalytics/Azure.AI.TextAnalytics/README.md) +* [Asynchronously ExtractSummary](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/textanalytics/Azure.AI.TextAnalytics/README.md) +* [Synchronously ExtractSummary Convenience](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/textanalytics/Azure.AI.TextAnalytics/README.md) +* [Asynchronously ExtractSummary Convenience](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/textanalytics/Azure.AI.TextAnalytics/README.md) [DefaultAzureCredential]: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/identity/Azure.Identity/README.md [README]: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/textanalytics/Azure.AI.TextAnalytics/README.md \ No newline at end of file From 788f2c5c21b9c4de8a03849f5f80911a52c68f10 Mon Sep 17 00:00:00 2001 From: Caio Saldanha Date: Wed, 4 Aug 2021 12:05:31 -0700 Subject: [PATCH 7/7] Addressed PR comments --- .../Azure.AI.TextAnalytics/README.md | 20 +---- .../samples/Sample8_ExtractSummary.md | 4 +- .../Sample8_ExtractSummaryConvenienceAsync.cs | 4 +- .../tests/samples/SampleSnippets.cs | 79 +++++++++++++++++++ 4 files changed, 84 insertions(+), 23 deletions(-) diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/README.md b/sdk/textanalytics/Azure.AI.TextAnalytics/README.md index f9b48ec93d0fd..8e989e2b0762f 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/README.md +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/README.md @@ -715,7 +715,7 @@ This functionality allows running multiple actions in one or more documents. Act ### Perform Extractive Text Summarization Asynchronously Get a summary for the input documents by extracting their most relevant sentences. Note that this API can only be used as part of an [Analyze Operation](#run-multiple-actions-asynchronously). -```C# Snippet:TextAnalyticsExtractSummaryConvenienceAsyncAll +```C# Snippet:TextAnalyticsExtractSummaryWithoutErrorHandlingAsync // Get input document. string document = @"Windows 365 was in the works before COVID-19 sent companies around the world on a scramble to secure solutions to support employees suddenly forced to work from home, but “what really put the firecracker behind it was the pandemic, it accelerated everything,” McKelvey said. She explained that customers were asking, “’How do we create an experience for people that makes them still feel connected to the company without the physical presence of being there?” In this new world of Windows 365, remote workers flip the lid on their laptop, bootup the family workstation or clip a keyboard onto a tablet, launch a native app or modern web browser and login to their Windows 365 account.From there, their Cloud PC appears with their background, apps, settings and content just as they left it when they last were last there – in the office, at home or a coffee shop. @@ -757,30 +757,14 @@ Console.WriteLine($"Last Modified: {operation.LastModified}"); Console.WriteLine(); // View operation results. -foreach (AnalyzeActionsResult documentsInPage in operation.GetValues()) +await foreach (AnalyzeActionsResult documentsInPage in operation.Value) { IReadOnlyCollection summaryResults = documentsInPage.ExtractSummaryResults; foreach (ExtractSummaryActionResult summaryActionResults in summaryResults) { - if (summaryActionResults.HasError) - { - Console.WriteLine($" Error!"); - Console.WriteLine($" Action error code: {summaryActionResults.Error.ErrorCode}."); - Console.WriteLine($" Message: {summaryActionResults.Error.Message}"); - continue; - } - foreach (ExtractSummaryResult documentResults in summaryActionResults.DocumentsResults) { - if (documentResults.HasError) - { - Console.WriteLine($" Error!"); - Console.WriteLine($" Document error code: {documentResults.Error.ErrorCode}."); - Console.WriteLine($" Message: {documentResults.Error.Message}"); - continue; - } - Console.WriteLine($" Extracted the following {documentResults.Sentences.Count} sentence(s):"); Console.WriteLine(); diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample8_ExtractSummary.md b/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample8_ExtractSummary.md index 996bbb6928035..1ca5b8cdc1134 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample8_ExtractSummary.md +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/samples/Sample8_ExtractSummary.md @@ -3,7 +3,7 @@ This sample demonstrates how to run an Extractive Text Summarization action in o ## Creating a `TextAnalyticsClient` -To create a new `TextAnalyticsClient` to recognize healthcare entities in a document, you need a Text Analytics endpoint and credentials. You can use the [DefaultAzureCredential][DefaultAzureCredential] to try a number of common authentication methods optimized for both running as a service and development. In the sample below, however, you'll use a Text Analytics API key credential by creating an `AzureKeyCredential` object, that if needed, will allow you to update the API key without creating a new client. +To create a new `TextAnalyticsClient` to extract summary sentences from a document, you need a Text Analytics endpoint and credentials. You can use the [DefaultAzureCredential][DefaultAzureCredential] to try a number of common authentication methods optimized for both running as a service and development. In the sample below, however, you'll use a Text Analytics API key credential by creating an `AzureKeyCredential` object, that if needed, will allow you to update the API key without creating a new client. You can set `endpoint` and `apiKey` based on an environment variable, a configuration setting, or any way that works for your application. @@ -67,7 +67,7 @@ To view the final results of the long-running operation: ```C# Snippet:TextAnalyticsExtractSummaryAsyncViewResults // View operation results. -foreach (AnalyzeActionsResult documentsInPage in operation.GetValues()) +await foreach (AnalyzeActionsResult documentsInPage in operation.Value) { IReadOnlyCollection summaryResults = documentsInPage.ExtractSummaryResults; diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample8_ExtractSummaryConvenienceAsync.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample8_ExtractSummaryConvenienceAsync.cs index aa18cb17e6f0c..2437c6a906432 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample8_ExtractSummaryConvenienceAsync.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/Sample8_ExtractSummaryConvenienceAsync.cs @@ -21,7 +21,6 @@ public async Task ExtractSummaryConvenienceAsync() string apiKey = TestEnvironment.ApiKey; var client = new TextAnalyticsClient(new Uri(endpoint), new AzureKeyCredential(apiKey)); - #region Snippet:TextAnalyticsExtractSummaryConvenienceAsyncAll #region Snippet:TextAnalyticsExtractSummaryAsync // Get input document. string document = @"Windows 365 was in the works before COVID-19 sent companies around the world on a scramble to secure solutions to support employees suddenly forced to work from home, but “what really put the firecracker behind it was the pandemic, it accelerated everything,” McKelvey said. She explained that customers were asking, “’How do we create an experience for people that makes them still feel connected to the company without the physical presence of being there?” @@ -68,7 +67,7 @@ public async Task ExtractSummaryConvenienceAsync() #region Snippet:TextAnalyticsExtractSummaryAsyncViewResults // View operation results. - foreach (AnalyzeActionsResult documentsInPage in operation.GetValues()) + await foreach (AnalyzeActionsResult documentsInPage in operation.Value) { IReadOnlyCollection summaryResults = documentsInPage.ExtractSummaryResults; @@ -107,7 +106,6 @@ public async Task ExtractSummaryConvenienceAsync() } } #endregion Snippet:TextAnalyticsExtractSummaryAsyncViewResults - #endregion Snippet:TextAnalyticsExtractSummaryConvenienceAsyncAll } } } diff --git a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/SampleSnippets.cs b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/SampleSnippets.cs index 690f66b666d81..3cf128de6c599 100644 --- a/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/SampleSnippets.cs +++ b/sdk/textanalytics/Azure.AI.TextAnalytics/tests/samples/SampleSnippets.cs @@ -2,6 +2,8 @@ // Licensed under the MIT License. using System; +using System.Collections.Generic; +using System.Threading.Tasks; using Azure.AI.TextAnalytics.Tests; using Azure.Core.TestFramework; using Azure.Identity; @@ -42,6 +44,83 @@ public void CreateTextAnalyticsClientTokenCredential() #endregion } + [Test] + public async Task ExtractSummaryWithoutErrorHandling() + { + // Shorter than other Extractive Summarization samples. Used in README for simplicity. + + // Create a text analytics client. + string endpoint = TestEnvironment.Endpoint; + string apiKey = TestEnvironment.ApiKey; + var client = new TextAnalyticsClient(new Uri(endpoint), new AzureKeyCredential(apiKey)); + + #region Snippet:TextAnalyticsExtractSummaryWithoutErrorHandlingAsync + // Get input document. + string document = @"Windows 365 was in the works before COVID-19 sent companies around the world on a scramble to secure solutions to support employees suddenly forced to work from home, but “what really put the firecracker behind it was the pandemic, it accelerated everything,” McKelvey said. She explained that customers were asking, “’How do we create an experience for people that makes them still feel connected to the company without the physical presence of being there?” + In this new world of Windows 365, remote workers flip the lid on their laptop, bootup the family workstation or clip a keyboard onto a tablet, launch a native app or modern web browser and login to their Windows 365 account.From there, their Cloud PC appears with their background, apps, settings and content just as they left it when they last were last there – in the office, at home or a coffee shop. + And then, when you’re done, you’re done.You won’t have any issues around security because you’re not saving anything on your device,” McKelvey said, noting that all the data is stored in the cloud. + The ability to login to a Cloud PC from anywhere on any device is part of Microsoft’s larger strategy around tailoring products such as Microsoft Teams and Microsoft 365 for the post-pandemic hybrid workforce of the future, she added. It enables employees accustomed to working from home to continue working from home; it enables companies to hire interns from halfway around the world; it allows startups to scale without requiring IT expertise. + “I think this will be interesting for those organizations who, for whatever reason, have shied away from virtualization.This is giving them an opportunity to try it in a way that their regular, everyday endpoint admin could manage,” McKelvey said. + The simplicity of Windows 365 won over Dean Wells, the corporate chief information officer for the Government of Nunavut. His team previously attempted to deploy a traditional virtual desktop infrastructure and found it inefficient and unsustainable given the limitations of low-bandwidth satellite internet and the constant need for IT staff to manage the network and infrastructure. + We didn’t run it for very long,” he said. “It didn’t turn out the way we had hoped.So, we actually had terminated the project and rolled back out to just regular PCs.” + He re-evaluated this decision after the Government of Nunavut was hit by a ransomware attack in November 2019 that took down everything from the phone system to the government’s servers. Microsoft helped rebuild the system, moving the government to Teams, SharePoint, OneDrive and Microsoft 365. Manchester’s team recruited the Government of Nunavut to pilot Windows 365. Wells was intrigued, especially by the ability to manage the elastic workforce securely and seamlessly. + “The impact that I believe we are finding, and the impact that we’re going to find going forward, is being able to access specialists from outside the territory and organizations outside the territory to come in and help us with our projects, being able to get people on staff with us to help us deliver the day-to-day expertise that we need to run the government,” he said. + “Being able to improve healthcare, being able to improve education, economic development is going to improve the quality of life in the communities.”"; + + // Prepare analyze operation input. You can add multiple documents to this list and perform the same + // operation to all of them. + var batchInput = new List + { + document + }; + + TextAnalyticsActions actions = new TextAnalyticsActions() + { + ExtractSummaryActions = new List() { new ExtractSummaryAction() } + }; + + // Start analysis process. + AnalyzeActionsOperation operation = await client.StartAnalyzeActionsAsync(batchInput, actions); + + await operation.WaitForCompletionAsync(); + + // View operation status. + Console.WriteLine($"AnalyzeActions operation has completed"); + Console.WriteLine(); + + Console.WriteLine($"Created On : {operation.CreatedOn}"); + Console.WriteLine($"Expires On : {operation.ExpiresOn}"); + Console.WriteLine($"Id : {operation.Id}"); + Console.WriteLine($"Status : {operation.Status}"); + Console.WriteLine($"Last Modified: {operation.LastModified}"); + Console.WriteLine(); + + // View operation results. + await foreach (AnalyzeActionsResult documentsInPage in operation.Value) + { + IReadOnlyCollection summaryResults = documentsInPage.ExtractSummaryResults; + + foreach (ExtractSummaryActionResult summaryActionResults in summaryResults) + { + foreach (ExtractSummaryResult documentResults in summaryActionResults.DocumentsResults) + { + Console.WriteLine($" Extracted the following {documentResults.Sentences.Count} sentence(s):"); + Console.WriteLine(); + + foreach (SummarySentence sentence in documentResults.Sentences) + { + Console.WriteLine($" Sentence: {sentence.Text}"); + Console.WriteLine($" Rank Score: {sentence.RankScore}"); + Console.WriteLine($" Offset: {sentence.Offset}"); + Console.WriteLine($" Length: {sentence.Length}"); + Console.WriteLine(); + } + } + } + } + #endregion Snippet:TextAnalyticsExtractSummaryWithoutErrorHandlingAsync + } + [Test] public void BadRequestSnippet() {