Class: Iriq::PositionEvidence

Inherits:
Struct
  • Object
show all
Defined in:
lib/iriq/position_evidence.rb

Overview

The slice of a position's stats that classifying one value reads (Corpus#classify). A backend can answer it without materializing every value tracked at the position.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#cardinalityObject

Returns the value of attribute cardinality

Returns:

  • the current value of cardinality



5
6
7
# File 'lib/iriq/position_evidence.rb', line 5

def cardinality
  @cardinality
end

#totalObject

Returns the value of attribute total

Returns:

  • the current value of total



5
6
7
# File 'lib/iriq/position_evidence.rb', line 5

def total
  @total
end

#type_countsObject

Returns the value of attribute type_counts

Returns:

  • the current value of type_counts



5
6
7
# File 'lib/iriq/position_evidence.rb', line 5

def type_counts
  @type_counts
end

#value_countObject

Returns the value of attribute value_count

Returns:

  • the current value of value_count



5
6
7
# File 'lib/iriq/position_evidence.rb', line 5

def value_count
  @value_count
end

Class Method Details

.from_stats(stats, value) ⇒ Object

value_count is nil when the value isn't tracked (never seen, or dropped at the cap).



8
9
10
11
12
13
14
15
# File 'lib/iriq/position_evidence.rb', line 8

def self.from_stats(stats, value)
  new(
    total:       stats.total,
    type_counts: stats.type_counts,
    cardinality: stats.cardinality,
    value_count: stats.value_counts.fetch(value, nil),
  )
end

Instance Method Details

#value_fractionObject

Same as PositionStats#value_fraction for the probed value.



25
26
27
28
29
# File 'lib/iriq/position_evidence.rb', line 25

def value_fraction
  return 0.0 if total.zero?

  (value_count || 0).to_f / total
end

#variable_fraction(classifier) ⇒ Object

Same as PositionStats#variable_fraction.



18
19
20
21
22
# File 'lib/iriq/position_evidence.rb', line 18

def variable_fraction(classifier)
  return 0.0 if total.zero?

  type_counts.sum { |t, c| classifier.variable?(t) ? c : 0 }.to_f / total
end