Class: GreenMidget::Examples
Constant Summary
collapse
- GENERAL_FEATURE_NAME =
'any'
Instance Attribute Summary
Attributes inherited from Countable
#key
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Countable
#[], #initialize, #log_ratio, #record_key
Class Method Details
.[](feature) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/green_midget/models/examples.rb', line 19
def self.[](feature)
object = super(feature)
if object.no_examples? && (feature == GENERAL_FEATURE_NAME)
raise NoExamplesGiven
elsif object.no_examples?
super GENERAL_FEATURE_NAME
else
object
end
end
|
.log_ratio ⇒ Object
36
37
38
|
# File 'lib/green_midget/models/examples.rb', line 36
def self.log_ratio
self[GENERAL_FEATURE_NAME].log_ratio
end
|
.objects(features, with_general = false) ⇒ Object
31
32
33
34
|
# File 'lib/green_midget/models/examples.rb', line 31
def self.objects(features, with_general = false)
features += with_general ? [ GENERAL_FEATURE_NAME ] : []
super(features)
end
|
.total ⇒ Object
40
41
42
|
# File 'lib/green_midget/models/examples.rb', line 40
def self.total
@@total ||= self[GENERAL_FEATURE_NAME].total
end
|
Instance Method Details
#no_examples? ⇒ Boolean
52
53
54
|
# File 'lib/green_midget/models/examples.rb', line 52
def no_examples?
CATEGORIES.inject(1) { |memo, category| memo *= self[category] } == 0
end
|
#probability_for(category) ⇒ Object
44
45
46
|
# File 'lib/green_midget/models/examples.rb', line 44
def probability_for(category)
self[category] / total
end
|
#total ⇒ Object
48
49
50
|
# File 'lib/green_midget/models/examples.rb', line 48
def total
CATEGORIES.inject(0) { |memo, category| memo += self[category] }
end
|