class AwsDetectSentiment::AwsComprehendClient
Constants
- BATCH_LIMIT
Attributes
s3_client[RW]
Public Class Methods
new()
click to toggle source
# 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
Public Instance Methods
detect_sentiment(text, options: inner_options, stub_response: {})
click to toggle source
# 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: [{}])
click to toggle source
# 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
Private Instance Methods
inner_options()
click to toggle source
# File lib/aws_detect_sentiment/aws_comprehend_client.rb, line 37 def inner_options { language_code: "en" } end
sentiment(result)
click to toggle source
# File lib/aws_detect_sentiment/aws_comprehend_client.rb, line 33 def sentiment(result) result.sentiment.downcase end
stub_enabled?()
click to toggle source
# File lib/aws_detect_sentiment/aws_comprehend_client.rb, line 43 def stub_enabled? AwsDetectSentiment.configuration.stub_client_requests end