Class: Azure::CognitiveServices::ContentModerator::V1_0::TextModeration
- Inherits:
-
Object
- Object
- Azure::CognitiveServices::ContentModerator::V1_0::TextModeration
- Includes:
- MsRestAzure
- Defined in:
- lib/1.0/generated/azure_cognitiveservices_contentmoderator/text_moderation.rb
Overview
You use the API to scan your content as it is generated. Content Moderator then processes your content and sends the results along with relevant information either back to your systems or to the built-in review tool. You can use this information to take decisions e.g. take it down, send to human judge, etc.
When using the API, images need to have a minimum of 128 pixels and a maximum file size of 4MB. Text can be at most 1024 characters long. If the content passed to the text API or the image API exceeds the size limits, the API will return an error code that informs about the issue.
Instance Attribute Summary collapse
-
#client ⇒ ContentModeratorClient
readonly
Reference to the ContentModeratorClient.
Instance Method Summary collapse
-
#detect_language(text_content_type, text_content, custom_headers: nil) ⇒ DetectedLanguage
This operation will detect the language of given input content.
-
#detect_language_async(text_content_type, text_content, custom_headers: nil) ⇒ Concurrent::Promise
This operation will detect the language of given input content.
-
#detect_language_with_http_info(text_content_type, text_content, custom_headers: nil) ⇒ MsRestAzure::AzureOperationResponse
This operation will detect the language of given input content.
-
#initialize(client) ⇒ TextModeration
constructor
Creates and initializes a new instance of the TextModeration class.
-
#screen_text(text_content_type, text_content, language: nil, autocorrect: false, pii: false, list_id: nil, classify: false, custom_headers: nil) ⇒ Screen
Detect profanity and match against custom and shared blacklists.
-
#screen_text_async(text_content_type, text_content, language: nil, autocorrect: false, pii: false, list_id: nil, classify: false, custom_headers: nil) ⇒ Concurrent::Promise
Detect profanity and match against custom and shared blacklists.
-
#screen_text_with_http_info(text_content_type, text_content, language: nil, autocorrect: false, pii: false, list_id: nil, classify: false, custom_headers: nil) ⇒ MsRestAzure::AzureOperationResponse
Detect profanity and match against custom and shared blacklists.
Constructor Details
#initialize(client) ⇒ TextModeration
Creates and initializes a new instance of the TextModeration class.
27 28 29 |
# File 'lib/1.0/generated/azure_cognitiveservices_contentmoderator/text_moderation.rb', line 27 def initialize(client) @client = client end |
Instance Attribute Details
#client ⇒ ContentModeratorClient (readonly)
Returns reference to the ContentModeratorClient.
32 33 34 |
# File 'lib/1.0/generated/azure_cognitiveservices_contentmoderator/text_moderation.rb', line 32 def client @client end |
Instance Method Details
#detect_language(text_content_type, text_content, custom_headers: nil) ⇒ DetectedLanguage
This operation will detect the language of given input content. Returns the <a href=“www-01.sil.org/iso639-3/codes.asp”>ISO 639-3 code</a> for the predominant language comprising the submitted text. Over 110 languages supported.
‘text/plain’, ‘text/html’, ‘text/xml’, ‘text/markdown’ will be added to the HTTP request.
180 181 182 183 |
# File 'lib/1.0/generated/azure_cognitiveservices_contentmoderator/text_moderation.rb', line 180 def detect_language(text_content_type, text_content, custom_headers:nil) response = detect_language_async(text_content_type, text_content, custom_headers:custom_headers).value! response.body unless response.nil? end |
#detect_language_async(text_content_type, text_content, custom_headers: nil) ⇒ Concurrent::Promise
This operation will detect the language of given input content. Returns the <a href=“www-01.sil.org/iso639-3/codes.asp”>ISO 639-3 code</a> for the predominant language comprising the submitted text. Over 110 languages supported.
‘text/plain’, ‘text/html’, ‘text/xml’, ‘text/markdown’ to the HTTP request.
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
# File 'lib/1.0/generated/azure_cognitiveservices_contentmoderator/text_moderation.rb', line 217 def detect_language_async(text_content_type, text_content, custom_headers:nil) fail ArgumentError, '@client.endpoint is nil' if @client.endpoint.nil? fail ArgumentError, 'text_content_type is nil' if text_content_type.nil? fail ArgumentError, 'text_content is nil' if text_content.nil? request_headers = {} request_headers['Content-Type'] = 'text/plain' # Set Headers request_headers['x-ms-client-request-id'] = SecureRandom.uuid request_headers['Content-Type'] = text_content_type.to_s unless text_content_type.to_s.nil? request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil? # Serialize Request request_mapper = { client_side_validation: true, required: true, serialized_name: 'Text Content', type: { name: 'Stream' } } request_content = @client.serialize(request_mapper, text_content) path_template = 'contentmoderator/moderate/v1.0/ProcessText/DetectLanguage' request_url = @base_url || @client.base_url request_url = request_url.gsub('{Endpoint}', @client.endpoint) = { middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]], body: request_content, headers: request_headers.merge(custom_headers || {}), base_url: request_url } promise = @client.make_request_async(:post, path_template, ) promise = promise.then do |result| http_response = result.response status_code = http_response.status response_content = http_response.body unless status_code == 200 error_model = JSON.load(response_content) fail MsRest::HttpOperationError.new(result.request, http_response, error_model) end result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil? # Deserialize Response if status_code == 200 begin parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content) result_mapper = Azure::CognitiveServices::ContentModerator::V1_0::Models::DetectedLanguage.mapper() result.body = @client.deserialize(result_mapper, parsed_response) rescue Exception => e fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e., e.backtrace, result) end end result end promise.execute end |
#detect_language_with_http_info(text_content_type, text_content, custom_headers: nil) ⇒ MsRestAzure::AzureOperationResponse
This operation will detect the language of given input content. Returns the <a href=“www-01.sil.org/iso639-3/codes.asp”>ISO 639-3 code</a> for the predominant language comprising the submitted text. Over 110 languages supported.
‘text/plain’, ‘text/html’, ‘text/xml’, ‘text/markdown’ will be added to the HTTP request.
199 200 201 |
# File 'lib/1.0/generated/azure_cognitiveservices_contentmoderator/text_moderation.rb', line 199 def detect_language_with_http_info(text_content_type, text_content, custom_headers:nil) detect_language_async(text_content_type, text_content, custom_headers:custom_headers).value! end |
#screen_text(text_content_type, text_content, language: nil, autocorrect: false, pii: false, list_id: nil, classify: false, custom_headers: nil) ⇒ Screen
Detect profanity and match against custom and shared blacklists
Detects profanity in more than 100 languages and match against custom and shared blacklists.
‘text/plain’, ‘text/html’, ‘text/xml’, ‘text/markdown’ will be added to the HTTP request.
53 54 55 56 |
# File 'lib/1.0/generated/azure_cognitiveservices_contentmoderator/text_moderation.rb', line 53 def screen_text(text_content_type, text_content, language:nil, autocorrect:false, pii:false, list_id:nil, classify:false, custom_headers:nil) response = screen_text_async(text_content_type, text_content, language:language, autocorrect:autocorrect, pii:pii, list_id:list_id, classify:classify, custom_headers:custom_headers).value! response.body unless response.nil? end |
#screen_text_async(text_content_type, text_content, language: nil, autocorrect: false, pii: false, list_id: nil, classify: false, custom_headers: nil) ⇒ Concurrent::Promise
Detect profanity and match against custom and shared blacklists
Detects profanity in more than 100 languages and match against custom and shared blacklists.
‘text/plain’, ‘text/html’, ‘text/xml’, ‘text/markdown’ to the HTTP request.
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/1.0/generated/azure_cognitiveservices_contentmoderator/text_moderation.rb', line 100 def screen_text_async(text_content_type, text_content, language:nil, autocorrect:false, pii:false, list_id:nil, classify:false, custom_headers:nil) fail ArgumentError, '@client.endpoint is nil' if @client.endpoint.nil? fail ArgumentError, 'text_content_type is nil' if text_content_type.nil? fail ArgumentError, 'text_content is nil' if text_content.nil? request_headers = {} request_headers['Content-Type'] = 'text/plain' # Set Headers request_headers['x-ms-client-request-id'] = SecureRandom.uuid request_headers['Content-Type'] = text_content_type.to_s unless text_content_type.to_s.nil? request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil? # Serialize Request request_mapper = { client_side_validation: true, required: true, serialized_name: 'Text Content', type: { name: 'Stream' } } request_content = @client.serialize(request_mapper, text_content) path_template = 'contentmoderator/moderate/v1.0/ProcessText/Screen/' request_url = @base_url || @client.base_url request_url = request_url.gsub('{Endpoint}', @client.endpoint) = { middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]], query_params: {'language' => language,'autocorrect' => autocorrect,'PII' => pii,'listId' => list_id,'classify' => classify}, body: request_content, headers: request_headers.merge(custom_headers || {}), base_url: request_url } promise = @client.make_request_async(:post, path_template, ) promise = promise.then do |result| http_response = result.response status_code = http_response.status response_content = http_response.body unless status_code == 200 error_model = JSON.load(response_content) fail MsRest::HttpOperationError.new(result.request, http_response, error_model) end result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil? # Deserialize Response if status_code == 200 begin parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content) result_mapper = Azure::CognitiveServices::ContentModerator::V1_0::Models::Screen.mapper() result.body = @client.deserialize(result_mapper, parsed_response) rescue Exception => e fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e., e.backtrace, result) end end result end promise.execute end |
#screen_text_with_http_info(text_content_type, text_content, language: nil, autocorrect: false, pii: false, list_id: nil, classify: false, custom_headers: nil) ⇒ MsRestAzure::AzureOperationResponse
Detect profanity and match against custom and shared blacklists
Detects profanity in more than 100 languages and match against custom and shared blacklists.
‘text/plain’, ‘text/html’, ‘text/xml’, ‘text/markdown’ will be added to the HTTP request.
77 78 79 |
# File 'lib/1.0/generated/azure_cognitiveservices_contentmoderator/text_moderation.rb', line 77 def screen_text_with_http_info(text_content_type, text_content, language:nil, autocorrect:false, pii:false, list_id:nil, classify:false, custom_headers:nil) screen_text_async(text_content_type, text_content, language:language, autocorrect:autocorrect, pii:pii, list_id:list_id, classify:classify, custom_headers:custom_headers).value! end |