private static async Task <EvaluateImageResult> EvaluateImage(string key, string type, string urlImage, Stream rawImage, bool cacheImage) { // init EvaluateImageResult result = null; var moderator = new ModeratorClient(key); // go switch (type) { case "url": { result = await moderator.EvaluateImageAsync(urlImage, DataRepresentationType.Url, cacheImage); break; } case "raw": { result = await moderator.EvaluateImageAsync(rawImage, cacheImage); break; } } return(result); }
/// <summary> /// Moderates the text to check for inappropriate content /// </summary> /// <param name="textToScreen">Text to be moderated</param> /// <param name="contentType">Content Type of the input text to be moderated</param> /// <param name="language">Language of the input text to be moderated</param> /// <param name="autoCorrect">Enable Autocorrection on the text to be moderated</param> /// <param name="identifyUrls">Enable Url identification on the text to be moderated</param> /// <param name="detectPii">Detect Personal Identifiable Information on the text moderation</param> /// <param name="listId">ListId for the Content Moderation API</param> /// <returns>Moderated string with the inappropriate words highlighted</returns> public static async Task <ImageContract.EvaluateImageResult> ModerateImage(ModeratorApiImageModel moderationImageApiInput) { // Invoke the Moderation Client API ModeratorClient moderatorClient = new ModeratorClient(SUBSCRIPTIONKEY); // Return the status as inappropriate image return(await moderatorClient.EvaluateImageAsync(moderationImageApiInput.content, ImageContract.DataRepresentationType.Url, moderationImageApiInput.cacheImage)); }
/// <summary> /// Moderates the text to check for inappropriate content /// </summary> /// <param name="textToScreen">Text to be moderated</param> /// <param name="contentType">Content Type of the input text to be moderated</param> /// <param name="language">Language of the input text to be moderated</param> /// <param name="autoCorrect">Enable Autocorrection on the text to be moderated</param> /// <param name="identifyUrls">Enable Url identification on the text to be moderated</param> /// <param name="detectPii">Detect Personal Identifiable Information on the text moderation</param> /// <param name="listId">ListId for the Content Moderation API</param> /// <returns>Moderated string with the inappropriate words highlighted</returns> static async Task <bool> ModerateImage(ModeratorApiImageModel moderationImageApiInput) { bool responseStatus = false; // Invoke the Moderation Client API ModeratorClient moderatorClient = new ModeratorClient(SUBSCRIPTIONKEY); var matchAfterDeleteRes = await moderatorClient.EvaluateImageAsync(moderationImageApiInput.content, ImageContract.DataRepresentationType.Url, moderationImageApiInput.cacheImage); // Analyze the reponse object for inappropriate content responseStatus = ((ImageContract.EvaluateImageResult)matchAfterDeleteRes).IsImageAdultClassified || ((ImageContract.EvaluateImageResult)matchAfterDeleteRes).IsImageRacyClassified; // Return the status as inappropriate image return(responseStatus); }
/// <summary> /// Moderates the text to check for inappropriate content /// </summary> /// <param name="textToScreen">Text to be moderated</param> /// <param name="contentType">Content Type of the input text to be moderated</param> /// <param name="language">Language of the input text to be moderated</param> /// <param name="autoCorrect">Enable Autocorrection on the text to be moderated</param> /// <param name="identifyUrls">Enable Url identification on the text to be moderated</param> /// <param name="detectPii">Detect Personal Identifiable Information on the text moderation</param> /// <param name="listId">ListId for the Content Moderation API</param> /// <returns>Moderated string with the inappropriate words highlighted</returns> public static async Task <String> ModerateText(ModeratorApiTextModel moderationTextApiInput) { var inputText = moderationTextApiInput.textToScreen; var responseText = string.Empty; var wrapTemplate = "<span data-cls='moderator-highlight'>{0}</span>"; var chrCount = 0; List <string> convertedItem = new List <string>(); // Invoke the Moderation Client API ModeratorClient moderatorClient = new ModeratorClient(SUBSCRIPTIONKEY); // Split the job into batches of character limit var lines = inputText.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) .GroupBy(w => (chrCount += w.Length + 1) / APICHARACTERLIMIT) .Select(g => string.Join(" ", g)); // Perform the text operation based on the character limit the API supports foreach (var line in lines) { var splitText = line; var moderatedTextResponse = await moderatorClient.ScreenTextAsync(splitText, moderationTextApiInput.contentType, moderationTextApiInput.language, moderationTextApiInput.autoCorrect, moderationTextApiInput.identifyUrls, moderationTextApiInput.detectPii, moderationTextApiInput.listId); // Analyze the reponse object for inappropriate content foreach (TextContract.MatchTerm item in ((TextContract.ScreenTextResult)moderatedTextResponse).Terms) { // Process the current inappropriate content, if not already processed if (!convertedItem.Contains(item.Term)) { // Keep Track of the inappropriate word convertedItem.Add(item.Term); // Wrap it with a span tag and class to highlight it splitText = Regex.Replace(splitText, item.Term, string.Format(wrapTemplate, item.Term), RegexOptions.Singleline | RegexOptions.IgnoreCase); } } // Merge the moderated text back into the final response responseText += splitText.Replace("data-cls", "class"); } // Return the final response with the inappropriate words highlighted Console.WriteLine(responseText); return(responseText); }
private static async Task RunContentModeration() { Console.ForegroundColor = ConsoleColor.Blue; Console.WriteLine("Begining content moderation ({0})", DateTime.Now.ToString()); var client = new ModeratorClient(contentModeratorApiKey); foreach (var conversation in conversations) { foreach (var message in conversation.Messages) { try { var screenedText = await client.ScreenTextAsync(message.Text, Constants.MediaType.Plain, message.Metadata.LanguageName, true, true, true, ""); if (screenedText.Terms != null) { message.Metadata.ContainsProfanity = true; } else { message.Metadata.ContainsProfanity = false; } Console.Write("Conversation {0} | Message {1} | Contains Profanity {2}", conversation.Id, message.Id, message.Metadata.ContainsProfanity); } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(); Console.WriteLine("Exception encountered ({0})", DateTime.Now.ToString()); Console.WriteLine("Conversation {0} | Message {1}", conversation.Id, message.Id); Console.WriteLine(ex.Message); } } } Console.WriteLine("Content moderation complete ({0})", DateTime.Now.ToString()); Console.WriteLine(); }
public MainForm() { InitializeComponent(); this.client = new ModeratorClient(Properties.Settings.Default.ContentModerator_SubscriptionKey); webBody.ScriptErrorsSuppressed = true; outlookApp = new Microsoft.Office.Interop.Outlook.Application(); outlookNamespace = outlookApp.GetNamespace("MAPI"); accounts = outlookApp.Session.Accounts; foreach (Microsoft.Office.Interop.Outlook.Account account in accounts) { toolStripComboBox_Accounts.Items.Add(account.DisplayName); } if (accountsExist()) { toolStripComboBox_Accounts.SelectedIndex = 0; } }
public ModeratorTests() { this.client = new ModeratorClient(ConfigurationManager.AppSettings["subscriptionkey"]); }
public ImageListAndMatchScenarios() { this.imageListclient = new ListManagementClient(ConfigurationManager.AppSettings["subscriptionkey"]); this.moderatorClient = new ModeratorClient(ConfigurationManager.AppSettings["subscriptionkey"]); }
public TextListScreenScenarios() { this.textListclient = new ListManagementClient(ConfigurationManager.AppSettings["subscriptionkey"]); this.moderatorClient = new ModeratorClient(ConfigurationManager.AppSettings["subscriptionkey"]); }
private static async Task GetImageEvaluationResult(Stream stream, Boolean cache) { ModeratorClient client = new ModeratorClient(SUBSCRIPTIONKEY); var imageEvaluationResult = await client.EvaluateImageAsync(stream, false); }