Exemplo n.º 1
0
        public async Task AnalyzeOperationTest()
        {
            TextAnalyticsClient client = GetClient();

            TextAnalyticsActions batchActions = new TextAnalyticsActions()
            {
                ExtractKeyPhrasesActions = new List <ExtractKeyPhrasesAction>()
                {
                    new ExtractKeyPhrasesAction()
                },
            };

            AnalyzeActionsOperation operation = await client.StartAnalyzeActionsAsync(batchConvenienceDocuments, batchActions, "en");

            await operation.WaitForCompletionAsync();

            //Take the first page
            AnalyzeActionsResult resultCollection = operation.Value.ToEnumerableAsync().Result.FirstOrDefault();

            IReadOnlyCollection <RecognizeEntitiesActionResult>       entitiesActionsResults         = resultCollection.RecognizeEntitiesActionsResults;
            IReadOnlyCollection <ExtractKeyPhrasesActionResult>       keyPhrasesActionsResults       = resultCollection.ExtractKeyPhrasesActionsResults;
            IReadOnlyCollection <RecognizePiiEntitiesActionResult>    piiActionsResults              = resultCollection.RecognizePiiEntitiesActionsResults;
            IReadOnlyCollection <RecognizeLinkedEntitiesActionResult> entityLinkingActionsResults    = resultCollection.RecognizeLinkedEntitiesActionsResults;
            IReadOnlyCollection <AnalyzeSentimentActionResult>        analyzeSentimentActionsResults = resultCollection.AnalyzeSentimentActionsResults;

            Assert.IsNotNull(keyPhrasesActionsResults);
            Assert.IsNotNull(entitiesActionsResults);
            Assert.IsNotNull(piiActionsResults);
            Assert.IsNotNull(entityLinkingActionsResults);
            Assert.IsNotNull(analyzeSentimentActionsResults);

            var keyPhrasesListId1 = new List <string> {
                "CEO", "SpaceX", "Elon Musk", "Tesla"
            };
            var keyPhrasesListId2 = new List <string> {
                "Tesla stock"
            };

            ExtractKeyPhrasesResultCollection keyPhrasesDocumentsResults = keyPhrasesActionsResults.FirstOrDefault().DocumentsResults;

            Assert.AreEqual(2, keyPhrasesDocumentsResults.Count);

            foreach (string keyphrase in keyPhrasesDocumentsResults[0].KeyPhrases)
            {
                Assert.IsTrue(keyPhrasesListId1.Contains(keyphrase));
            }

            foreach (string keyphrase in keyPhrasesDocumentsResults[1].KeyPhrases)
            {
                Assert.IsTrue(keyPhrasesListId2.Contains(keyphrase));
            }
        }
        // This has been added to stop the custom tests to run forever while we
        // get more reliable information on which scenarios cause timeouts.
        // Issue https://github.com/Azure/azure-sdk-for-net/issues/25152
        internal async Task PollUntilTimeout(AnalyzeActionsOperation operation, int timeoutInMinutes = 20)
        {
            TimeSpan pollingInterval = TimeSpan.FromSeconds(10);
            var      timeout         = TimeSpan.FromMinutes(timeoutInMinutes);

            using CancellationTokenSource cts = new CancellationTokenSource(timeout);
            try
            {
                await operation.WaitForCompletionAsync(pollingInterval, cts.Token);
            }
            catch (TaskCanceledException)
            {
                Debug.WriteLine("Test cancelled. Test timed out.");
            }
        }
Exemplo n.º 3
0
        public async Task AnalyzeOperationWithPiiCategories()
        {
            TextAnalyticsClient client = GetClient();

            var documents = new List <string>
            {
                "A developer with SSN 859-98-0987 whose phone number is 800-102-1100 is building tools with our APIs. They work at Microsoft.",
            };

            TextAnalyticsActions batchActions = new TextAnalyticsActions()
            {
                RecognizePiiEntitiesActions = new List <RecognizePiiEntitiesAction>()
                {
                    new RecognizePiiEntitiesAction()
                    {
                        CategoriesFilter = { PiiEntityCategory.USSocialSecurityNumber }
                    }
                },
            };

            AnalyzeActionsOperation operation = await client.StartAnalyzeActionsAsync(documents, batchActions, "en");

            await operation.WaitForCompletionAsync();

            //Take the first page
            AnalyzeActionsResult resultCollection = operation.Value.ToEnumerableAsync().Result.FirstOrDefault();

            IReadOnlyCollection <RecognizePiiEntitiesActionResult> piiActionsResults = resultCollection.RecognizePiiEntitiesResults;

            Assert.IsNotNull(piiActionsResults);

            RecognizePiiEntitiesResultCollection piiDocumentsResults = piiActionsResults.FirstOrDefault().DocumentsResults;

            Assert.AreEqual(1, piiDocumentsResults.Count);

            Assert.IsNotEmpty(piiDocumentsResults[0].Entities.RedactedText);

            Assert.IsFalse(piiDocumentsResults[0].HasError);
            Assert.AreEqual(1, piiDocumentsResults[0].Entities.Count);
            Assert.AreEqual(PiiEntityCategory.USSocialSecurityNumber, piiDocumentsResults[0].Entities.FirstOrDefault().Category);
        }
Exemplo n.º 4
0
        public async Task AnalyzeOperationWithPHIDomain()
        {
            TextAnalyticsClient client = GetClient();

            var documents = new List <string>
            {
                "A patient with medical id 12345678 whose phone number is 800-102-1100 is going under heart surgery",
            };

            TextAnalyticsActions batchActions = new TextAnalyticsActions()
            {
                RecognizePiiEntitiesActions = new List <RecognizePiiEntitiesAction>()
                {
                    new RecognizePiiEntitiesAction()
                    {
                        DomainFilter = PiiEntityDomainType.ProtectedHealthInformation
                    }
                },
                DisplayName = "AnalyzeOperationWithPHIDomain",
            };

            AnalyzeActionsOperation operation = await client.StartAnalyzeActionsAsync(documents, batchActions, "en");

            await operation.WaitForCompletionAsync();

            //Take the first page
            AnalyzeActionsResult resultCollection = operation.Value.ToEnumerableAsync().Result.FirstOrDefault();

            IReadOnlyCollection <RecognizePiiEntitiesActionResult> piiActionsResults = resultCollection.RecognizePiiEntitiesActionsResults;

            Assert.IsNotNull(piiActionsResults);

            RecognizePiiEntitiesResultCollection piiResult = piiActionsResults.FirstOrDefault().Result;

            Assert.AreEqual(1, piiResult.Count);

            Assert.IsNotEmpty(piiResult[0].Entities.RedactedText);

            Assert.IsFalse(piiResult[0].HasError);
            Assert.AreEqual(2, piiResult[0].Entities.Count);
        }
Exemplo n.º 5
0
        public async Task AnalyzeOperationAnalyzeSentimentWithOpinionMining()
        {
            TextAnalyticsClient client = GetClient();

            var documents = new List <string>
            {
                "The park was clean and pretty. The bathrooms and restaurant were not clean.",
            };

            TextAnalyticsActions batchActions = new TextAnalyticsActions()
            {
                AnalyzeSentimentActions = new List <AnalyzeSentimentAction>()
                {
                    new AnalyzeSentimentAction()
                    {
                        IncludeOpinionMining = true
                    }
                },
                DisplayName = "AnalyzeOperationWithOpinionMining",
            };

            AnalyzeActionsOperation operation = await client.StartAnalyzeActionsAsync(documents, batchActions);

            await operation.WaitForCompletionAsync();

            //Take the first page
            AnalyzeActionsResult resultCollection = operation.Value.ToEnumerableAsync().Result.FirstOrDefault();

            IReadOnlyCollection <AnalyzeSentimentActionResult> analyzeSentimentActionsResults = resultCollection.AnalyzeSentimentActionsResults;

            Assert.IsNotNull(analyzeSentimentActionsResults);

            AnalyzeSentimentResultCollection analyzeSentimentResult = analyzeSentimentActionsResults.FirstOrDefault().Result;

            Assert.AreEqual(1, analyzeSentimentResult.Count);

            Assert.AreEqual(TextSentiment.Mixed, analyzeSentimentResult[0].DocumentSentiment.Sentiment);
        }
Exemplo n.º 6
0
        public async Task ExtractSummaryWithMultipleActions()
        {
            TextAnalyticsClient client = GetClient();

            TextAnalyticsActions batchActions = new TextAnalyticsActions()
            {
                ExtractSummaryActions = new List <ExtractSummaryAction>()
                {
                    new ExtractSummaryAction()
                    {
                        DisableServiceLogs = true,
                        ActionName         = "ExtractSummaryWithDisabledServiceLogs"
                    },
                    new ExtractSummaryAction()
                    {
                        ActionName = "ExtractSummary"
                    }
                }
            };

            AnalyzeActionsOperation operation = await client.StartAnalyzeActionsAsync(s_extractSummaryBatchDocuments, batchActions);

            await operation.WaitForCompletionAsync();

            // Take the first page
            AnalyzeActionsResult resultCollection = operation.Value.ToEnumerableAsync().Result.FirstOrDefault();

            IReadOnlyCollection <ExtractSummaryActionResult> ExtractSummaryActionsResults = resultCollection.ExtractSummaryResults;

            Assert.IsNotNull(ExtractSummaryActionsResults);

            IList <string> expected = new List <string> {
                "ExtractSummary", "ExtractSummaryWithDisabledServiceLogs"
            };

            CollectionAssert.AreEquivalent(expected, ExtractSummaryActionsResults.Select(result => result.ActionName));
        }
        public async Task RecognizeLinkedEntitiesWithMultipleActions()
        {
            TextAnalyticsClient client = GetClient();

            TextAnalyticsActions batchActions = new TextAnalyticsActions()
            {
                RecognizeLinkedEntitiesActions = new List <RecognizeLinkedEntitiesAction>()
                {
                    new RecognizeLinkedEntitiesAction()
                    {
                        DisableServiceLogs = true,
                        ActionName         = "RecognizeLinkedEntitiesWithDisabledServiceLogs"
                    },
                    new RecognizeLinkedEntitiesAction()
                    {
                        ActionName = "RecognizeLinkedEntities"
                    }
                }
            };

            AnalyzeActionsOperation operation = await client.StartAnalyzeActionsAsync(s_batchDocuments, batchActions);

            await operation.WaitForCompletionAsync();

            // Take the first page
            AnalyzeActionsResult resultCollection = operation.Value.ToEnumerableAsync().Result.FirstOrDefault();

            IReadOnlyCollection <RecognizeLinkedEntitiesActionResult> RecognizeLinkedEntitiesActionsResults = resultCollection.RecognizeLinkedEntitiesResults;

            Assert.IsNotNull(RecognizeLinkedEntitiesActionsResults);

            IList <string> expected = new List <string> {
                "RecognizeLinkedEntities", "RecognizeLinkedEntitiesWithDisabledServiceLogs"
            };

            CollectionAssert.AreEquivalent(expected, RecognizeLinkedEntitiesActionsResults.Select(result => result.ActionName));
        }
Exemplo n.º 8
0
        public async Task AnalyzeSentimentWithMultipleActions()
        {
            TextAnalyticsClient client = GetClient();

            TextAnalyticsActions batchActions = new TextAnalyticsActions()
            {
                AnalyzeSentimentActions = new List <AnalyzeSentimentAction>()
                {
                    new AnalyzeSentimentAction()
                    {
                        DisableServiceLogs = true,
                        ActionName         = "AnalyzeSentimentWithDisabledServiceLogs"
                    },
                    new AnalyzeSentimentAction()
                    {
                        ActionName = "AnalyzeSentiment"
                    }
                }
            };

            AnalyzeActionsOperation operation = await client.StartAnalyzeActionsAsync(batchConvenienceDocuments, batchActions);

            await operation.WaitForCompletionAsync();

            // Take the first page
            AnalyzeActionsResult resultCollection = operation.Value.ToEnumerableAsync().Result.FirstOrDefault();

            IReadOnlyCollection <AnalyzeSentimentActionResult> AnalyzeSentimentActionsResults = resultCollection.AnalyzeSentimentResults;

            Assert.IsNotNull(AnalyzeSentimentActionsResults);

            IList <string> expected = new List <string> {
                "AnalyzeSentiment", "AnalyzeSentimentWithDisabledServiceLogs"
            };

            CollectionAssert.AreEquivalent(expected, AnalyzeSentimentActionsResults.Select(result => result.ActionName));
        }
Exemplo n.º 9
0
        public async Task AnalyzeOperationWithAADTest()
        {
            TextAnalyticsClient client = GetClient(useTokenCredential: true);

            TextAnalyticsActions batchActions = new TextAnalyticsActions()
            {
                ExtractKeyPhrasesActions = new List <ExtractKeyPhrasesAction>()
                {
                    new ExtractKeyPhrasesAction()
                },
            };

            AnalyzeActionsOperation operation = await client.StartAnalyzeActionsAsync(batchDocuments, batchActions);

            await operation.WaitForCompletionAsync();

            //Take the first page
            AnalyzeActionsResult resultCollection = operation.Value.ToEnumerableAsync().Result.FirstOrDefault();

            IReadOnlyCollection <ExtractKeyPhrasesActionResult> keyPhrasesActionsResults = resultCollection.ExtractKeyPhrasesActionsResults;

            Assert.IsNotNull(keyPhrasesActionsResults);
            Assert.AreEqual(2, keyPhrasesActionsResults.FirstOrDefault().Result.Count);
        }
Exemplo n.º 10
0
        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 <string>
            {
                document
            };

            TextAnalyticsActions actions = new TextAnalyticsActions()
            {
                ExtractSummaryActions = new List <ExtractSummaryAction>()
                {
                    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 <ExtractSummaryActionResult> 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
        }
        public async Task RecognizeCustomEntitiesConvenienceAsync()
        {
            // Create a text analytics client.
            string endpoint = TestEnvironment.Endpoint;
            string apiKey   = TestEnvironment.ApiKey;

            var client = new TextAnalyticsClient(new Uri(endpoint), new AzureKeyCredential(apiKey), CreateSampleOptions());

            // Create input documents.
            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.";

            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!";

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

            // Set project and deployment names of the target model
            // To train a model to recognize your custom entities, see https://aka.ms/azsdk/textanalytics/customentityrecognition
            string projectName    = TestEnvironment.RecognizeCustomEntitiesProjectName;
            string deploymentName = TestEnvironment.RecognizeCustomEntitiesDeploymentName;

            var recognizeCustomEntitiesAction = new RecognizeCustomEntitiesAction(projectName, deploymentName);

            // prepare actions.
            var actions = new TextAnalyticsActions()
            {
                RecognizeCustomEntitiesActions = new List <RecognizeCustomEntitiesAction>()
                {
                    recognizeCustomEntitiesAction
                }
            };

            AnalyzeActionsOperation operation = await client.StartAnalyzeActionsAsync(batchDocuments, actions);

            await operation.WaitForCompletionAsync();

            await foreach (AnalyzeActionsResult documentsInPage in operation.Value)
            {
                IReadOnlyCollection <RecognizeCustomEntitiesActionResult> customEntitiesActionResults = documentsInPage.RecognizeCustomEntitiesResults;
                foreach (RecognizeCustomEntitiesActionResult customEntitiesActionResult in customEntitiesActionResults)
                {
                    Console.WriteLine($" Action name: {customEntitiesActionResult.ActionName}");
                    int docNumber = 1;
                    foreach (RecognizeEntitiesResult documentResults in customEntitiesActionResult.DocumentsResults)
                    {
                        Console.WriteLine($" Document #{docNumber++}");
                        Console.WriteLine($"  Recognized the following {documentResults.Entities.Count} entities:");

                        foreach (CategorizedEntity entity in documentResults.Entities)
                        {
                            Console.WriteLine($"  Entity: {entity.Text}");
                            Console.WriteLine($"  Category: {entity.Category}");
                            Console.WriteLine($"  Offset: {entity.Offset}");
                            Console.WriteLine($"  Length: {entity.Length}");
                            Console.WriteLine($"  ConfidenceScore: {entity.ConfidenceScore}");
                            Console.WriteLine($"  SubCategory: {entity.SubCategory}");
                        }
                        Console.WriteLine("");
                    }
                }
            }
        }
Exemplo n.º 12
0
        public async Task SingleCategoryClassifyAsync()
        {
            // Create a Text Analytics client.
            string endpoint = TestEnvironment.Endpoint;
            string apiKey   = TestEnvironment.ApiKey;

            var client = new TextAnalyticsClient(new Uri(endpoint), new AzureKeyCredential(apiKey), CreateSampleOptions());

            // Get input document.
            string document = @"I need a reservation for an indoor restaurant in China. Please don't stop the music. Play music and add it to my playlist.";

            // Prepare analyze operation input. You can add multiple documents to this list and perform the same
            // operation to all of them.
            var batchDocuments = new List <TextDocumentInput>
            {
                new TextDocumentInput("1", document)
                {
                    Language = "en",
                }
            };

            // Set project and deployment names of the target model
            // To train a model to classify your documents, see https://aka.ms/azsdk/textanalytics/customfunctionalities
            string projectName    = TestEnvironment.SingleClassificationProjectName;
            string deploymentName = TestEnvironment.SingleClassificationDeploymentName;

            var singleCategoryClassifyAction = new SingleCategoryClassifyAction(projectName, deploymentName);

            TextAnalyticsActions actions = new TextAnalyticsActions()
            {
                SingleCategoryClassifyActions = new List <SingleCategoryClassifyAction>()
                {
                    singleCategoryClassifyAction
                }
            };

            // 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 <SingleCategoryClassifyActionResult> singleClassificationActionResults = documentsInPage.SingleCategoryClassifyResults;

                foreach (SingleCategoryClassifyActionResult classificationActionResults in singleClassificationActionResults)
                {
                    Console.WriteLine($" Action name: {classificationActionResults.ActionName}");
                    foreach (SingleCategoryClassifyResult documentResults in classificationActionResults.DocumentsResults)
                    {
                        Console.WriteLine($"  Class category \"{documentResults.Classification.Category}\" predicted with a confidence score of {documentResults.Classification.ConfidenceScore}.");
                        Console.WriteLine();
                    }
                }
            }
        }
        public async Task AnalyzeOperationConvenienceAsync()
        {
            string endpoint = TestEnvironment.Endpoint;
            string apiKey   = TestEnvironment.ApiKey;

            var client = new TextAnalyticsClient(new Uri(endpoint), new AzureKeyCredential(apiKey));

            #region Snippet:AnalyzeOperationConvenienceAsync
            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.";

            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!";

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

            TextAnalyticsActions actions = new TextAnalyticsActions()
            {
                ExtractKeyPhrasesActions = new List <ExtractKeyPhrasesAction>()
                {
                    new ExtractKeyPhrasesAction()
                },
                RecognizeEntitiesActions = new List <RecognizeEntitiesAction>()
                {
                    new RecognizeEntitiesAction()
                },
                RecognizePiiEntitiesActions = new List <RecognizePiiEntitiesAction>()
                {
                    new RecognizePiiEntitiesAction()
                },
                RecognizeLinkedEntitiesActions = new List <RecognizeLinkedEntitiesAction>()
                {
                    new RecognizeLinkedEntitiesAction()
                },
                AnalyzeSentimentActions = new List <AnalyzeSentimentAction>()
                {
                    new AnalyzeSentimentAction()
                },
                DisplayName = "AnalyzeOperationSample"
            };

            AnalyzeActionsOperation operation = await client.StartAnalyzeActionsAsync(batchDocuments, actions);

            await operation.WaitForCompletionAsync();

            Console.WriteLine($"Status: {operation.Status}");
            Console.WriteLine($"Created On: {operation.CreatedOn}");
            Console.WriteLine($"Expires On: {operation.ExpiresOn}");
            Console.WriteLine($"Last modified: {operation.LastModified}");
            if (!string.IsNullOrEmpty(operation.DisplayName))
            {
                Console.WriteLine($"Display name: {operation.DisplayName}");
            }
            Console.WriteLine($"Total actions: {operation.ActionsTotal}");
            Console.WriteLine($"  Succeeded actions: {operation.ActionsSucceeded}");
            Console.WriteLine($"  Failed actions: {operation.ActionsFailed}");
            Console.WriteLine($"  In progress actions: {operation.ActionsInProgress}");

            await foreach (AnalyzeActionsResult documentsInPage in operation.Value)
            {
                IReadOnlyCollection <ExtractKeyPhrasesActionResult>       keyPhrasesActionsResults       = documentsInPage.ExtractKeyPhrasesActionsResults;
                IReadOnlyCollection <RecognizeEntitiesActionResult>       entitiesActionsResults         = documentsInPage.RecognizeEntitiesActionsResults;
                IReadOnlyCollection <RecognizePiiEntitiesActionResult>    piiActionsResults              = documentsInPage.RecognizePiiEntitiesActionsResults;
                IReadOnlyCollection <RecognizeLinkedEntitiesActionResult> entityLinkingActionsResults    = documentsInPage.RecognizeLinkedEntitiesActionsResults;
                IReadOnlyCollection <AnalyzeSentimentActionResult>        analyzeSentimentActionsResults = documentsInPage.AnalyzeSentimentActionsResults;

                Console.WriteLine("Recognized Entities");
                int docNumber = 1;
                foreach (RecognizeEntitiesActionResult entitiesActionResults in entitiesActionsResults)
                {
                    foreach (RecognizeEntitiesResult result in entitiesActionResults.Result)
                    {
                        Console.WriteLine($" Document #{docNumber++}");
                        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($"  Length: {entity.Length}");
                            Console.WriteLine($"  ConfidenceScore: {entity.ConfidenceScore}");
                            Console.WriteLine($"  SubCategory: {entity.SubCategory}");
                        }
                        Console.WriteLine("");
                    }
                }

                Console.WriteLine("Recognized PII Entities");
                docNumber = 1;
                foreach (RecognizePiiEntitiesActionResult piiActionResults in piiActionsResults)
                {
                    foreach (RecognizePiiEntitiesResult result in piiActionResults.Result)
                    {
                        Console.WriteLine($" Document #{docNumber++}");
                        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($"  Length: {entity.Length}");
                            Console.WriteLine($"  ConfidenceScore: {entity.ConfidenceScore}");
                            Console.WriteLine($"  SubCategory: {entity.SubCategory}");
                        }
                        Console.WriteLine("");
                    }
                }

                Console.WriteLine("Key Phrases");
                docNumber = 1;
                foreach (ExtractKeyPhrasesActionResult keyPhrasesActionResult in keyPhrasesActionsResults)
                {
                    foreach (ExtractKeyPhrasesResult result in keyPhrasesActionResult.Result)
                    {
                        Console.WriteLine($" Document #{docNumber++}");
                        Console.WriteLine($"  Recognized the following {result.KeyPhrases.Count} Keyphrases:");

                        foreach (string keyphrase in result.KeyPhrases)
                        {
                            Console.WriteLine($"  {keyphrase}");
                        }
                        Console.WriteLine("");
                    }
                }

                Console.WriteLine("Recognized Linked Entities");
                docNumber = 1;
                foreach (RecognizeLinkedEntitiesActionResult linkedEntitiesActionResults in entityLinkingActionsResults)
                {
                    foreach (RecognizeLinkedEntitiesResult result in linkedEntitiesActionResults.Result)
                    {
                        Console.WriteLine($" Document #{docNumber++}");
                        Console.WriteLine($"  Recognized the following {result.Entities.Count} linked entities:");

                        foreach (LinkedEntity entity in result.Entities)
                        {
                            Console.WriteLine($"  Entity: {entity.Name}");
                            Console.WriteLine($"  DataSource: {entity.DataSource}");
                            Console.WriteLine($"  DataSource EntityId: {entity.DataSourceEntityId}");
                            Console.WriteLine($"  Language: {entity.Language}");
                            Console.WriteLine($"  DataSource Url: {entity.Url}");

                            Console.WriteLine($"  Total Matches: {entity.Matches.Count()}");
                            foreach (LinkedEntityMatch match in entity.Matches)
                            {
                                Console.WriteLine($"    Match Text: {match.Text}");
                                Console.WriteLine($"    ConfidenceScore: {match.ConfidenceScore}");
                                Console.WriteLine($"    Offset: {match.Offset}");
                                Console.WriteLine($"    Length: {match.Length}");
                            }
                            Console.WriteLine("");
                        }
                        Console.WriteLine("");
                    }
                }

                Console.WriteLine("Analyze Sentiment");
                docNumber = 1;
                foreach (AnalyzeSentimentActionResult analyzeSentimentActionsResult in analyzeSentimentActionsResults)
                {
                    foreach (AnalyzeSentimentResult result in analyzeSentimentActionsResult.Result)
                    {
                        Console.WriteLine($" Document #{docNumber++}");
                        Console.WriteLine($"  Sentiment is {result.DocumentSentiment.Sentiment}, with confidence scores: ");
                        Console.WriteLine($"    Positive confidence score: {result.DocumentSentiment.ConfidenceScores.Positive}.");
                        Console.WriteLine($"    Neutral confidence score: {result.DocumentSentiment.ConfidenceScores.Neutral}.");
                        Console.WriteLine($"    Negative confidence score: {result.DocumentSentiment.ConfidenceScores.Negative}.");
                        Console.WriteLine("");
                    }
                }
            }
        }
Exemplo n.º 14
0
        public async Task AnalyzeOperationAllActionsAndDisableServiceLogs()
        {
            TextAnalyticsClient client = GetClient();

            TextAnalyticsActions batchActions = new TextAnalyticsActions()
            {
                ExtractKeyPhrasesActions = new List <ExtractKeyPhrasesAction>()
                {
                    new ExtractKeyPhrasesAction()
                    {
                        DisableServiceLogs = true
                    }
                },
                RecognizeEntitiesActions = new List <RecognizeEntitiesAction>()
                {
                    new RecognizeEntitiesAction()
                    {
                        DisableServiceLogs = true
                    }
                },
                RecognizePiiEntitiesActions = new List <RecognizePiiEntitiesAction>()
                {
                    new RecognizePiiEntitiesAction()
                    {
                        DisableServiceLogs = false
                    }
                },
                RecognizeLinkedEntitiesActions = new List <RecognizeLinkedEntitiesAction>()
                {
                    new RecognizeLinkedEntitiesAction()
                    {
                        DisableServiceLogs = true
                    }
                },
                AnalyzeSentimentActions = new List <AnalyzeSentimentAction>()
                {
                    new AnalyzeSentimentAction()
                    {
                        DisableServiceLogs = true
                    }
                },
            };

            AnalyzeActionsOperation operation = await client.StartAnalyzeActionsAsync(batchConvenienceDocuments, batchActions);

            await operation.WaitForCompletionAsync();

            //Take the first page
            AnalyzeActionsResult resultCollection = operation.Value.ToEnumerableAsync().Result.FirstOrDefault();

            IReadOnlyCollection <ExtractKeyPhrasesActionResult>       keyPhrasesActionsResults       = resultCollection.ExtractKeyPhrasesActionsResults;
            IReadOnlyCollection <RecognizeEntitiesActionResult>       entitiesActionsResults         = resultCollection.RecognizeEntitiesActionsResults;
            IReadOnlyCollection <RecognizePiiEntitiesActionResult>    piiActionsResults              = resultCollection.RecognizePiiEntitiesActionsResults;
            IReadOnlyCollection <RecognizeLinkedEntitiesActionResult> entityLinkingActionsResults    = resultCollection.RecognizeLinkedEntitiesActionsResults;
            IReadOnlyCollection <AnalyzeSentimentActionResult>        analyzeSentimentActionsResults = resultCollection.AnalyzeSentimentActionsResults;

            Assert.IsNotNull(keyPhrasesActionsResults);
            Assert.AreEqual(2, keyPhrasesActionsResults.FirstOrDefault().Result.Count);

            Assert.IsNotNull(entitiesActionsResults);
            Assert.AreEqual(2, entitiesActionsResults.FirstOrDefault().Result.Count);

            Assert.IsNotNull(piiActionsResults);
            Assert.AreEqual(2, piiActionsResults.FirstOrDefault().Result.Count);

            Assert.IsNotNull(entityLinkingActionsResults);
            Assert.AreEqual(2, entityLinkingActionsResults.FirstOrDefault().Result.Count);

            Assert.IsNotNull(analyzeSentimentActionsResults);
            Assert.AreEqual(2, analyzeSentimentActionsResults.FirstOrDefault().Result.Count);
        }
Exemplo n.º 15
0
        public async Task AnalyzeOperationAsync()
        {
            string endpoint = TestEnvironment.Endpoint;
            string apiKey   = TestEnvironment.ApiKey;

            var client = new TextAnalyticsClient(new Uri(endpoint), new AzureKeyCredential(apiKey), CreateSampleOptions());

            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.";

            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!";

            var batchDocuments = new List <TextDocumentInput>
            {
                new TextDocumentInput("1", documentA)
                {
                    Language = "en",
                },
                new TextDocumentInput("2", documentB)
                {
                    Language = "en",
                }
            };

            TextAnalyticsActions actions = new TextAnalyticsActions()
            {
                ExtractKeyPhrasesActions = new List <ExtractKeyPhrasesAction>()
                {
                    new ExtractKeyPhrasesAction()
                },
                RecognizeEntitiesActions = new List <RecognizeEntitiesAction>()
                {
                    new RecognizeEntitiesAction()
                },
                DisplayName = "AnalyzeOperationSample"
            };

            AnalyzeActionsOperation operation = await client.StartAnalyzeActionsAsync(batchDocuments, actions);

            await operation.WaitForCompletionAsync();

            Console.WriteLine($"Status: {operation.Status}");
            Console.WriteLine($"Created On: {operation.CreatedOn}");
            Console.WriteLine($"Expires On: {operation.ExpiresOn}");
            Console.WriteLine($"Last modified: {operation.LastModified}");
            if (!string.IsNullOrEmpty(operation.DisplayName))
            {
                Console.WriteLine($"Display name: {operation.DisplayName}");
            }
            Console.WriteLine($"Total actions: {operation.ActionsTotal}");
            Console.WriteLine($"  Succeeded actions: {operation.ActionsSucceeded}");
            Console.WriteLine($"  Failed actions: {operation.ActionsFailed}");
            Console.WriteLine($"  In progress actions: {operation.ActionsInProgress}");

            await foreach (AnalyzeActionsResult documentsInPage in operation.Value)
            {
                IReadOnlyCollection <ExtractKeyPhrasesActionResult> keyPhrasesResults = documentsInPage.ExtractKeyPhrasesResults;
                IReadOnlyCollection <RecognizeEntitiesActionResult> entitiesResults   = documentsInPage.RecognizeEntitiesResults;

                Console.WriteLine("Recognized Entities");
                int docNumber = 1;
                foreach (RecognizeEntitiesActionResult entitiesActionResults in entitiesResults)
                {
                    Console.WriteLine($" Action name: {entitiesActionResults.ActionName}");
                    foreach (RecognizeEntitiesResult documentResults in entitiesActionResults.DocumentsResults)
                    {
                        Console.WriteLine($" Document #{docNumber++}");
                        Console.WriteLine($"  Recognized the following {documentResults.Entities.Count} entities:");

                        foreach (CategorizedEntity entity in documentResults.Entities)
                        {
                            Console.WriteLine($"  Entity: {entity.Text}");
                            Console.WriteLine($"  Category: {entity.Category}");
                            Console.WriteLine($"  Offset: {entity.Offset}");
                            Console.WriteLine($"  Length: {entity.Length}");
                            Console.WriteLine($"  ConfidenceScore: {entity.ConfidenceScore}");
                            Console.WriteLine($"  SubCategory: {entity.SubCategory}");
                        }
                        Console.WriteLine("");
                    }
                }

                Console.WriteLine("Key Phrases");
                docNumber = 1;
                foreach (ExtractKeyPhrasesActionResult keyPhrasesActionResult in keyPhrasesResults)
                {
                    foreach (ExtractKeyPhrasesResult documentResults in keyPhrasesActionResult.DocumentsResults)
                    {
                        Console.WriteLine($" Document #{docNumber++}");
                        Console.WriteLine($"  Recognized the following {documentResults.KeyPhrases.Count} Keyphrases:");

                        foreach (string keyphrase in documentResults.KeyPhrases)
                        {
                            Console.WriteLine($"  {keyphrase}");
                        }
                        Console.WriteLine("");
                    }
                }
            }
        }
Exemplo n.º 16
0
        public async Task AnalyzeOperationWithMultipleActionsOfSameType()
        {
            TextAnalyticsClient client = GetClient();

            var batchDocuments = new List <TextDocumentInput>
            {
                new TextDocumentInput("1", "Microsoft was founded by Bill Gates and Paul Allen.")
                {
                    Language = "en",
                },
                new TextDocumentInput("2", "Mi perro y mi gato tienen que ir al veterinario.")
                {
                    Language = "es",
                }
            };

            TextAnalyticsActions batchActions = new TextAnalyticsActions()
            {
                ExtractKeyPhrasesActions = new List <ExtractKeyPhrasesAction>()
                {
                    new ExtractKeyPhrasesAction()
                    {
                        ActionName = "DisableServaiceLogsTrue", DisableServiceLogs = true
                    },
                    new ExtractKeyPhrasesAction()
                    {
                        ActionName = "DisableServiceLogsFalse"
                    },
                },
                RecognizeEntitiesActions = new List <RecognizeEntitiesAction>()
                {
                    new RecognizeEntitiesAction()
                    {
                        ActionName = "DisableServiceLogsTrue", DisableServiceLogs = true
                    },
                    new RecognizeEntitiesAction()
                    {
                        ActionName = "DisableServiceLogsFalse"
                    },
                },
                RecognizePiiEntitiesActions = new List <RecognizePiiEntitiesAction>()
                {
                    new RecognizePiiEntitiesAction()
                    {
                        ActionName = "DisableServiceLogsTrue", DisableServiceLogs = true
                    },
                    new RecognizePiiEntitiesAction()
                    {
                        ActionName = "DisableServiceLogsFalse"
                    },
                },
                RecognizeLinkedEntitiesActions = new List <RecognizeLinkedEntitiesAction>()
                {
                    new RecognizeLinkedEntitiesAction()
                    {
                        ActionName = "DisableServiceLogsTrue", DisableServiceLogs = true
                    },
                    new RecognizeLinkedEntitiesAction()
                    {
                        ActionName = "DisableServiceLogsFalse"
                    },
                },
                AnalyzeSentimentActions = new List <AnalyzeSentimentAction>()
                {
                    new AnalyzeSentimentAction()
                    {
                        ActionName = "DisableServiceLogsTrue", DisableServiceLogs = true
                    },
                    new AnalyzeSentimentAction()
                    {
                        ActionName = "DisableServiceLogsFalse"
                    },
                },
                RecognizeCustomEntitiesActions = new List <RecognizeCustomEntitiesAction>()
                {
                    new RecognizeCustomEntitiesAction(TestEnvironment.RecognizeCustomEntitiesProjectName, TestEnvironment.RecognizeCustomEntitiesDeploymentName)
                    {
                        ActionName = "DisableServiceLogsTrue", DisableServiceLogs = true
                    },
                    new RecognizeCustomEntitiesAction(TestEnvironment.RecognizeCustomEntitiesProjectName, TestEnvironment.RecognizeCustomEntitiesDeploymentName)
                    {
                        ActionName = "DisableServiceLogsFalse"
                    },
                },
                SingleCategoryClassifyActions = new List <SingleCategoryClassifyAction>()
                {
                    new SingleCategoryClassifyAction(TestEnvironment.SingleClassificationProjectName, TestEnvironment.SingleClassificationDeploymentName)
                    {
                        ActionName = "DisableServiceLogsTrue", DisableServiceLogs = true
                    },
                    new SingleCategoryClassifyAction(TestEnvironment.SingleClassificationProjectName, TestEnvironment.SingleClassificationDeploymentName)
                    {
                        ActionName = "DisableServiceLogsFalse"
                    },
                },
                MultiCategoryClassifyActions = new List <MultiCategoryClassifyAction>()
                {
                    new MultiCategoryClassifyAction(TestEnvironment.MultiClassificationProjectName, TestEnvironment.MultiClassificationDeploymentName)
                    {
                        ActionName = "DisableServiceLogsTrue", DisableServiceLogs = true
                    },
                    new MultiCategoryClassifyAction(TestEnvironment.MultiClassificationProjectName, TestEnvironment.MultiClassificationDeploymentName)
                    {
                        ActionName = "DisableServiceLogsFalse"
                    },
                },
                DisplayName = "AnalyzeOperationWithMultipleTasksOfSameType"
            };

            AnalyzeActionsOperation operation = await client.StartAnalyzeActionsAsync(batchDocuments, batchActions);

            Assert.AreEqual(0, operation.ActionsFailed);
            Assert.AreEqual(0, operation.ActionsSucceeded);
            Assert.AreEqual(0, operation.ActionsInProgress);
            Assert.AreEqual(0, operation.ActionsTotal);

            await operation.WaitForCompletionAsync();

            Assert.AreEqual(0, operation.ActionsFailed);
            Assert.AreEqual(16, operation.ActionsSucceeded);
            Assert.AreEqual(0, operation.ActionsInProgress);
            Assert.AreEqual(16, operation.ActionsTotal);
            Assert.AreNotEqual(new DateTimeOffset(), operation.CreatedOn);
            Assert.AreNotEqual(new DateTimeOffset(), operation.LastModified);
            Assert.AreNotEqual(new DateTimeOffset(), operation.ExpiresOn);

            //Take the first page
            AnalyzeActionsResult resultCollection = operation.Value.ToEnumerableAsync().Result.FirstOrDefault();

            IReadOnlyCollection <RecognizeEntitiesActionResult>       entitiesActionsResults         = resultCollection.RecognizeEntitiesResults;
            IReadOnlyCollection <ExtractKeyPhrasesActionResult>       keyPhrasesActionsResults       = resultCollection.ExtractKeyPhrasesResults;
            IReadOnlyCollection <RecognizePiiEntitiesActionResult>    piiActionsResults              = resultCollection.RecognizePiiEntitiesResults;
            IReadOnlyCollection <RecognizeLinkedEntitiesActionResult> entityLinkingActionsResults    = resultCollection.RecognizeLinkedEntitiesResults;
            IReadOnlyCollection <AnalyzeSentimentActionResult>        analyzeSentimentActionsResults = resultCollection.AnalyzeSentimentResults;
            IReadOnlyCollection <RecognizeCustomEntitiesActionResult> recognizeCustomEntitiesResults = resultCollection.RecognizeCustomEntitiesResults;
            IReadOnlyCollection <SingleCategoryClassifyActionResult>  singleCategoryClassifyResults  = resultCollection.SingleCategoryClassifyResults;
            IReadOnlyCollection <MultiCategoryClassifyActionResult>   multiCategoryClassifyResults   = resultCollection.MultiCategoryClassifyResults;

            Assert.IsNotNull(keyPhrasesActionsResults);
            Assert.IsNotNull(entitiesActionsResults);
            Assert.IsNotNull(piiActionsResults);
            Assert.IsNotNull(entityLinkingActionsResults);
            Assert.IsNotNull(analyzeSentimentActionsResults);
            Assert.IsNotNull(recognizeCustomEntitiesResults);
            Assert.IsNotNull(singleCategoryClassifyResults);
            Assert.IsNotNull(multiCategoryClassifyResults);
            Assert.AreEqual("AnalyzeOperationWithMultipleTasks", operation.DisplayName);
        }
Exemplo n.º 17
0
        public async Task AnalyzeOperationWithMultipleActions()
        {
            TextAnalyticsClient client = GetClient();

            var batchDocuments = new List <TextDocumentInput>
            {
                new TextDocumentInput("1", "Microsoft was founded by Bill Gates and Paul Allen.")
                {
                    Language = "en",
                },
                new TextDocumentInput("2", "Mi perro y mi gato tienen que ir al veterinario.")
                {
                    Language = "es",
                }
            };

            TextAnalyticsActions batchActions = new TextAnalyticsActions()
            {
                ExtractKeyPhrasesActions = new List <ExtractKeyPhrasesAction>()
                {
                    new ExtractKeyPhrasesAction()
                },
                RecognizeEntitiesActions = new List <RecognizeEntitiesAction>()
                {
                    new RecognizeEntitiesAction()
                },
                RecognizePiiEntitiesActions = new List <RecognizePiiEntitiesAction>()
                {
                    new RecognizePiiEntitiesAction()
                },
                RecognizeLinkedEntitiesActions = new List <RecognizeLinkedEntitiesAction>()
                {
                    new RecognizeLinkedEntitiesAction()
                },
                AnalyzeSentimentActions = new List <AnalyzeSentimentAction>()
                {
                    new AnalyzeSentimentAction()
                },
                DisplayName = "AnalyzeOperationWithMultipleTasks"
            };

            AnalyzeActionsOperation operation = await client.StartAnalyzeActionsAsync(batchDocuments, batchActions);

            Assert.AreEqual(0, operation.ActionsFailed);
            Assert.AreEqual(0, operation.ActionsSucceeded);
            Assert.AreEqual(0, operation.ActionsInProgress);
            Assert.AreEqual(0, operation.ActionsTotal);

            await operation.WaitForCompletionAsync();

            Assert.AreEqual(0, operation.ActionsFailed);
            Assert.AreEqual(5, operation.ActionsSucceeded);
            Assert.AreEqual(0, operation.ActionsInProgress);
            Assert.AreEqual(5, operation.ActionsTotal);
            Assert.AreNotEqual(new DateTimeOffset(), operation.CreatedOn);
            Assert.AreNotEqual(new DateTimeOffset(), operation.LastModified);
            Assert.AreNotEqual(new DateTimeOffset(), operation.ExpiresOn);

            //Take the first page
            AnalyzeActionsResult resultCollection = operation.Value.ToEnumerableAsync().Result.FirstOrDefault();

            IReadOnlyCollection <RecognizeEntitiesActionResult>       entitiesActionsResults         = resultCollection.RecognizeEntitiesActionsResults;
            IReadOnlyCollection <ExtractKeyPhrasesActionResult>       keyPhrasesActionsResults       = resultCollection.ExtractKeyPhrasesActionsResults;
            IReadOnlyCollection <RecognizePiiEntitiesActionResult>    piiActionsResults              = resultCollection.RecognizePiiEntitiesActionsResults;
            IReadOnlyCollection <RecognizeLinkedEntitiesActionResult> entityLinkingActionsResults    = resultCollection.RecognizeLinkedEntitiesActionsResults;
            IReadOnlyCollection <AnalyzeSentimentActionResult>        analyzeSentimentActionsResults = resultCollection.AnalyzeSentimentActionsResults;

            Assert.IsNotNull(keyPhrasesActionsResults);
            Assert.IsNotNull(entitiesActionsResults);
            Assert.IsNotNull(piiActionsResults);
            Assert.IsNotNull(entityLinkingActionsResults);
            Assert.AreEqual("AnalyzeOperationWithMultipleTasks", operation.DisplayName);

            // Keyphrases
            ExtractKeyPhrasesResultCollection keyPhrasesResults = keyPhrasesActionsResults.FirstOrDefault().Result;

            Assert.AreEqual(2, keyPhrasesResults.Count);

            var keyPhrasesListId1 = new List <string> {
                "Bill Gates", "Paul Allen", "Microsoft"
            };
            var keyPhrasesListId2 = new List <string> {
                "gato", "perro", "veterinario"
            };

            foreach (string keyphrase in keyPhrasesResults[0].KeyPhrases)
            {
                Assert.IsTrue(keyPhrasesListId1.Contains(keyphrase));
            }

            foreach (string keyphrase in keyPhrasesResults[1].KeyPhrases)
            {
                Assert.IsTrue(keyPhrasesListId2.Contains(keyphrase));
            }

            // Entities
            RecognizeEntitiesResultCollection entitiesResult = entitiesActionsResults.FirstOrDefault().Result;

            Assert.AreEqual(2, entitiesResult.Count);

            Assert.AreEqual(3, entitiesResult[0].Entities.Count);

            var entitiesList = new List <string> {
                "Bill Gates", "Microsoft", "Paul Allen"
            };

            foreach (CategorizedEntity entity in entitiesResult[0].Entities)
            {
                Assert.IsTrue(entitiesList.Contains(entity.Text));
                Assert.IsNotNull(entity.Category);
                Assert.IsNotNull(entity.Offset);
                Assert.IsNotNull(entity.ConfidenceScore);
            }

            // PII
            RecognizePiiEntitiesResultCollection piiResult = piiActionsResults.FirstOrDefault().Result;

            Assert.AreEqual(2, piiResult.Count);

            Assert.AreEqual(3, piiResult[0].Entities.Count);
            Assert.IsNotNull(piiResult[0].Id);
            Assert.IsNotNull(piiResult[0].Entities);
            Assert.IsNotNull(piiResult[0].Error);

            // Entity Linking
            RecognizeLinkedEntitiesResultCollection entityLinkingResult = entityLinkingActionsResults.FirstOrDefault().Result;

            Assert.AreEqual(2, entityLinkingResult.Count);

            Assert.AreEqual(3, entityLinkingResult[0].Entities.Count);
            Assert.IsNotNull(entityLinkingResult[0].Id);
            Assert.IsNotNull(entityLinkingResult[0].Entities);
            Assert.IsNotNull(entityLinkingResult[0].Error);

            foreach (LinkedEntity entity in entityLinkingResult[0].Entities)
            {
                if (entity.Name == "Bill Gates")
                {
                    Assert.AreEqual("Bill Gates", entity.DataSourceEntityId);
                    Assert.AreEqual("Wikipedia", entity.DataSource);
                }

                if (entity.Name == "Microsoft")
                {
                    Assert.AreEqual("Microsoft", entity.DataSourceEntityId);
                    Assert.AreEqual("Wikipedia", entity.DataSource);
                }
            }

            // Analyze sentiment
            AnalyzeSentimentResultCollection analyzeSentimentResult = analyzeSentimentActionsResults.FirstOrDefault().Result;

            Assert.AreEqual(2, analyzeSentimentResult.Count);

            Assert.AreEqual(TextSentiment.Neutral, analyzeSentimentResult[0].DocumentSentiment.Sentiment);
            Assert.AreEqual(TextSentiment.Neutral, analyzeSentimentResult[1].DocumentSentiment.Sentiment);
        }
        public async Task MultiCategoryClassifyConvenienceAsync()
        {
            // Create a text analytics client.
            string endpoint = TestEnvironment.Endpoint;
            string apiKey   = TestEnvironment.ApiKey;

            var client = new TextAnalyticsClient(new Uri(endpoint), new AzureKeyCredential(apiKey), CreateSampleOptions());

            #region Snippet:TextAnalyticsMultiCategoryClassifyAsync
            // Get input document.
            string document = @"I need a reservation for an indoor restaurant in China. Please don't stop the music. Play music and add it to my playlist.";

            // 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 <string>
            {
                document
            };

            // Set project and deployment names of the target model
#if SNIPPET
            // To train a model to classify your documents, see https://aka.ms/azsdk/textanalytics/customfunctionalities
            string projectName    = "<projectName>";
            string deploymentName = "<deploymentName>";
#else
            string projectName    = TestEnvironment.MultiClassificationProjectName;
            string deploymentName = TestEnvironment.MultiClassificationDeploymentName;
#endif

            var multiCategoryClassifyAction = new MultiCategoryClassifyAction(projectName, deploymentName);

            TextAnalyticsActions actions = new TextAnalyticsActions()
            {
                MultiCategoryClassifyActions = new List <MultiCategoryClassifyAction>()
                {
                    multiCategoryClassifyAction
                }
            };

            // Start analysis process.
            AnalyzeActionsOperation operation = await client.StartAnalyzeActionsAsync(batchInput, actions);

            await operation.WaitForCompletionAsync();

            #endregion Snippet:TextAnalyticsMultiCategoryClassifyAsync

            #region Snippet:TextAnalyticsMultiCategoryClassifyOperationStatus
            // 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();
            #endregion Snippet:TextAnalyticsMultiCategoryClassifyOperationStatus

            #region Snippet:TextAnalyticsMultiCategoryClassifyAsyncViewResults
            // View operation results.
            await foreach (AnalyzeActionsResult documentsInPage in operation.Value)
            {
                IReadOnlyCollection <MultiCategoryClassifyActionResult> multiClassificationActionResults = documentsInPage.MultiCategoryClassifyResults;

                foreach (MultiCategoryClassifyActionResult classificationActionResults in multiClassificationActionResults)
                {
                    Console.WriteLine($" Action name: {classificationActionResults.ActionName}");
                    foreach (MultiCategoryClassifyResult documentResults in classificationActionResults.DocumentsResults)
                    {
                        if (documentResults.Classifications.Count > 0)
                        {
                            Console.WriteLine($"  The following classes were predicted for this document:");

                            foreach (ClassificationCategory classification in documentResults.Classifications)
                            {
                                Console.WriteLine($"  Class category \"{classification.Category}\" predicted with a confidence score of {classification.ConfidenceScore}.");
                            }

                            Console.WriteLine();
                        }
                    }
                }
            }
            #endregion Snippet:TextAnalyticsMultiCategoryClassifyAsyncViewResults
        }