Class: See5::RulesOutputParser
- Inherits:
-
Object
- Object
- See5::RulesOutputParser
- Defined in:
- lib/see5/rules_output_parser.rb
Overview
Read See5 rules output and return an array of hashes representing the rules Note that this is the output normally sent to stdout, NOT the .rules file! The .rules file lacks some important information like confidence.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(fname) ⇒ RulesOutputParser
constructor
A new instance of RulesOutputParser.
- #model ⇒ Object
- #parse_file ⇒ Object
Constructor Details
#initialize(fname) ⇒ RulesOutputParser
Returns a new instance of RulesOutputParser.
14 15 16 17 18 19 |
# File 'lib/see5/rules_output_parser.rb', line 14 def initialize(fname) @file = File.open(fname) @rules = [] parse_file end |
Class Method Details
.parse_file(fname) ⇒ Object
10 11 12 |
# File 'lib/see5/rules_output_parser.rb', line 10 def self.parse_file(fname) new(fname).model end |
Instance Method Details
#model ⇒ Object
21 22 23 24 25 26 |
# File 'lib/see5/rules_output_parser.rb', line 21 def model { default_classification: @default_classification, rules: @rules } end |
#parse_file ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/see5/rules_output_parser.rb', line 28 def parse_file discard_header while (line = lines.next) if line.start_with?("Rule ") @rules << parse_rule(line) elsif line.start_with?("Default class:") @default_classification = line.split(":").last.strip break end end end |