Class: AnswerFactory::Machines::EvaluateSimpleScore

Inherits:
Machine
  • Object
show all
Defined in:
lib/machines/evaluate_simple_score.rb

Instance Attribute Summary

Attributes inherited from Machine

#options

Instance Method Summary collapse

Methods inherited from Machine

#initialize

Constructor Details

This class inherits a constructor from AnswerFactory::Machines::Machine

Instance Method Details

#score(batch, overridden_options = {}, &score_block) ⇒ Object Also known as: generate

Raises:

  • (ArgumentError)


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/machines/evaluate_simple_score.rb', line 9

def score(batch, overridden_options = {}, &score_block)
  all_options = @options.merge(overridden_options)
  name = all_options[:name]
  scorer = score_block || all_options[:scorer]
  
  raise ArgumentError, "EvaluateSimpleScore#score cannot process a #{batch.class}" unless
    batch.kind_of?(Batch)
  raise ArgumentError, "EvaluateSimpleScore: Undefined #name attribute" if
    name.nil?
  raise ArgumentError, "EvaluateSimpleScore: No scoring block available" if
    scorer.nil?
  
  batch.each do |answer|
    all_options[:static_score?] ?
      (answer.scores[name] ||= scorer.call(answer)) :
      (answer.scores[name] = scorer.call(answer))
  end
  return batch
end