# File scripts/eval.rb, line 29
def score_ad(ext_atts, fielded_atts)
  relv_matches_found = 0
  # First, find out what we extracted, correctly or incorrectly.
  ext_atts.each do |f,v|
    if !fielded_atts.has_key?(f)
      puts "    Falsely extracted #{f}=#{v}"
    elsif fielded_atts[f] != v
      good_val = fielded_atts[f]
      puts "    For #{f} -- extracted: #{v}"
      puts "          should have been: #{good_val}"
    else
      relv_matches_found += 1
    end
  end
  # Now, find out what we did not extract, but should have.
  fielded_atts.each do |f,v|
    puts "    Failed to extract #{f}=#{v}" if !ext_atts.has_key?(f)
  end
  # Finally, print results for this ad and return the count.
  p = relv_matches_found.to_f / ext_atts.size.to_f
  r = relv_matches_found.to_f / fielded_atts.size.to_f
  puts "  ***Precision=#{p}, Recall=#{r}***"
  return relv_matches_found
end