Class: Azure::CognitiveServices::TextAnalytics::V2_0::TextAnalyticsClient
- Inherits:
-
MsRestAzure::AzureServiceClient
- Object
- MsRestAzure::AzureServiceClient
- Azure::CognitiveServices::TextAnalytics::V2_0::TextAnalyticsClient
- Includes:
- MsRestAzure, MsRestAzure::Serialization
- Defined in:
- lib/v2.0/generated/azure_cognitiveservices_textanalytics/text_analytics_client.rb
Overview
A service client - single point of access to the REST API.
Instance Attribute Summary collapse
-
#accept_language ⇒ String
The preferred language for the response.
-
#base_url ⇒ String
readonly
The base URI of the service.
-
#credentials ⇒ Object
subscription.
-
#credentials1 ⇒ Object
readonly
Credentials needed for the client to connect to Azure.
-
#endpoint ⇒ String
hostname, for example: westus.api.cognitive.microsoft.com).
-
#generate_client_request_id ⇒ Boolean
generated.
-
#long_running_operation_retry_timeout ⇒ Integer
Operations.
Instance Method Summary collapse
-
#detect_language(input, custom_headers: nil) ⇒ LanguageBatchResult
The API returns the detected language and a numeric score between 0 and 1.
-
#detect_language_async(input, custom_headers: nil) ⇒ Concurrent::Promise
The API returns the detected language and a numeric score between 0 and 1.
-
#detect_language_with_http_info(input, custom_headers: nil) ⇒ MsRestAzure::AzureOperationResponse
The API returns the detected language and a numeric score between 0 and 1.
-
#entities(input, custom_headers: nil) ⇒ EntitiesBatchResult
The API returns a list of recognized entities in a given document.
-
#entities_async(input, custom_headers: nil) ⇒ Concurrent::Promise
The API returns a list of recognized entities in a given document.
-
#entities_with_http_info(input, custom_headers: nil) ⇒ MsRestAzure::AzureOperationResponse
The API returns a list of recognized entities in a given document.
-
#initialize(credentials = nil, options = nil) ⇒ TextAnalyticsClient
constructor
Creates initializes a new instance of the TextAnalyticsClient class.
-
#key_phrases(input, custom_headers: nil) ⇒ KeyPhraseBatchResult
The API returns a list of strings denoting the key talking points in the input text.
-
#key_phrases_async(input, custom_headers: nil) ⇒ Concurrent::Promise
The API returns a list of strings denoting the key talking points in the input text.
-
#key_phrases_with_http_info(input, custom_headers: nil) ⇒ MsRestAzure::AzureOperationResponse
The API returns a list of strings denoting the key talking points in the input text.
-
#make_request(method, path, options = {}) ⇒ Hash{String=>String}
Makes a request and returns the body of the response.
-
#make_request_async(method, path, options = {}) ⇒ Concurrent::Promise
Makes a request asynchronously.
-
#make_request_with_http_info(method, path, options = {}) ⇒ MsRestAzure::AzureOperationResponse
Makes a request and returns the operation response.
-
#sentiment(input, custom_headers: nil) ⇒ SentimentBatchResult
The API returns a numeric score between 0 and 1.
-
#sentiment_async(input, custom_headers: nil) ⇒ Concurrent::Promise
The API returns a numeric score between 0 and 1.
-
#sentiment_with_http_info(input, custom_headers: nil) ⇒ MsRestAzure::AzureOperationResponse
The API returns a numeric score between 0 and 1.
Constructor Details
#initialize(credentials = nil, options = nil) ⇒ TextAnalyticsClient
Creates initializes a new instance of the TextAnalyticsClient class.
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/v2.0/generated/azure_cognitiveservices_textanalytics/text_analytics_client.rb', line 45 def initialize(credentials = nil, = nil) super(credentials, ) @base_url = '{Endpoint}/text/analytics/v2.0' fail ArgumentError, 'invalid type of credentials input parameter' unless credentials.is_a?(MsRest::ServiceClientCredentials) unless credentials.nil? @credentials = credentials @accept_language = 'en-US' @long_running_operation_retry_timeout = 30 @generate_client_request_id = true add_telemetry end |
Instance Attribute Details
#accept_language ⇒ String
Returns The preferred language for the response.
29 30 31 |
# File 'lib/v2.0/generated/azure_cognitiveservices_textanalytics/text_analytics_client.rb', line 29 def accept_language @accept_language end |
#base_url ⇒ String (readonly)
Returns the base URI of the service.
15 16 17 |
# File 'lib/v2.0/generated/azure_cognitiveservices_textanalytics/text_analytics_client.rb', line 15 def base_url @base_url end |
#credentials ⇒ Object
subscription.
26 27 28 |
# File 'lib/v2.0/generated/azure_cognitiveservices_textanalytics/text_analytics_client.rb', line 26 def credentials @credentials end |
#credentials1 ⇒ Object (readonly)
Returns Credentials needed for the client to connect to Azure.
18 19 20 |
# File 'lib/v2.0/generated/azure_cognitiveservices_textanalytics/text_analytics_client.rb', line 18 def credentials1 @credentials1 end |
#endpoint ⇒ String
hostname, for example: westus.api.cognitive.microsoft.com).
22 23 24 |
# File 'lib/v2.0/generated/azure_cognitiveservices_textanalytics/text_analytics_client.rb', line 22 def endpoint @endpoint end |
#generate_client_request_id ⇒ Boolean
generated. When set to true a unique x-ms-client-request-id value is generated and included in each request. Default is true.
38 39 40 |
# File 'lib/v2.0/generated/azure_cognitiveservices_textanalytics/text_analytics_client.rb', line 38 def generate_client_request_id @generate_client_request_id end |
#long_running_operation_retry_timeout ⇒ Integer
Operations. Default value is 30.
33 34 35 |
# File 'lib/v2.0/generated/azure_cognitiveservices_textanalytics/text_analytics_client.rb', line 33 def long_running_operation_retry_timeout @long_running_operation_retry_timeout end |
Instance Method Details
#detect_language(input, custom_headers: nil) ⇒ LanguageBatchResult
The API returns the detected language and a numeric score between 0 and 1.
Scores close to 1 indicate 100% certainty that the identified language is true. A total of 120 languages are supported.
will be added to the HTTP request.
242 243 244 245 |
# File 'lib/v2.0/generated/azure_cognitiveservices_textanalytics/text_analytics_client.rb', line 242 def detect_language(input, custom_headers:nil) response = detect_language_async(input, custom_headers:custom_headers).value! response.body unless response.nil? end |
#detect_language_async(input, custom_headers: nil) ⇒ Concurrent::Promise
The API returns the detected language and a numeric score between 0 and 1.
Scores close to 1 indicate 100% certainty that the identified language is true. A total of 120 languages are supported.
to the HTTP request.
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 |
# File 'lib/v2.0/generated/azure_cognitiveservices_textanalytics/text_analytics_client.rb', line 275 def detect_language_async(input, custom_headers:nil) fail ArgumentError, 'endpoint is nil' if endpoint.nil? fail ArgumentError, 'input is nil' if input.nil? request_headers = {} request_headers['Content-Type'] = 'application/json; charset=utf-8' # Set Headers request_headers['x-ms-client-request-id'] = SecureRandom.uuid request_headers['accept-language'] = accept_language unless accept_language.nil? # Serialize Request request_mapper = Azure::CognitiveServices::TextAnalytics::V2_0::Models::BatchInput.mapper() request_content = self.serialize(request_mapper, input) request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil path_template = 'languages' request_url = @base_url || self.base_url request_url = request_url.gsub('{Endpoint}', 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 = self.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::TextAnalytics::V2_0::Models::LanguageBatchResult.mapper() result.body = self.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(input, custom_headers: nil) ⇒ MsRestAzure::AzureOperationResponse
The API returns the detected language and a numeric score between 0 and 1.
Scores close to 1 indicate 100% certainty that the identified language is true. A total of 120 languages are supported.
will be added to the HTTP request.
259 260 261 |
# File 'lib/v2.0/generated/azure_cognitiveservices_textanalytics/text_analytics_client.rb', line 259 def detect_language_with_http_info(input, custom_headers:nil) detect_language_async(input, custom_headers:custom_headers).value! end |
#entities(input, custom_headers: nil) ⇒ EntitiesBatchResult
The API returns a list of recognized entities in a given document.
To get even more information on each recognized entity we recommend using the Bing Entity Search API by querying for the recognized entities names. See the <a href=“docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/text-analytics-supported-languages”>Supported languages in Text Analytics API</a> for the list of enabled languages.
will be added to the HTTP request.
461 462 463 464 |
# File 'lib/v2.0/generated/azure_cognitiveservices_textanalytics/text_analytics_client.rb', line 461 def entities(input, custom_headers:nil) response = entities_async(input, custom_headers:custom_headers).value! response.body unless response.nil? end |
#entities_async(input, custom_headers: nil) ⇒ Concurrent::Promise
The API returns a list of recognized entities in a given document.
To get even more information on each recognized entity we recommend using the Bing Entity Search API by querying for the recognized entities names. See the <a href=“docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/text-analytics-supported-languages”>Supported languages in Text Analytics API</a> for the list of enabled languages.
to the HTTP request.
500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 |
# File 'lib/v2.0/generated/azure_cognitiveservices_textanalytics/text_analytics_client.rb', line 500 def entities_async(input, custom_headers:nil) fail ArgumentError, 'endpoint is nil' if endpoint.nil? fail ArgumentError, 'input is nil' if input.nil? request_headers = {} request_headers['Content-Type'] = 'application/json; charset=utf-8' # Set Headers request_headers['x-ms-client-request-id'] = SecureRandom.uuid request_headers['accept-language'] = accept_language unless accept_language.nil? # Serialize Request request_mapper = Azure::CognitiveServices::TextAnalytics::V2_0::Models::MultiLanguageBatchInput.mapper() request_content = self.serialize(request_mapper, input) request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil path_template = 'entities' request_url = @base_url || self.base_url request_url = request_url.gsub('{Endpoint}', 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 = self.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::TextAnalytics::V2_0::Models::EntitiesBatchResult.mapper() result.body = self.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 |
#entities_with_http_info(input, custom_headers: nil) ⇒ MsRestAzure::AzureOperationResponse
The API returns a list of recognized entities in a given document.
To get even more information on each recognized entity we recommend using the Bing Entity Search API by querying for the recognized entities names. See the <a href=“docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/text-analytics-supported-languages”>Supported languages in Text Analytics API</a> for the list of enabled languages.
will be added to the HTTP request.
481 482 483 |
# File 'lib/v2.0/generated/azure_cognitiveservices_textanalytics/text_analytics_client.rb', line 481 def entities_with_http_info(input, custom_headers:nil) entities_async(input, custom_headers:custom_headers).value! end |
#key_phrases(input, custom_headers: nil) ⇒ KeyPhraseBatchResult
The API returns a list of strings denoting the key talking points in the input text.
See the <a href=“docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/overview#supported-languages”>Text Analytics Documentation</a> for details about the languages that are supported by key phrase extraction.
Documents can now contain a language field to indicate the text language will be added to the HTTP request.
132 133 134 135 |
# File 'lib/v2.0/generated/azure_cognitiveservices_textanalytics/text_analytics_client.rb', line 132 def key_phrases(input, custom_headers:nil) response = key_phrases_async(input, custom_headers:custom_headers).value! response.body unless response.nil? end |
#key_phrases_async(input, custom_headers: nil) ⇒ Concurrent::Promise
The API returns a list of strings denoting the key talking points in the input text.
See the <a href=“docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/overview#supported-languages”>Text Analytics Documentation</a> for details about the languages that are supported by key phrase extraction.
Documents can now contain a language field to indicate the text language to the HTTP request.
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/v2.0/generated/azure_cognitiveservices_textanalytics/text_analytics_client.rb', line 173 def key_phrases_async(input, custom_headers:nil) fail ArgumentError, 'endpoint is nil' if endpoint.nil? fail ArgumentError, 'input is nil' if input.nil? request_headers = {} request_headers['Content-Type'] = 'application/json; charset=utf-8' # Set Headers request_headers['x-ms-client-request-id'] = SecureRandom.uuid request_headers['accept-language'] = accept_language unless accept_language.nil? # Serialize Request request_mapper = Azure::CognitiveServices::TextAnalytics::V2_0::Models::MultiLanguageBatchInput.mapper() request_content = self.serialize(request_mapper, input) request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil path_template = 'keyPhrases' request_url = @base_url || self.base_url request_url = request_url.gsub('{Endpoint}', 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 = self.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::TextAnalytics::V2_0::Models::KeyPhraseBatchResult.mapper() result.body = self.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 |
#key_phrases_with_http_info(input, custom_headers: nil) ⇒ MsRestAzure::AzureOperationResponse
The API returns a list of strings denoting the key talking points in the input text.
See the <a href=“docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/overview#supported-languages”>Text Analytics Documentation</a> for details about the languages that are supported by key phrase extraction.
Documents can now contain a language field to indicate the text language will be added to the HTTP request.
153 154 155 |
# File 'lib/v2.0/generated/azure_cognitiveservices_textanalytics/text_analytics_client.rb', line 153 def key_phrases_with_http_info(input, custom_headers:nil) key_phrases_async(input, custom_headers:custom_headers).value! end |
#make_request(method, path, options = {}) ⇒ Hash{String=>String}
Makes a request and returns the body of the response. Example:
request_content = "{'location':'westus','tags':{'tag1':'val1','tag2':'val2'}}"
path = "/path"
= {
body: request_content,
query_params: {'api-version' => '2016-02-01'}
}
result = @client.make_request(:put, path, )
74 75 76 77 |
# File 'lib/v2.0/generated/azure_cognitiveservices_textanalytics/text_analytics_client.rb', line 74 def make_request(method, path, = {}) result = make_request_with_http_info(method, path, ) result.body unless result.nil? end |
#make_request_async(method, path, options = {}) ⇒ Concurrent::Promise
Makes a request asynchronously.
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/v2.0/generated/azure_cognitiveservices_textanalytics/text_analytics_client.rb', line 99 def make_request_async(method, path, = {}) fail ArgumentError, 'method is nil' if method.nil? fail ArgumentError, 'path is nil' if path.nil? request_url = [:base_url] || @base_url if(![:headers].nil? && ![:headers]['Content-Type'].nil?) @request_headers['Content-Type'] = [:headers]['Content-Type'] end request_headers = @request_headers request_headers.merge!({'accept-language' => @accept_language}) unless @accept_language.nil? .merge!({headers: request_headers.merge([:headers] || {})}) .merge!({credentials: @credentials}) unless @credentials.nil? super(request_url, method, path, ) end |
#make_request_with_http_info(method, path, options = {}) ⇒ MsRestAzure::AzureOperationResponse
Makes a request and returns the operation response.
86 87 88 89 90 |
# File 'lib/v2.0/generated/azure_cognitiveservices_textanalytics/text_analytics_client.rb', line 86 def make_request_with_http_info(method, path, = {}) result = make_request_async(method, path, ).value! result.body = result.response.body.to_s.empty? ? nil : JSON.load(result.response.body) result end |
#sentiment(input, custom_headers: nil) ⇒ SentimentBatchResult
The API returns a numeric score between 0 and 1.
Scores close to 1 indicate positive sentiment, while scores close to 0 indicate negative sentiment. A score of 0.5 indicates the lack of sentiment (e.g. a factoid statement). See the <a href=“docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/overview#supported-languages”>Text Analytics Documentation</a> for details about the languages that are supported by sentiment analysis.
will be added to the HTTP request.
348 349 350 351 |
# File 'lib/v2.0/generated/azure_cognitiveservices_textanalytics/text_analytics_client.rb', line 348 def sentiment(input, custom_headers:nil) response = sentiment_async(input, custom_headers:custom_headers).value! response.body unless response.nil? end |
#sentiment_async(input, custom_headers: nil) ⇒ Concurrent::Promise
The API returns a numeric score between 0 and 1.
Scores close to 1 indicate positive sentiment, while scores close to 0 indicate negative sentiment. A score of 0.5 indicates the lack of sentiment (e.g. a factoid statement). See the <a href=“docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/overview#supported-languages”>Text Analytics Documentation</a> for details about the languages that are supported by sentiment analysis.
to the HTTP request.
389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 |
# File 'lib/v2.0/generated/azure_cognitiveservices_textanalytics/text_analytics_client.rb', line 389 def sentiment_async(input, custom_headers:nil) fail ArgumentError, 'endpoint is nil' if endpoint.nil? fail ArgumentError, 'input is nil' if input.nil? request_headers = {} request_headers['Content-Type'] = 'application/json; charset=utf-8' # Set Headers request_headers['x-ms-client-request-id'] = SecureRandom.uuid request_headers['accept-language'] = accept_language unless accept_language.nil? # Serialize Request request_mapper = Azure::CognitiveServices::TextAnalytics::V2_0::Models::MultiLanguageBatchInput.mapper() request_content = self.serialize(request_mapper, input) request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil path_template = 'sentiment' request_url = @base_url || self.base_url request_url = request_url.gsub('{Endpoint}', 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 = self.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::TextAnalytics::V2_0::Models::SentimentBatchResult.mapper() result.body = self.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 |
#sentiment_with_http_info(input, custom_headers: nil) ⇒ MsRestAzure::AzureOperationResponse
The API returns a numeric score between 0 and 1.
Scores close to 1 indicate positive sentiment, while scores close to 0 indicate negative sentiment. A score of 0.5 indicates the lack of sentiment (e.g. a factoid statement). See the <a href=“docs.microsoft.com/en-us/azure/cognitive-services/text-analytics/overview#supported-languages”>Text Analytics Documentation</a> for details about the languages that are supported by sentiment analysis.
will be added to the HTTP request.
369 370 371 |
# File 'lib/v2.0/generated/azure_cognitiveservices_textanalytics/text_analytics_client.rb', line 369 def sentiment_with_http_info(input, custom_headers:nil) sentiment_async(input, custom_headers:custom_headers).value! end |