Class: Datasets::AFINN

Inherits:
Dataset show all
Defined in:
lib/datasets/afinn.rb

Defined Under Namespace

Classes: Record

Instance Attribute Summary

Attributes inherited from Dataset

#metadata

Instance Method Summary collapse

Methods inherited from Dataset

#clear_cache!, #to_table

Constructor Details

#initializeAFINN

Returns a new instance of AFINN.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/datasets/afinn.rb', line 9

def initialize
  super()
  @metadata.id = "afinn"
  @metadata.name = "AFINN"
  @metadata.url = "http://www2.imm.dtu.dk/pubdb/pubs/6010-full.html"
  @metadata.licenses = ["ODbL-1.0"]
  @metadata.description = lambda do
    extract_file("AFINN/AFINN-README.txt") do |input|
      readme = input.read
      readme.force_encoding("UTF-8")
      readme.
        gsub(/^AFINN-96:.*?\n\n/m, "").
        gsub(/^In Python.*$/m, "").
        strip
    end
  end
end

Instance Method Details

#eachObject



27
28
29
30
31
32
33
34
35
36
# File 'lib/datasets/afinn.rb', line 27

def each
  return to_enum(__method__) unless block_given?

  extract_file("AFINN/AFINN-111.txt") do |input|
    csv = CSV.new(input, col_sep: "\t", converters: :numeric)
    csv.each do |row|
      yield(Record.new(*row))
    end
  end
end