compare.rb 2.13 KB
#!/usr/bin/env ruby

require "rubygems"

def read_oki()
    h = Hash.new(false)
    f = File.open("oki2.txt")
    f.each do |line|
        line.chomp!
        line = line.split(" ")
        h[ line[0] ] = true
    end
    f.close
    return h
end

def read_embedding()
    h = Hash.new(false)
    f = File.open("embedding/word2vecf_size100_win3.bin")
    f.each do |line|
        line.chomp!
        line = line.split(" ")
        if line.size > 4
            h[ line[0] ] = true
        end
    end
    f.close
    return h
end

def embedding(text, h)
    text.split(" ").each do |w|
        if w[0] == "#"
            if h.key?(w.downcase) == false
                return true
            end
        end
    end
    return false
end


def majuscule(text)

    counter = 0
    text.split(" ").each do |w|
        if w.size > 2
            if w.upcase == w
                counter += 1
            end
        end
    end

    if counter > 1
        return true
    end

    return false
end

def launch(output_dnn, annotation, type)
    #hemb = read_embedding()
    hoki = read_oki()

    h = Hash.new
    f = File.open(output_dnn)
    f.each do |line|
        line.chomp!
        line = line.split("\t")
        h[ line[0] ] = line[1]
=begin
        score = line[1].split(" ")
        score.map! { |x| x.to_f }
        ind = score.index( score.max )
        if ind == 0
            h[ line[0] ] = "negative"
        end

        if ind == 1
            h[ line[0] ] = "positive"
        end
=end
    end
    f.close



    f = File.open(annotation)
    f.each do |line|
        line.chomp!
        line = line.split("\t")
        a = line[2]
        line[2] = line[1]
        line[1] = a
        if h.key?( line[0] )
            if h[ line[0] ] != line[1]
                    #if hoki.key?(line[0]) == false

                        puts "#{line[0]}\t#{type}\t#{line[1]}\t#{h[ line[0] ]}\t#{line[2]}"
                    #end
            end
        end

    end
    f.close



end


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


if ARGV.size == 3
    launch(ARGV[0], ARGV[1], ARGV[2])
else
    errarg
end