Class: AnswerFactory::Machines::EvaluateSimpleScore
- Defined in:
- lib/machines/evaluate_simple_score.rb
Instance Attribute Summary
Attributes inherited from Machine
Instance Method Summary collapse
- #score(batch, overridden_options = {}, &score_block) ⇒ Object (also: #generate)
Methods inherited from Machine
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
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, = {}, &score_block) = @options.merge() name = [:name] scorer = score_block || [: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| [:static_score?] ? (answer.scores[name] ||= scorer.call(answer)) : (answer.scores[name] = scorer.call(answer)) end return batch end |