Skip to content

Commit 55b7727

Browse files
committed
add snippet tags
1 parent 31b2287 commit 55b7727

File tree

1 file changed

+25
-2
lines changed
  • documentation-samples/quickstarts/ContentModerator

1 file changed

+25
-2
lines changed

documentation-samples/quickstarts/ContentModerator/Program.cs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,11 @@ class Program
6969
// </snippet_text_vars>
7070

7171
// CREATE HUMAN REVIEWS FOR IMAGES
72+
// <snippet_review_urls>
7273
// The list of URLs of the images to create review jobs for.
7374
private static readonly string[] IMAGE_URLS_FOR_REVIEW = new string[] { "https://moderatorsampleimages.blob.core.windows.net/samples/sample5.png" };
75+
// </snippet_review_urls>
76+
// <snippet_review_vars>
7477
// The name of the team to assign the review to. Must be the team name used to create your Content Moderator website account.
7578
// If you do not yet have an account, follow this: https://docs.microsoft.com/en-us/azure/cognitive-services/content-moderator/quick-start
7679
// Select the gear symbol (settings)-->Credentials to retrieve it. Your team name is the Id associated with your subscription.
@@ -79,6 +82,7 @@ class Program
7982
// For example: https://westus.api.cognitive.microsoft.com/contentmoderator/review/v1.0
8083
// As reviewers complete reviews, results are sent using an HTTP POST request.
8184
private static readonly string ReviewsEndpoint = Environment.GetEnvironmentVariable("CONTENT_MODERATOR_REVIEWS_ENDPOINT");
85+
// </snippet_review_vars>
8286

8387
static void Main(string[] args)
8488
{
@@ -102,8 +106,10 @@ static void Main(string[] args)
102106
ModerateText(clientText, TextFile, TextOutputFile);
103107
// </snippet_textmod_call>
104108

109+
// <snippet_review_call>
105110
// Create image reviews for human reviewers
106111
CreateReviews(clientReviews, IMAGE_URLS_FOR_REVIEW, TEAM_NAME, ReviewsEndpoint);
112+
// </snippet_review_call>
107113

108114
Console.WriteLine();
109115
Console.WriteLine("End of the quickstart.");
@@ -124,7 +130,7 @@ public static ContentModeratorClient Authenticate(string key, string endpoint)
124130
return client;
125131
}
126132

127-
// <snippet_imagemod>
133+
// <snippet_imagemod_iterate>
128134
/*
129135
* IMAGE MODERATION
130136
* This example moderates images from URLs.
@@ -150,6 +156,8 @@ public static void ModerateImages(ContentModeratorClient client, string urlFile,
150156
{
151157
Console.WriteLine("Evaluating {0}...", Path.GetFileName(line));
152158
var imageUrl = new BodyModel("URL", line.Trim());
159+
// </snippet_imagemod_iterate>
160+
// <snippet_imagemod_analyze>
153161
var imageData = new EvaluationData
154162
{
155163
ImageUrl = imageUrl.Value,
@@ -175,6 +183,8 @@ public static void ModerateImages(ContentModeratorClient client, string urlFile,
175183
}
176184
}
177185
}
186+
// </snippet_imagemod_analyze>
187+
// <snippet_imagemod_save>
178188
// Save the moderation results to a file.
179189
using (StreamWriter outputWriter = new StreamWriter(outputFile, false))
180190
{
@@ -189,6 +199,7 @@ public static void ModerateImages(ContentModeratorClient client, string urlFile,
189199
Console.WriteLine();
190200
}
191201
}
202+
// </snippet_imagemod_save>
192203

193204
// <snippet_dataclass>
194205
// Contains the image moderation results for an image,
@@ -268,7 +279,7 @@ public static void ModerateText(ContentModeratorClient client, string inputFile,
268279
*
269280
* Prerequisistes:
270281
* 1. In your Content Moderator resource go to Resource Management -> Properties, then copy your Resource ID.
271-
* 2. Go to the Content Moderator website, https://{YOUR REGION}.contentmoderator.cognitive.microsoft.com.
282+
* 2. Go to the Content Moderator website.
272283
* 3. Click the gear sign (Settings) and go to "Credentials".
273284
* 4. Under "Whitelisted Resource Id(s)" paste your Resource ID, then select the "+" button to add it.
274285
* This enables the website to receive programmatic reviews from your Content Moderator resource in Azure.
@@ -278,6 +289,7 @@ public static void ModerateText(ContentModeratorClient client, string inputFile,
278289
* Use your Azure account with the review APIs:
279290
* https://docs.microsoft.com/en-us/azure/cognitive-services/content-moderator/review-tool-user-guide/configure
280291
*/
292+
// <snippet_review_item>
281293
// Associates the review ID (assigned by the service) to the internal.
282294
public class ReviewItem
283295
{
@@ -290,7 +302,9 @@ public class ReviewItem
290302
// The ID that the service assigned to the review.
291303
public string ReviewId;
292304
}
305+
// </snippet_review_item>
293306

307+
// <snippet_createreview_fields>
294308
// Create the reviews using the fixed list of images.
295309
private static void CreateReviews(ContentModeratorClient client, string[] ImageUrls, string teamName, string endpoint)
296310
{
@@ -324,7 +338,9 @@ private static void CreateReviews(ContentModeratorClient client, string[] ImageU
324338

325339
// The cached review information, associating a local content ID to the created review ID for each item.
326340
List<ReviewItem> reviewItems = new List<ReviewItem>();
341+
// </snippet_createreview_fields>
327342

343+
// <snippet_createreview_create>
328344
using (TextWriter outputWriter = new StreamWriter(OutputFile, false))
329345
{
330346
writer = outputWriter;
@@ -361,7 +377,9 @@ private static void CreateReviews(ContentModeratorClient client, string[] ImageU
361377
}
362378

363379
var reviewResponse = client.Reviews.CreateReviewsWithHttpMessagesAsync("application/json", teamName, requestInfo);
380+
// </snippet_createreview_create>
364381

382+
// <snippet_createreview_ids>
365383
// Update the local cache to associate the created review IDs with the associated content.
366384
var reviewIds = reviewResponse.Result.Body;
367385
for (int i = 0; i < reviewIds.Count; i++) { reviewItems[i].ReviewId = reviewIds[i]; }
@@ -380,7 +398,9 @@ private static void CreateReviews(ContentModeratorClient client, string[] ImageU
380398
WriteLine(outputWriter, JsonConvert.SerializeObject(reviewDetail.Result.Body, Formatting.Indented));
381399
Thread.Sleep(throttleRate);
382400
}
401+
// </snippet_createreview_ids>
383402

403+
// <snippet_createreview_results>
384404
Console.WriteLine();
385405
Console.WriteLine("Perform manual reviews on the Content Moderator site.");
386406
Console.WriteLine("Then, press any key to continue.");
@@ -412,14 +432,17 @@ private static void CreateReviews(ContentModeratorClient client, string[] ImageU
412432
}
413433
Console.WriteLine("--------------------------------------------------------------");
414434
}
435+
// </snippet_createreview_results>
415436

437+
// <snippet_writeline>
416438
// Helper function that writes a message to the log file, and optionally to the console.
417439
// If echo is set to true, details will be written to the console.
418440
private static void WriteLine(TextWriter writer, string message = null, bool echo = true)
419441
{
420442
writer.WriteLine(message ?? String.Empty);
421443
if (echo) { Console.WriteLine(message ?? String.Empty); }
422444
}
445+
// </snippet_writeline>
423446
/*
424447
* END - CREATE HUMAN IMAGE REVIEWS
425448
*/

0 commit comments

Comments
 (0)