Last active
August 29, 2015 14:22
-
-
Save dhiraka/1923d65865331c420d42 to your computer and use it in GitHub Desktop.
Sentiment Analysis for a bunch of texts to be done asynchronously
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'httparty' | |
module SentimentAnalysis | |
texts = [ | |
"I am a pathetic person", | |
"Today is going to be a good day", | |
"I wish you were dead" | |
] | |
def self.calculate(texts) | |
actions = [] | |
for text in texts | |
actions.push( | |
{ | |
params:{ | |
text:text, | |
apikey: ENV['SENTIMENT_ANALYSIS_API_KEY'] | |
} | |
} | |
) | |
end | |
job_id = HTTParty.post( | |
'https://api.idolondemand.com/1/job', | |
{ | |
query: { | |
actions: actions | |
} | |
} | |
) | |
puts job_id.response.inspect | |
result = HTTParty.get( | |
'https://api.idolondemand.com/1/job/result/' + job_id, | |
{ | |
query: { | |
apikey: ENV['SENTIMENT_ANALYSIS_API_KEY'], | |
} | |
} | |
) | |
puts result.inspect | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment