Exemplo n.º 1
0
 private void AddCategoriesToContentModeratorTextResults(Screen screen, ContentModeratorTextResults contentModeratorTextResults)
 {
     if (screen.Classification != null)
     {
         contentModeratorTextResults.IsReviewRecommended          = screen.Classification.ReviewRecommended ?? false;
         contentModeratorTextResults.SexuallyExplicitConfidence   = screen.Classification.Category1.Score ?? 0.0;
         contentModeratorTextResults.SexuallySuggestiveConfidence = screen.Classification.Category2.Score ?? 0.0;
         contentModeratorTextResults.OffensiveConfidence          = screen.Classification.Category3.Score ?? 0.0;
     }
 }
Exemplo n.º 2
0
        private void AddTermsToContentModeratorTextResults(Screen screen, ContentModeratorTextResults contentModeratorTextResults)
        {
            if (screen.Terms != null)
            {
                foreach (var term in screen.Terms)
                {
                    var termResultItem = new ContentModeratorTextResultItem
                    {
                        Text  = term.Term,
                        Index = term.Index ?? 0,
                        Label = term.ListId.HasValue ? term.ListId.Value.ToString() : null
                    };

                    contentModeratorTextResults.ProfaneTerms.Add(termResultItem);
                }

                contentModeratorTextResults.DoesContainProfaneTerms = contentModeratorTextResults.ProfaneTerms.Count > 0;
            }
        }
Exemplo n.º 3
0
        public async Task <ContentModeratorTextResults> ScreenTextAsync(string text, string termListId)
        {
            if (termListId == string.Empty)
            {
                termListId = null;
            }

            var contentModeratorTextResults = new ContentModeratorTextResults();

            try
            {
                using (var contentModeratorClient = new ContentModeratorClient(new ApiKeyServiceClientCredentials(_key))
                {
                    Endpoint = _endpoint
                })
                {
                    var byteArray = Encoding.UTF8.GetBytes(text);

                    using (var memoryStream = new MemoryStream(byteArray))
                    {
                        var screen = await contentModeratorClient.TextModeration.ScreenTextAsync("text/plain", memoryStream, listId : termListId);

                        AddTermsToContentModeratorTextResults(screen, contentModeratorTextResults);

                        AddCategoriesToContentModeratorTextResults(screen, contentModeratorTextResults);

                        AddPiiToContentModeratorTextResults(screen, contentModeratorTextResults);
                    }
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message, e);
            }

            return(contentModeratorTextResults);
        }
Exemplo n.º 4
0
        private void AddPiiToContentModeratorTextResults(Screen screen, ContentModeratorTextResults contentModeratorTextResults)
        {
            if (screen.PII != null)
            {
                if (screen.PII.Address != null)
                {
                    foreach (var address in screen.PII.Address)
                    {
                        var resultItem = new ContentModeratorTextResultItem
                        {
                            Index = address.Index ?? 0,
                            Text  = address.Text,
                            Label = "Address"
                        };
                        contentModeratorTextResults.Pii.Add(resultItem);
                    }
                }

                if (screen.PII.Email != null)
                {
                    foreach (var email in screen.PII.Email)
                    {
                        var resultItem = new ContentModeratorTextResultItem
                        {
                            Index = email.Index ?? 0,
                            Text  = email.Text,
                            Label = "Email"
                        };
                        contentModeratorTextResults.Pii.Add(resultItem);
                    }
                }

                if (screen.PII.IPA != null)
                {
                    foreach (var ipa in screen.PII.IPA)
                    {
                        var resultItem = new ContentModeratorTextResultItem
                        {
                            Index = ipa.Index ?? 0,
                            Text  = ipa.Text,
                            Label = "IPA"
                        };
                        contentModeratorTextResults.Pii.Add(resultItem);
                    }
                }

                if (screen.PII.Phone != null)
                {
                    foreach (var phone in screen.PII.Phone)
                    {
                        var resultItem = new ContentModeratorTextResultItem
                        {
                            Index = phone.Index ?? 0,
                            Text  = phone.CountryCode + " " + phone.Text,
                            Label = "Phone"
                        };
                        contentModeratorTextResults.Pii.Add(resultItem);
                    }
                }

                if (screen.PII.SSN != null)
                {
                    foreach (var ssn in screen.PII.SSN)
                    {
                        var resultItem = new ContentModeratorTextResultItem
                        {
                            Index = ssn.Index ?? 0,
                            Text  = ssn.Text,
                            Label = "SSN"
                        };
                        contentModeratorTextResults.Pii.Add(resultItem);
                    }
                }

                contentModeratorTextResults.DoesContainPii = contentModeratorTextResults.Pii.Count > 0;
            }
        }