Module: SentimentAnalysis

Defined in:
lib/alchemy_connect.rb

Class Method Summary collapse

Class Method Details

.get_sentiment(tweets) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/alchemy_connect.rb', line 4

def self.get_sentiment(tweets)
  alchemyapi = AlchemyAPI.new
  response = alchemyapi.sentiment("text", tweets)

  if response["status"] == "OK"
    puts '## Response Object ##'
    puts JSON.pretty_generate(response)
    puts ""
    puts '## Document Sentiment ##'
    puts "type: " + response["docSentiment"]["type"]
    # Make sure score exists (it's not returned for neutral sentiment
    if response["docSentiment"].key?("score")
      puts "score: " + response["docSentiment"]["score"]
    end
  else
    puts "Error in sentiment analysis call: " + response["statusInfo"]
  end
end