// Matt Content Moderator Part 1 public static void CallContentModeratorAPIText() { try { // Get the file name Console.WriteLine("Please enter a some text to analyze:"); var message = Console.ReadLine(); // Create query var query = new ContentModeratorTextQuery(); query.AutoCorrect = true; query.Classify = true; query.PII = true; query.Text = message; query.Endpoint = Constants.CONTENT_MODERATOR_TEXT_URL; query.SubscriptionKey = Constants.CONTENT_MODERATOR_KEY; var result = ContentModeratorService.CallContentModeratorTextAPI(query).Result; ExportJSON(JsonConvert.SerializeObject(result)); Console.WriteLine("\nPress Enter to exit "); Console.ReadLine(); } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); Console.ReadLine(); throw; } }
private async Task RunContentModeratorServicesOnNewsFeedPostAsync(NewsFeedPost newsFeedPost) { if (IsMessageEditorTextValid(newsFeedPost.Message)) { var contentModeratorTextResults = await ContentModeratorService.ScreenTextAsync(newsFeedPost.Message, TermListId); ValidatePostMessage(contentModeratorTextResults); newsFeedPost.MessageModeratorResults = contentModeratorTextResults; } }
private async Task RunCognitiveServicesOnNewsFeedPostAsync(Stream stream, NewsFeedPost newsFeedPost) { Task <ContentModeratorTextResults> contentModeratorTextTask = null; if (IsMessageEditorTextValid(newsFeedPost.Message)) { contentModeratorTextTask = ContentModeratorService.ScreenTextAsync(newsFeedPost.Message, TermListId); } var computerVisionTask = ComputerVisionService.GetComputerVisionResultsAsync(stream); var tasks = new List <Task>() { computerVisionTask }; if (contentModeratorTextTask != null) { tasks.Add(contentModeratorTextTask); } await Task.WhenAll(tasks); if (computerVisionTask.IsFaulted) { throw new Exception("Something went wrong with your image upload. Please try again later."); } ValidatePostImage(computerVisionTask.Result); newsFeedPost.ImageVisionResults = computerVisionTask.Result; PopulateCaptionProperty(newsFeedPost); PopulateDescriptionTagsProperty(newsFeedPost); PopulateCelebritiesProperty(newsFeedPost); PopulateLandmarksProperty(newsFeedPost); PopulateBrandsProperty(newsFeedPost); if (contentModeratorTextTask != null) { if (contentModeratorTextTask.IsFaulted) { throw new Exception("Something went wrong with your message post. Please try again later."); } ValidatePostMessage(contentModeratorTextTask.Result); newsFeedPost.MessageModeratorResults = contentModeratorTextTask.Result; } }
// Matt Content Moderator Part 3 public static void CallContentModeratorAPIImage() { try { // Get the file name Console.WriteLine("Please enter a file name:"); var imagePath = Console.ReadLine(); Console.WriteLine("Please enter a content type: (image/jpeg) is default"); var contentType = "image/jpeg"; var line = Console.ReadLine(); if (!String.IsNullOrEmpty(line)) { contentType = line; } if (File.Exists(imagePath)) { var fileName = new FileInfo(imagePath).Name; Console.WriteLine("Getting image Insights for image: " + fileName); Console.WriteLine(); var query = new ContentModeratorImageQuery(); query.ImagePath = imagePath; query.ContentType = contentType; query.Endpoint = Constants.CONTENT_MODERATOR_IMAGE_URL; query.SubscriptionKey = Constants.CONTENT_MODERATOR_KEY; var result = ContentModeratorService.CallContentModeratorImageAPI(query).Result; ExportJSON(JsonConvert.SerializeObject(result)); Console.WriteLine("\nPress Enter to exit "); Console.ReadLine(); } else { Console.WriteLine("Invalid Image Path"); Console.ReadLine(); } } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); Console.ReadLine(); throw; } }