class See5::Model
Attributes
rules[R]
Public Class Methods
from_json(json)
click to toggle source
# File lib/see5/model.rb, line 33 def self.from_json(json) json_hash = JSON.parse(json, symbolize_names: true) new(default_classification: json_hash[:default_classification], rules: json_hash[:rules]&.map { |rule_hash| Rule.from_h(rule_hash) }) end
new(default_classification:, rules:)
click to toggle source
# File lib/see5/model.rb, line 9 def initialize(default_classification:, rules:) @default_classification = default_classification @rules = rules end
Public Instance Methods
classify(data)
click to toggle source
# 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()
click to toggle source
# File lib/see5/model.rb, line 24 def to_h { default_classification: @default_classification, rules: rules.map(&:to_h) } end
to_json()
click to toggle source
# File lib/see5/model.rb, line 29 def to_json to_h.to_json end