Class: SentimentInsights::Clients::Sentiment::SentimentalClient
- Inherits:
-
Object
- Object
- SentimentInsights::Clients::Sentiment::SentimentalClient
- Defined in:
- lib/sentiment_insights/clients/sentiment/sentimental_client.rb
Overview
Client that uses the Sentimental gem for local sentiment analysis.
Instance Method Summary collapse
-
#analyze_entries(entries, question: nil, prompt: nil, batch_size: nil) ⇒ Array<Hash>
Analyzes each entry’s answer text and returns an array of sentiment results.
-
#initialize ⇒ SentimentalClient
constructor
A new instance of SentimentalClient.
Constructor Details
#initialize ⇒ SentimentalClient
Returns a new instance of SentimentalClient.
8 9 10 11 |
# File 'lib/sentiment_insights/clients/sentiment/sentimental_client.rb', line 8 def initialize @analyzer = Sentimental.new @analyzer.load_defaults # load built-in positive/negative word scores end |
Instance Method Details
#analyze_entries(entries, question: nil, prompt: nil, batch_size: nil) ⇒ Array<Hash>
Analyzes each entry’s answer text and returns an array of sentiment results.
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/sentiment_insights/clients/sentiment/sentimental_client.rb', line 17 def analyze_entries(entries, question: nil, prompt: nil, batch_size: nil) puts "Inside sentimental" entries.map do |entry| text = entry[:answer].to_s.strip label = @analyzer.sentiment(text) # :positive, :neutral, or :negative score = case label when :positive then 1.0 when :negative then -1.0 else 0.0 end { label: label, score: score } end end |