###### fingerprinting results parser ###### # # parses a results file and prints the number of # correct guesses for each modification. # # 2012 01 16 # ############################### # # The input looks like this: # #Best 15 matches for MR.1969.3.10-B11_0.15_white_noise.wav: # 1 Close match (80%) with: MR.1968.16.8-16.wav # 2 Close match (78%) with: MR.1969.18.4-47.wav # 3 Close match (77%) with: MR.1968.30.1-11.wav # 4 Close match (76%) with: MR.1976.13.3-10.wav # 5 Close match (76%) with: MR.1985.23.7-1.wav # 6 Close match (76%) with: MR.1969.18.4-46.wav # 7 Close match (75%) with: MR.1969.3.7-B12.wav # 8 Close match (74%) with: MR.2004.35.13-11.wav # 9 Close match (74%) with: MR.1959.5.3.wav # 10 Close match (74%) with: MR.1976.15.3-5.wav # 11 Close match (74%) with: MR.1969.18.4-60.wav # 12 Close match (74%) with: MR.1976.13.3-14.wav # 13 Close match (74%) with: MR.1971.15.9-21.mp3 # 14 Close match (74%) with: MR.1968.19.16-5.wav # 15 Close match (74%) with: MR.1959.18.4-B4.mp3 # ############################## #!/bin/ruby modifications = %w(.10_percent_faster .10_percent_slower .10_sec_less .15_sec_less .20_percent_faster .20_percent_slower .20_sec_less .25_sec_less .30_sec_less .35_sec_less .40_sec_less .45_sec_less .50_sec_less .55_sec_less .60_sec_less .one_semitone_down .one_semitone_up .original .reversed .two_semitones_down .two_semitones_up _0.1_white_noise _0.2_white_noise _0.3_white_noise _0.05_white_noise _0.15_white_noise _0.25_white_noise) modifications = modifications.map{|m| m + ".wav"} modification_counts = Array.new 15.times do modification_count_hash = Hash.new modifications.each{|m| modification_count_hash[m] = 0} modification_counts << modification_count_hash end counter = 0 File.open('fingerprinting_results.txt','r') do |input_file| while(line = input_file.gets) modifications.each do |m| if line =~ /.*for (.*)(#{m}).*/ file_to_match = $1 #puts "#{counter} #{file_to_match} #{$2}" counter = counter + 1 matches = Array.new 15.times{matches << input_file.gets} 15.times do |i| modification_count_hash = modification_counts[i] is_match = false (i+1).times do |j| is_match = (is_match or matches[j] =~ /.*#{file_to_match}.*/) end modification_count_hash[m] = modification_count_hash[m] + 1 if is_match end end end end end puts "Modification;#{(1...16).to_a.join(' match;')}" modification_counts[0].each do |modification, number_correct| results = Array.new 15.times{|i| results << modification_counts[i][modification]/50.0} puts "#{modification.gsub('.wav','')};#{results.join(';')}" end