class Cmp

Public Class Methods

new() click to toggle source
# File tools/compare_sentiments.rb, line 4
def initialize
  @filename = 'tweets.csv'
  @url ="http://localhost:4567/sentra/analyzer/batch"
  @file_out = CSV.open('tweets_cmp.csv', "wb")
  @file_errors = File.new('errors.csv', 'wb')
end

Public Instance Methods

make_compare() click to toggle source
# File tools/compare_sentiments.rb, line 11
def make_compare

  mycsv = CSV_MODULE::MyCSV.new(@filename)
  queries = mycsv.get_queries
  @file_out << ['screen_name', 'tweet', 'posTs', 'negTs', 'neuTs', 'difference', 'posOs', 'negOs', 'neuOs']
  queries.each_with_index do |query, index|
    p index
    q = {}
    q['content'] = query['tweet']

    #puts "Sent content " + q['content'].to_s
    begin
    response = RestClient2.post(@url, q.to_json)

    json = JSON.parse(response.body)
    #puts "RECEIVED RESPONSE: " + json.to_s
    #p query['pos']
    @file_out << [query['screen_name'],query['tweet'], query['pos'], query['neg'], query['neu'], 0 ,
                  json['positive'], json['negative'], json['neutral']]
    rescue Exception => e
      @file_errors.puts index.to_s + ', ' + '"'+  q['content']   + '"'
      puts "Catching erros"
      p e.message
    end
  end

end