Class: Datasets::LIBSVMDatasetList::DetailListener
- Inherits:
-
Object
- Object
- Datasets::LIBSVMDatasetList::DetailListener
- Includes:
- REXML::StreamListener
- Defined in:
- lib/datasets/libsvm-dataset-list.rb
Instance Method Summary collapse
-
#initialize(abort_tag, id, base_url, record) ⇒ DetailListener
constructor
A new instance of DetailListener.
- #tag_end(name) ⇒ Object
- #tag_start(name, attributes) ⇒ Object
- #text(data) ⇒ Object
Constructor Details
#initialize(abort_tag, id, base_url, record) ⇒ DetailListener
Returns a new instance of DetailListener.
143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/datasets/libsvm-dataset-list.rb', line 143 def initialize(abort_tag, id, base_url, record) @abort_tag = abort_tag @id = id @base_url = base_url @record = record @in_target = false @target_li_level = nil @key = nil @data = nil @file = nil end |
Instance Method Details
#tag_end(name) ⇒ Object
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/datasets/libsvm-dataset-list.rb', line 179 def tag_end(name) if @in_target case name when "ul" throw(@abort_tag) if @target_li_level == -1 when "li" case @target_li_level when 0 if @key data = @data data = data.gsub(/[ \t\n]+/, " ").strip if data.is_a?(String) @record[@key] = data end when 1 @data << @file if @data and @file end @target_li_level -= 1 end end end |
#tag_start(name, attributes) ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/datasets/libsvm-dataset-list.rb', line 155 def tag_start(name, attributes) if @in_target case name when "li" @target_li_level += 1 case @target_li_level when 0 @key = nil @data = nil @file = nil when 1 @file = File.new end when "a" @file.url = @base_url + attributes["href"] if @file end else if attributes["name"] == @id @in_target = true @target_li_level = -1 end end end |
#text(data) ⇒ Object
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/datasets/libsvm-dataset-list.rb', line 200 def text(data) case @target_li_level when 0 if @key @data << data else case data.gsub(/[ \t\n]+/, " ") when /\ASource: / @key = :source @data = $POSTMATCH when /\APreprocessing: / @key = :preprocessing @data = $POSTMATCH when /\A\# of classes: (\d+)/ @key = :n_classes @data = Integer($1, 10) when /\A\# of data: ([\d,]+)/ @key = :n_data @data = Integer($1.gsub(/,/, ""), 10) when /\A\# of features: ([\d,]+)/ @key = :n_features @data = Integer($1.gsub(/,/, ""), 10) when /\AFiles:/ @key = :files @data = [] end end when 1 if @file.name.nil? @file.name = data else @file.note = data.strip.gsub(/[()]/, "") end end end |