class Object
Public Instance Methods
get_m1(hash)
click to toggle source
# File tools/calculate_sents_diff.rb, line 43 def get_m1 hash if (hash['posTs'].to_f > hash['negTs'].to_f) if hash['posOs'].to_f> hash['negOs'].to_f return 1 else return 0 end else return nil end end
get_m1_result(results)
click to toggle source
# File tools/calculate_sents_diff.rb, line 91 def get_m1_result results total = results[:excelent] + results[:bad] return (results[:excelent].to_f / total) * 100 end
get_m2(hash)
click to toggle source
# File tools/calculate_sents_diff.rb, line 55 def get_m2 hash diffTs = sum_neg_pos(hash, 'Ts') diffOs = sum_neg_pos(hash, 'Os') p diffTs p diffOs if diffTs >= 0.66 if diffOs >= 0.66 return 1 else return 0 end elsif diffTs >= 0.33 if diffOs >= 0.33 and diffOs <= 0.66 return 1 else return 0 end elsif diffTs > 0 if diffOs <= 0.33 return 1 else return 0 end end end
get_total_sentiment(hash)
click to toggle source
# File tools/calculate_sents_diff.rb, line 6 def get_total_sentiment hash if (hash['posTs'].to_f >= 0.5) if hash['posOs'].to_f >= 0.5 return 1 else return 0 end elsif (hash['negTs'].to_f >= 0.5) if hash['negOs'].to_f >= 0.5 return 1 else return 0 end elsif (hash['neuTs'].to_f >= 0.5) if hash['neuOs'].to_f >= 0.5 return 1 else return 0 end else return nil end end
interpret_results(diff, hash)
click to toggle source
# File tools/calculate_sents_diff.rb, line 30 def interpret_results diff, hash if diff < 2 hash[:excelent] +=1 elsif (diff< 5) hash[:not_bad] +=1 elsif diff > 5 hash[:bad] +=1 end end
prepare_article(content, url, title, domain='GENERAL')
click to toggle source
# File lib/sentra/opr.rb, line 75 def prepare_article content, url, title, domain='GENERAL' tweet = OprData::Article.new calendar = Util::Calendar.getInstance(); tweet.setUrl(Net::URL.new(url)); tweet.setDate(calendar.getTime) tweet.setTitle(title) tweet.setChannel(domain) tweet.setContent(content) tweet end
process_result(statistics)
click to toggle source
# File lib/sentra/opr.rb, line 88 def process_result statistics response = {} # puts 'here statistics' # p statistics if statistics[3].getValue.to_f > 0 response['negative'] = statistics[0].getValue.to_f / statistics[3].getValue.to_f response['positive'] = statistics[1].getValue.to_f / statistics[3].getValue.to_f response['neutral'] = statistics[2].getValue.to_f / statistics[3].getValue.to_f else response['negative'] = 0 response['positive'] = 0 response['neutral'] = 1 end response['details'] = {} response end
run_m1()
click to toggle source
# File tools/calculate_sents_diff.rb, line 97 def run_m1 rand = Random.new results = {} results[:excelent] = 0 results[:bad] = 0 samples = [] random_samples = [] CSV.foreach(@path_test + 'tweets_cmp.csv', :headers => true) do |row| diff = get_total_sentiment(row) # p diff if not diff.nil? case diff when 0 results[:bad] += 1 samples.push row when 1 results[:excelent] +=1 end end end puts 'The positive conincide in ' + get_m1_result(results).to_s + ' cases' length = samples.length - 1 100.times do |time| random_samples.push(samples[rand.rand(0..length)]) end CSV.open(@path_test + 'randoms.csv', 'wb') do |csv| csv << ['tweet', 'posTs', 'negTs', 'neuTs', 'posOs', 'negOs', 'neuOs'] random_samples.each do |query| csv << [query['tweet'], query['posTs'], query['negTs'], query['neuTs'], query['posOs'], query['negOs'], query['neuOs']] end end end
run_m2()
click to toggle source
# File tools/calculate_sents_diff.rb, line 137 def run_m2 results = {} results[:excelent] = 0 results[:bad] = 0 CSV.foreach('tweets_cmp.csv', :headers => true) do |row| diff = get_m2(row) p diff if not diff.nil? case diff when 0 results[:bad] += 1 when 1 results[:excelent] +=1 end end end puts 'The emotional conincide in ' + get_m1_result(results).to_s + ' cases' end
sum_neg_pos(hash, ext)
click to toggle source
# File tools/calculate_sents_diff.rb, line 83 def sum_neg_pos hash, ext pos = 'pos' + ext neg = 'neg' + ext return hash[pos].to_f + hash[neg].to_f end