Class: VaderSentimentRuby::LexiconDictionaryCreator

Inherits:
Object
  • Object
show all
Defined in:
lib/vader_sentiment_ruby/lexicon_dictionary_creator.rb

Overview

Converts lexicon file to a dictionary

Instance Method Summary collapse

Instance Method Details

#callHash

Returns:

  • (Hash)


7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/vader_sentiment_ruby/lexicon_dictionary_creator.rb', line 7

def call
  lexicon_file = File.open("#{__dir__}/data/vader_lexicon.txt").read
  lex_dict = {}
  lines = lexicon_file.strip.split("\n")
  lines.each do |line|
    next unless line

    word, measure = line.strip.split("\t")[0..1]
    lex_dict[word] = measure.to_f
  end

  lex_dict
end