somme_score.rb 1.07 KB
#!/usr/bin/env ruby

require "rubygems"

def launch(task, files)

    h = Hash.new
    convert = nil

    if task == "task1"
        convert = {0 => "negative", 1 => "positive", 2 => "objective", 3 => "mixed"}
    end
    
    if task == "task2"
        convert = {0 => "figurative", 1 => "nonfigurative"}
    end

    if task == "task3"
        convert = {0 => "negative", 1 => "positive", 2 => "objective", 3 => "mixed"}
    end
 
    
    files.each do |file|
        f = File.open(file)
        f.each do |line|
            line.chomp!
            line = line.split("\t")
            h[ line[0] ] ||= Array.new(4, 0)
            counter = 0
            line[1].split(" ").each do |x|
                h[ line[0] ][ counter ] += x.to_f
                counter += 1
            end
        end
        f.close
    end

    h.each do |key, value|
        value.map! { |x| x.to_f/files.size.to_f }
        puts "#{key}\t#{value.join(" ")}"
    end


end


def errarg
    puts "Usage : ./programme.rb"
    puts "Mickael Rouvier <mickael.rouvier@univ-avignon.fr>"
end


launch(ARGV[0], ARGV[1..-1])