Class: EncodingEstimator::Detection

Inherits:
Object
  • Object
show all
Defined in:
lib/encoding_estimator/detection.rb

Overview

Class to represent the results of a detection process.

Instance Method Summary collapse

Constructor Details

#initialize(scores, conversions) ⇒ Detection

Initialize a new object from the evaluation scores and the conversions tested

Parameters:

  • scores (Hash)

    Hash of scores mapping the conversion identifier key to the score for that conversion

  • conversions (Array<EncodingEstimator::Conversion>)

    objects the scores table references



11
12
13
14
# File 'lib/encoding_estimator/detection.rb', line 11

def initialize( scores, conversions )
  @scores      = scores
  @conversions = conversions
end

Instance Method Details

#resultEncodingEstimator::Conversion

Get the most probable conversion

Returns:



19
20
21
# File 'lib/encoding_estimator/detection.rb', line 19

def result
  @result ||= calculate_result
end

#resultsArray<Hash>

Get all conversions and their scores

Returns:

  • (Array<Hash>)

    Array containing a hash for every conversion of the form { conversion: EncodingEstimator::Conversion, score: Float }



34
35
36
# File 'lib/encoding_estimator/detection.rb', line 34

def results
  @results ||= @conversions.map { |c| { conversion: c, score: @scores[ c.key ] } }
end

#scoreFloat

Get the score of the most probable conversion (-> the highest score)

Returns:

  • (Float)

    Score of the most probable conversion



26
27
28
# File 'lib/encoding_estimator/detection.rb', line 26

def score
  @scores[ result.key ]
end