Class: Azure::CognitiveServices::TextAnalytics::V2_1::TextAnalyticsClient

Inherits:
MsRestAzure::AzureServiceClient
  • Object
show all
Includes:
MsRestAzure, MsRestAzure::Serialization
Defined in:
lib/v2.1/generated/azure_cognitiveservices_textanalytics/text_analytics_client.rb

Overview

A service client - single point of access to the REST API.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(credentials = nil, options = nil) ⇒ TextAnalyticsClient

Creates initializes a new instance of the TextAnalyticsClient class.

Parameters:

  • credentials (MsRest::ServiceClientCredentials) (defaults to: nil)

    credentials to authorize HTTP requests made by the service client.

  • options (Array) (defaults to: nil)

    filters to be applied to the HTTP requests.



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/v2.1/generated/azure_cognitiveservices_textanalytics/text_analytics_client.rb', line 45

def initialize(credentials = nil, options = nil)
  super(credentials, options)
  @base_url = '{Endpoint}/text/analytics/v2.1'

  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_languageString

Returns The preferred language for the response.

Returns:

  • (String)

    The preferred language for the response.



29
30
31
# File 'lib/v2.1/generated/azure_cognitiveservices_textanalytics/text_analytics_client.rb', line 29

def accept_language
  @accept_language
end

#base_urlString (readonly)

Returns the base URI of the service.

Returns:

  • (String)

    the base URI of the service.



15
16
17
# File 'lib/v2.1/generated/azure_cognitiveservices_textanalytics/text_analytics_client.rb', line 15

def base_url
  @base_url
end

#credentialsObject

subscription.

Returns:

  • Subscription credentials which uniquely identify client



26
27
28
# File 'lib/v2.1/generated/azure_cognitiveservices_textanalytics/text_analytics_client.rb', line 26

def credentials
  @credentials
end

#credentials1Object (readonly)

Returns Credentials needed for the client to connect to Azure.

Returns:

  • Credentials needed for the client to connect to Azure.



18
19
20
# File 'lib/v2.1/generated/azure_cognitiveservices_textanalytics/text_analytics_client.rb', line 18

def credentials1
  @credentials1
end

#endpointString

hostname, for example: westus.api.cognitive.microsoft.com).

Returns:

  • (String)

    Supported Cognitive Services endpoints (protocol and



22
23
24
# File 'lib/v2.1/generated/azure_cognitiveservices_textanalytics/text_analytics_client.rb', line 22

def endpoint
  @endpoint
end

#generate_client_request_idBoolean

generated. When set to true a unique x-ms-client-request-id value is generated and included in each request. Default is true.

Returns:

  • (Boolean)

    Whether a unique x-ms-client-request-id should be



38
39
40
# File 'lib/v2.1/generated/azure_cognitiveservices_textanalytics/text_analytics_client.rb', line 38

def generate_client_request_id
  @generate_client_request_id
end

#long_running_operation_retry_timeoutInteger

Operations. Default value is 30.

Returns:

  • (Integer)

    The retry timeout in seconds for Long Running



33
34
35
# File 'lib/v2.1/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(show_stats: nil, language_batch_input: nil, 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.

input and document level statistics. analyze. will be added to the HTTP request.

Parameters:

  • show_stats (Boolean) (defaults to: nil)

    (optional) if set to true, response will contain

  • language_batch_input (LanguageBatchInput) (defaults to: nil)

    Collection of documents to

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (LanguageBatchResult)

    operation results.



131
132
133
134
# File 'lib/v2.1/generated/azure_cognitiveservices_textanalytics/text_analytics_client.rb', line 131

def detect_language(show_stats:nil, language_batch_input:nil, custom_headers:nil)
  response = detect_language_async(show_stats:show_stats, language_batch_input:language_batch_input, custom_headers:custom_headers).value!
  response.body unless response.nil?
end

#detect_language_async(show_stats: nil, language_batch_input: nil, 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.

input and document level statistics. analyze. to the HTTP request.

Parameters:

  • show_stats (Boolean) (defaults to: nil)

    (optional) if set to true, response will contain

  • language_batch_input (LanguageBatchInput) (defaults to: nil)

    Collection of documents to

  • A (Hash{String => String})

    hash of custom headers that will be added

Returns:

  • (Concurrent::Promise)

    Promise object which holds the HTTP response.



170
171
172
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
# File 'lib/v2.1/generated/azure_cognitiveservices_textanalytics/text_analytics_client.rb', line 170

def detect_language_async(show_stats:nil, language_batch_input:nil, custom_headers:nil)
  fail ArgumentError, 'endpoint is nil' if endpoint.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_1::Models::LanguageBatchInput.mapper()
  request_content = self.serialize(request_mapper,  language_batch_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)

  options = {
      middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
      query_params: {'showStats' => show_stats},
      body: request_content,
      headers: request_headers.merge(custom_headers || {}),
      base_url: request_url
  }
  promise = self.make_request_async(:post, path_template, options)

  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_1::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.message, e.backtrace, result)
      end
    end

    result
  end

  promise.execute
end

#detect_language_with_http_info(show_stats: nil, language_batch_input: nil, 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.

input and document level statistics. analyze. will be added to the HTTP request.

Parameters:

  • show_stats (Boolean) (defaults to: nil)

    (optional) if set to true, response will contain

  • language_batch_input (LanguageBatchInput) (defaults to: nil)

    Collection of documents to

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (MsRestAzure::AzureOperationResponse)

    HTTP response information.



151
152
153
# File 'lib/v2.1/generated/azure_cognitiveservices_textanalytics/text_analytics_client.rb', line 151

def detect_language_with_http_info(show_stats:nil, language_batch_input:nil, custom_headers:nil)
  detect_language_async(show_stats:show_stats, language_batch_input:language_batch_input, custom_headers:custom_headers).value!
end

#entities(show_stats: nil, multi_language_batch_input: nil, 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.

input and document level statistics. documents to analyze. will be added to the HTTP request.

Parameters:

  • show_stats (Boolean) (defaults to: nil)

    (optional) if set to true, response will contain

  • multi_language_batch_input (MultiLanguageBatchInput) (defaults to: nil)

    Collection of

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (EntitiesBatchResult)

    operation results.



245
246
247
248
# File 'lib/v2.1/generated/azure_cognitiveservices_textanalytics/text_analytics_client.rb', line 245

def entities(show_stats:nil, multi_language_batch_input:nil, custom_headers:nil)
  response = entities_async(show_stats:show_stats, multi_language_batch_input:multi_language_batch_input, custom_headers:custom_headers).value!
  response.body unless response.nil?
end

#entities_async(show_stats: nil, multi_language_batch_input: nil, 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.

input and document level statistics. documents to analyze. to the HTTP request.

Parameters:

  • show_stats (Boolean) (defaults to: nil)

    (optional) if set to true, response will contain

  • multi_language_batch_input (MultiLanguageBatchInput) (defaults to: nil)

    Collection of

  • A (Hash{String => String})

    hash of custom headers that will be added

Returns:

  • (Concurrent::Promise)

    Promise object which holds the HTTP response.



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
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
# File 'lib/v2.1/generated/azure_cognitiveservices_textanalytics/text_analytics_client.rb', line 290

def entities_async(show_stats:nil, multi_language_batch_input:nil, custom_headers:nil)
  fail ArgumentError, 'endpoint is nil' if endpoint.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_1::Models::MultiLanguageBatchInput.mapper()
  request_content = self.serialize(request_mapper,  multi_language_batch_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)

  options = {
      middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
      query_params: {'showStats' => show_stats},
      body: request_content,
      headers: request_headers.merge(custom_headers || {}),
      base_url: request_url
  }
  promise = self.make_request_async(:post, path_template, options)

  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_1::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.message, e.backtrace, result)
      end
    end

    result
  end

  promise.execute
end

#entities_with_http_info(show_stats: nil, multi_language_batch_input: nil, 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.

input and document level statistics. documents to analyze. will be added to the HTTP request.

Parameters:

  • show_stats (Boolean) (defaults to: nil)

    (optional) if set to true, response will contain

  • multi_language_batch_input (MultiLanguageBatchInput) (defaults to: nil)

    Collection of

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (MsRestAzure::AzureOperationResponse)

    HTTP response information.



268
269
270
# File 'lib/v2.1/generated/azure_cognitiveservices_textanalytics/text_analytics_client.rb', line 268

def entities_with_http_info(show_stats:nil, multi_language_batch_input:nil, custom_headers:nil)
  entities_async(show_stats:show_stats, multi_language_batch_input:multi_language_batch_input, custom_headers:custom_headers).value!
end

#key_phrases(show_stats: nil, multi_language_batch_input: nil, 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.

input and document level statistics. documents to analyze. Documents can now contain a language field to indicate the text language will be added to the HTTP request.

Parameters:

  • show_stats (Boolean) (defaults to: nil)

    (optional) if set to true, response will contain

  • multi_language_batch_input (MultiLanguageBatchInput) (defaults to: nil)

    Collection of

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (KeyPhraseBatchResult)

    operation results.



366
367
368
369
# File 'lib/v2.1/generated/azure_cognitiveservices_textanalytics/text_analytics_client.rb', line 366

def key_phrases(show_stats:nil, multi_language_batch_input:nil, custom_headers:nil)
  response = key_phrases_async(show_stats:show_stats, multi_language_batch_input:multi_language_batch_input, custom_headers:custom_headers).value!
  response.body unless response.nil?
end

#key_phrases_async(show_stats: nil, multi_language_batch_input: nil, 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.

input and document level statistics. documents to analyze. Documents can now contain a language field to indicate the text language to the HTTP request.

Parameters:

  • show_stats (Boolean) (defaults to: nil)

    (optional) if set to true, response will contain

  • multi_language_batch_input (MultiLanguageBatchInput) (defaults to: nil)

    Collection of

  • A (Hash{String => String})

    hash of custom headers that will be added

Returns:

  • (Concurrent::Promise)

    Promise object which holds the HTTP response.



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
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
# File 'lib/v2.1/generated/azure_cognitiveservices_textanalytics/text_analytics_client.rb', line 413

def key_phrases_async(show_stats:nil, multi_language_batch_input:nil, custom_headers:nil)
  fail ArgumentError, 'endpoint is nil' if endpoint.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_1::Models::MultiLanguageBatchInput.mapper()
  request_content = self.serialize(request_mapper,  multi_language_batch_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)

  options = {
      middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
      query_params: {'showStats' => show_stats},
      body: request_content,
      headers: request_headers.merge(custom_headers || {}),
      base_url: request_url
  }
  promise = self.make_request_async(:post, path_template, options)

  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_1::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.message, e.backtrace, result)
      end
    end

    result
  end

  promise.execute
end

#key_phrases_with_http_info(show_stats: nil, multi_language_batch_input: nil, 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.

input and document level statistics. documents to analyze. Documents can now contain a language field to indicate the text language will be added to the HTTP request.

Parameters:

  • show_stats (Boolean) (defaults to: nil)

    (optional) if set to true, response will contain

  • multi_language_batch_input (MultiLanguageBatchInput) (defaults to: nil)

    Collection of

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (MsRestAzure::AzureOperationResponse)

    HTTP response information.



390
391
392
# File 'lib/v2.1/generated/azure_cognitiveservices_textanalytics/text_analytics_client.rb', line 390

def key_phrases_with_http_info(show_stats:nil, multi_language_batch_input:nil, custom_headers:nil)
  key_phrases_async(show_stats:show_stats, multi_language_batch_input:multi_language_batch_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"
options = {
  body: request_content,
  query_params: {'api-version' => '2016-02-01'}
}
result = @client.make_request(:put, path, options)

Parameters:

  • method (Symbol)

    with any of the following values :get, :put, :post, :patch, :delete.

  • path (String)

    the path, relative to #base_url.

  • options (Hash{String=>String}) (defaults to: {})

    specifying any request options like :body.

Returns:

  • (Hash{String=>String})

    containing the body of the response.



74
75
76
77
# File 'lib/v2.1/generated/azure_cognitiveservices_textanalytics/text_analytics_client.rb', line 74

def make_request(method, path, options = {})
  result = make_request_with_http_info(method, path, options)
  result.body unless result.nil?
end

#make_request_async(method, path, options = {}) ⇒ Concurrent::Promise

Makes a request asynchronously.

Parameters:

  • method (Symbol)

    with any of the following values :get, :put, :post, :patch, :delete.

  • path (String)

    the path, relative to #base_url.

  • options (Hash{String=>String}) (defaults to: {})

    specifying any request options like :body.

Returns:

  • (Concurrent::Promise)

    Promise object which holds the HTTP response.



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/v2.1/generated/azure_cognitiveservices_textanalytics/text_analytics_client.rb', line 99

def make_request_async(method, path, options = {})
  fail ArgumentError, 'method is nil' if method.nil?
  fail ArgumentError, 'path is nil' if path.nil?

  request_url = options[:base_url] || @base_url
  if(!options[:headers].nil? && !options[:headers]['Content-Type'].nil?)
    @request_headers['Content-Type'] = options[:headers]['Content-Type']
  end

  request_headers = @request_headers
  request_headers.merge!({'accept-language' => @accept_language}) unless @accept_language.nil?
  options.merge!({headers: request_headers.merge(options[:headers] || {})})
  options.merge!({credentials: @credentials}) unless @credentials.nil?

  super(request_url, method, path, options)
end

#make_request_with_http_info(method, path, options = {}) ⇒ MsRestAzure::AzureOperationResponse

Makes a request and returns the operation response.

Parameters:

  • method (Symbol)

    with any of the following values :get, :put, :post, :patch, :delete.

  • path (String)

    the path, relative to #base_url.

  • options (Hash{String=>String}) (defaults to: {})

    specifying any request options like :body.

Returns:

  • (MsRestAzure::AzureOperationResponse)

    Operation response containing the request, response and status.



86
87
88
89
90
# File 'lib/v2.1/generated/azure_cognitiveservices_textanalytics/text_analytics_client.rb', line 86

def make_request_with_http_info(method, path, options = {})
  result = make_request_async(method, path, options).value!
  result.body = result.response.body.to_s.empty? ? nil : JSON.load(result.response.body)
  result
end

#sentiment(show_stats: nil, multi_language_batch_input: nil, custom_headers: nil) ⇒ Object

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.

input and document level statistics. documents to analyze. will be added to the HTTP request.

Parameters:

  • show_stats (Boolean) (defaults to: nil)

    (optional) if set to true, response will contain

  • multi_language_batch_input (MultiLanguageBatchInput) (defaults to: nil)

    Collection of

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (Object)

    operation results.



489
490
491
492
# File 'lib/v2.1/generated/azure_cognitiveservices_textanalytics/text_analytics_client.rb', line 489

def sentiment(show_stats:nil, multi_language_batch_input:nil, custom_headers:nil)
  response = sentiment_async(show_stats:show_stats, multi_language_batch_input:multi_language_batch_input, custom_headers:custom_headers).value!
  response.body unless response.nil?
end

#sentiment_async(show_stats: nil, multi_language_batch_input: nil, 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.

input and document level statistics. documents to analyze. to the HTTP request.

Parameters:

  • show_stats (Boolean) (defaults to: nil)

    (optional) if set to true, response will contain

  • multi_language_batch_input (MultiLanguageBatchInput) (defaults to: nil)

    Collection of

  • A (Hash{String => String})

    hash of custom headers that will be added

Returns:

  • (Concurrent::Promise)

    Promise object which holds the HTTP response.



536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
# File 'lib/v2.1/generated/azure_cognitiveservices_textanalytics/text_analytics_client.rb', line 536

def sentiment_async(show_stats:nil, multi_language_batch_input:nil, custom_headers:nil)
  fail ArgumentError, 'endpoint is nil' if endpoint.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_1::Models::MultiLanguageBatchInput.mapper()
  request_content = self.serialize(request_mapper,  multi_language_batch_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)

  options = {
      middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
      query_params: {'showStats' => show_stats},
      body: request_content,
      headers: request_headers.merge(custom_headers || {}),
      base_url: request_url
  }
  promise = self.make_request_async(:post, path_template, options)

  promise = promise.then do |result|
    http_response = result.response
    status_code = http_response.status
    response_content = http_response.body
    unless status_code == 200 || status_code == 500
      error_model = JSON.load(response_content)
      fail MsRestAzure::AzureOperationError.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_1::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.message, e.backtrace, result)
      end
    end
    # Deserialize Response
    if status_code == 500
      begin
        parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
        result_mapper = Azure::CognitiveServices::TextAnalytics::V2_1::Models::ErrorResponse.mapper()
        result.body = self.deserialize(result_mapper, parsed_response)
      rescue Exception => e
        fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
      end
    end

    result
  end

  promise.execute
end

#sentiment_with_http_info(show_stats: nil, multi_language_batch_input: nil, 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.

input and document level statistics. documents to analyze. will be added to the HTTP request.

Parameters:

  • show_stats (Boolean) (defaults to: nil)

    (optional) if set to true, response will contain

  • multi_language_batch_input (MultiLanguageBatchInput) (defaults to: nil)

    Collection of

  • custom_headers (Hash{String => String}) (defaults to: nil)

    A hash of custom headers that

Returns:

  • (MsRestAzure::AzureOperationResponse)

    HTTP response information.



513
514
515
# File 'lib/v2.1/generated/azure_cognitiveservices_textanalytics/text_analytics_client.rb', line 513

def sentiment_with_http_info(show_stats:nil, multi_language_batch_input:nil, custom_headers:nil)
  sentiment_async(show_stats:show_stats, multi_language_batch_input:multi_language_batch_input, custom_headers:custom_headers).value!
end