public async Task AnalyzeOperationMultiCategoryClassifyWithDisableServiceLogs() { var mockResponse = new MockResponse(202); mockResponse.AddHeader(new HttpHeader("Operation-Location", "something/jobs/2a96a91f-7edf-4931-a880-3fdee1d56f15")); var mockTransport = new MockTransport(new[] { mockResponse, mockResponse }); var client = CreateTestClient(mockTransport); var documents = new List <string> { "Elon Musk is the CEO of SpaceX and Tesla." }; var actions = new MultiCategoryClassifyAction(FakeProjectName, FakeDeploymentName) { DisableServiceLogs = true }; TextAnalyticsActions batchActions = new TextAnalyticsActions() { MultiCategoryClassifyActions = new List <MultiCategoryClassifyAction>() { actions }, }; await client.StartAnalyzeActionsAsync(documents, batchActions); var contentString = GetString(mockTransport.Requests.Single().Content); string logging = contentString.Substring(contentString.IndexOf("loggingOptOut"), 19); var expectedContent = "loggingOptOut\":true"; Assert.AreEqual(expectedContent, logging); }
public void MultiCategoryClassifyConvenience() { // 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 = @"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 // To train a model to classify your documents, see https://aka.ms/azsdk/textanalytics/customfunctionalities string projectName = TestEnvironment.MultiClassificationProjectName; string deploymentName = TestEnvironment.MultiClassificationDeploymentName; var multiCategoryClassifyAction = new MultiCategoryClassifyAction(projectName, deploymentName); TextAnalyticsActions actions = new TextAnalyticsActions() { MultiCategoryClassifyActions = new List <MultiCategoryClassifyAction>() { multiCategoryClassifyAction } }; // 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 <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(); } } } } }
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 }