Class: EvalRuby::RSpecMatchers::HavePrecisionAtK
- Inherits:
-
Object
- Object
- EvalRuby::RSpecMatchers::HavePrecisionAtK
- Defined in:
- lib/eval_ruby/rspec.rb
Overview
RSpec matcher that checks precision@k for retrieval results.
Instance Method Summary collapse
- #above(threshold) ⇒ self
- #failure_message ⇒ String
-
#initialize(k) ⇒ HavePrecisionAtK
constructor
A new instance of HavePrecisionAtK.
- #matches?(results) ⇒ Boolean
Constructor Details
#initialize(k) ⇒ HavePrecisionAtK
Returns a new instance of HavePrecisionAtK.
52 53 54 55 |
# File 'lib/eval_ruby/rspec.rb', line 52 def initialize(k) @k = k @threshold = 0.5 end |
Instance Method Details
#above(threshold) ⇒ self
59 60 61 62 |
# File 'lib/eval_ruby/rspec.rb', line 59 def above(threshold) @threshold = threshold self end |
#failure_message ⇒ String
77 78 79 |
# File 'lib/eval_ruby/rspec.rb', line 77 def "expected precision@#{@k} >= #{@threshold}, but got #{@score.round(4)}" end |
#matches?(results) ⇒ Boolean
66 67 68 69 70 71 72 73 74 |
# File 'lib/eval_ruby/rspec.rb', line 66 def matches?(results) @results = results if results.is_a?(EvalRuby::RetrievalResult) @score = results.precision_at_k(@k) else raise ArgumentError, "Expected EvalRuby::RetrievalResult or use assert_precision_at_k" end @score >= @threshold end |