Class: See5::Model
- Inherits:
-
Object
- Object
- See5::Model
- Defined in:
- lib/see5/model.rb
Instance Attribute Summary collapse
-
#rules ⇒ Object
readonly
Returns the value of attribute rules.
Class Method Summary collapse
Instance Method Summary collapse
- #classify(data) ⇒ Object
-
#initialize(default_classification:, rules:) ⇒ Model
constructor
A new instance of Model.
- #to_h ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize(default_classification:, rules:) ⇒ Model
Returns a new instance of Model.
9 10 11 12 |
# File 'lib/see5/model.rb', line 9 def initialize(default_classification:, rules:) @default_classification = default_classification @rules = rules end |
Instance Attribute Details
#rules ⇒ Object (readonly)
Returns the value of attribute rules.
7 8 9 |
# File 'lib/see5/model.rb', line 7 def rules @rules end |
Class Method Details
Instance Method Details
#classify(data) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/see5/model.rb', line 14 def classify(data) # See5 orders rules by confidence within each class (TODO verify), # so the first matching rule is the one with the highest confidence. first_matching_rule = rules.find { |rule| rule.match?(data) } return first_matching_rule.classification unless first_matching_rule.nil? @default_classification end |
#to_h ⇒ Object
24 25 26 27 |
# File 'lib/see5/model.rb', line 24 def to_h { default_classification: @default_classification, rules: rules.map(&:to_h) } end |
#to_json ⇒ Object
29 30 31 |
# File 'lib/see5/model.rb', line 29 def to_json to_h.to_json end |