Class: AwsDetectSentiment::AwsComprehendClient

Inherits:
Object
  • Object
show all
Defined in:
lib/aws_detect_sentiment/aws_comprehend_client.rb

Constant Summary collapse

BATCH_LIMIT =
25

Instance Method Summary collapse

Constructor Details

#initializeAwsComprehendClient

Returns a new instance of AwsComprehendClient.



7
8
9
10
11
12
13
14
15
# File 'lib/aws_detect_sentiment/aws_comprehend_client.rb', line 7

def initialize
  self.s3_client =
    Aws::Comprehend::Client.new(
      stub_responses: stub_enabled?,
      region: AwsDetectSentiment.configuration.aws_region,
      access_key_id: AwsDetectSentiment.configuration.aws_access_key_id,
      secret_access_key: AwsDetectSentiment.configuration.aws_secret_access_key
    )
end

Instance Method Details

#detect_sentiment(text, options: inner_options, stub_response: {}) ⇒ Object



17
18
19
20
# File 'lib/aws_detect_sentiment/aws_comprehend_client.rb', line 17

def detect_sentiment(text, options: inner_options, stub_response: {})
  s3_client.stub_responses(:detect_sentiment, stub_response) if stub_enabled?
  sentiment(s3_client.detect_sentiment(text: text, **options))
end

#detect_sentiments(texts, batch_limit: BATCH_LIMIT, options: inner_options, stub_responses: [{}]) ⇒ Object



22
23
24
25
26
27
# File 'lib/aws_detect_sentiment/aws_comprehend_client.rb', line 22

def detect_sentiments(texts, batch_limit: BATCH_LIMIT, options: inner_options, stub_responses: [{}])
  texts.each_slice(batch_limit).map.with_index do |texts_slice, index|
    s3_client.stub_responses(:batch_detect_sentiment, stub_responses[index]) if stub_enabled?
    s3_client.batch_detect_sentiment(text_list: texts_slice, **options).result_list
  end.flatten.map(&method(:sentiment))
end