Class: Phronomy::Eval::Scorer::ExactMatch
- Defined in:
- lib/phronomy/eval/scorer/exact_match.rb
Overview
Scorer that returns 1.0 when the actual output exactly matches the expected output (after stripping leading/trailing whitespace). Comparison is case-sensitive by default.
Instance Method Summary collapse
-
#initialize(case_sensitive: true) ⇒ ExactMatch
constructor
A new instance of ExactMatch.
-
#score(actual:, expected:, input: nil) ⇒ Float
1.0 on match, 0.0 otherwise.
Constructor Details
#initialize(case_sensitive: true) ⇒ ExactMatch
Returns a new instance of ExactMatch.
15 16 17 |
# File 'lib/phronomy/eval/scorer/exact_match.rb', line 15 def initialize(case_sensitive: true) @case_sensitive = case_sensitive end |
Instance Method Details
#score(actual:, expected:, input: nil) ⇒ Float
Returns 1.0 on match, 0.0 otherwise.
20 21 22 23 24 25 |
# File 'lib/phronomy/eval/scorer/exact_match.rb', line 20 def score(actual:, expected:, input: nil) a = actual.to_s.strip e = expected.to_s.strip a = a.downcase and e = e.downcase unless @case_sensitive (a == e) ? 1.0 : 0.0 end |