From: <kt...@us...> - 2008-02-15 12:59:02
|
Revision: 1591 http://tomoe.svn.sourceforge.net/tomoe/?rev=1591&view=rev Author: ktou Date: 2008-02-15 04:59:03 -0800 (Fri, 15 Feb 2008) Log Message: ----------- * benchmark/evaluation.rb: created run to split initialize. Modified Paths: -------------- tomoe/trunk/ChangeLog tomoe/trunk/benchmark/evaluation.rb Modified: tomoe/trunk/ChangeLog =================================================================== --- tomoe/trunk/ChangeLog 2008-02-15 12:51:36 UTC (rev 1590) +++ tomoe/trunk/ChangeLog 2008-02-15 12:59:03 UTC (rev 1591) @@ -8,6 +8,7 @@ - used TomoeTestUtils::Path. - used 2 spaces for indentation. (it's natural for Ruby script.) - used each rather than for ... in. (it's natural for Ruby script.) + - created run to split initialize. * benchmark/search-by-recognizer.rb: TomoeSpecUtils -> TomoeTestUtils. Modified: tomoe/trunk/benchmark/evaluation.rb =================================================================== --- tomoe/trunk/benchmark/evaluation.rb 2008-02-15 12:51:36 UTC (rev 1590) +++ tomoe/trunk/benchmark/evaluation.rb 2008-02-15 12:59:03 UTC (rev 1591) @@ -13,39 +13,38 @@ include TomoeTestUtils::Path def initialize(recognizer_class, set) - data_folder = File.join(benchmark_data_dir, set) + @recognizer_class = recognizer_class - xml_files = Dir.glob(File.join(data_folder, "*.xml")) - @n_files = xml_files.length + data_set_dir = File.join(benchmark_data_dir, set) + @xml_files = Dir.glob(File.join(data_set_dir, "*.xml")) + @n_files = @xml_files.length + @results = {} + @match1 = [] + @match5 = [] + @match10 = [] + end + + def run dict = Tomoe::DictXML.new("filename" => handwriting_dictionary("ja"), "editable" => false) - - recognizer = recognizer_class.new("dictionary" => dict) - + recognizer = @recognizer_class.new("dictionary" => dict) context = Tomoe::Context.new("recognizer" => recognizer) - context.load_config() - query = Tomoe::Query.new - @results = {} - @match1 = [] - @match5 = [] - @match10 = [] - - xml_files.each do |xml_file| + @xml_files.each do |xml_file| char = Tomoe::Char.new(IO.read(xml_file)) char_utf8 = char.utf8 query.writing = char.writing - candidates = context.search(query).map { |c| c.char.utf8 } + candidates = context.search(query).map {|c| c.char.utf8} ten_candidates = candidates[0...10] @results[char_utf8] = candidates @match1 << char_utf8 if ten_candidates.first == char_utf8 - @match5 << char_utf8 if ten_candidates[0...5].include? char_utf8 - @match10 << char_utf8 if ten_candidates.include? char_utf8 + @match5 << char_utf8 if ten_candidates[0...5].include?(char_utf8) + @match10 << char_utf8 if ten_candidates.include?(char_utf8) end end @@ -63,11 +62,9 @@ def character_details(char_utf8) ret = char_utf8 + "\t" - ret << if i = @results[char_utf8].index(char_utf8) - "%d\t" % (i + 1) - else - "X\t" - end + i = @results[char_utf8].index(char_utf8) + ret << (i ? "%d" % (i + 1) : "X") + ret << "\t" ret << @results[char_utf8][0...5].join(", ") end @@ -88,13 +85,16 @@ sets.each do |set| puts "#{recognizer.to_s}, #{set}" evaluation = Evaluation.new(recognizer, set) + evaluation.run puts "1st match: #{evaluation.first_match_accuracy.to_s}%" puts "5th match: #{evaluation.fith_match_accuracy.to_s}%" puts "10th match: #{evaluation.tenth_match_accuracy.to_s}%" - evaluation.characters.each do |char| - puts evaluation.character_details(char) - end if detailed + if detailed + evaluation.characters.each do |char| + puts evaluation.character_details(char) + end + end match1 += evaluation.first_match_accuracy match5 += evaluation.fith_match_accuracy This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |