class EncodingEstimator::Detection

Class to represent the results of a detection process.

Public Class Methods

new( scores, conversions ) click to toggle source

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

@param [Hash] scores Hash of scores mapping the conversion identifier key to

the score for that conversion

@param [Array<EncodingEstimator::Conversion>] conversions objects the scores table references

# File lib/encoding_estimator/detection.rb, line 11
def initialize( scores, conversions )
  @scores      = scores
  @conversions = conversions
end

Public Instance Methods

result() click to toggle source

Get the most probable conversion

@return [EncodingEstimator::Conversion] Most probable conversion

# File lib/encoding_estimator/detection.rb, line 19
def result
  @result ||= calculate_result
end
results() click to toggle source

Get all conversions and their scores

@return [Array<Hash>] Array containing a hash for every conversion of the form

{ conversion: EncodingEstimator::Conversion, score: Float }
# File lib/encoding_estimator/detection.rb, line 34
def results
  @results ||= @conversions.map { |c| { conversion: c, score: @scores[ c.key ] } }
end
score() click to toggle source

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

@return [Float] Score of the most probable conversion

# File lib/encoding_estimator/detection.rb, line 26
def score
  @scores[ result.key ]
end

Private Instance Methods

calculate_result() click to toggle source

Find the most probable conversion

@return [EncodingEstimator::Conversion] The most probable conversion

# File lib/encoding_estimator/detection.rb, line 42
def calculate_result
  max_conv = @conversions.first
  @conversions.each { |conv| max_conv = conv if @scores[conv.key] > @scores[max_conv.key] }

  max_conv
end