Class: CorrectHorseBatteryStaple::Writer::Csv

Inherits:
File show all
Defined in:
lib/correct_horse_battery_staple/writer/csv.rb

Instance Attribute Summary

Attributes inherited from File

#io

Attributes inherited from Base

#dest, #options

Instance Method Summary collapse

Methods inherited from File

#close

Methods inherited from Base

#close

Methods included from Common

#array_sample, #logger, #random_in_range, #random_number, #set_sample

Methods inherited from CorrectHorseBatteryStaple::Writer

make_writer, write

Constructor Details

#initialize(dest, options = {}) ⇒ Csv

Returns a new instance of Csv.



3
4
5
# File 'lib/correct_horse_battery_staple/writer/csv.rb', line 3

def initialize(dest, options={})
  super
end

Instance Method Details

#write_corpus(corpus) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/correct_horse_battery_staple/writer/csv.rb', line 7

def write_corpus(corpus)
  puts "index,rank,word,frequency,percentile,distance,probability,distance_probability"
  corpus.each_with_index do |w, index|
    puts sprintf("%d,%d,\"%s\",%d,%.4f,%.6f,%.8f,%.8f\n",
      index || -1, w.rank || -1, w.word, w.frequency || -1,
      w.percentile || -1, w.distance || -1, w.probability || -1, w.distance_probability || -1)
  end
end