module SentimentAnalysis
Public Class Methods
get_sentiment(tweets)
click to toggle source
# 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