Class: SentimentLib::Analysis::Strategies::FinancialDictStrategy
- Inherits:
-
SentimentLib::Analysis::Strategy
- Object
- SentimentLib::Analysis::Strategy
- SentimentLib::Analysis::Strategies::FinancialDictStrategy
- Defined in:
- lib/sentiment_lib/analysis/strategies/financial_dict_strategy.rb
Constant Summary collapse
- @@mappings =
nil
Instance Method Summary collapse
-
#initialize ⇒ FinancialDictStrategy
constructor
A new instance of FinancialDictStrategy.
- #mappings ⇒ Object
-
#weigh(tokens, opts = {}) ⇒ Object
weight is pure sum (not average).
Methods inherited from SentimentLib::Analysis::Strategy
Constructor Details
#initialize ⇒ FinancialDictStrategy
Returns a new instance of FinancialDictStrategy.
9 10 11 |
# File 'lib/sentiment_lib/analysis/strategies/financial_dict_strategy.rb', line 9 def initialize self.class._load_mappings if !@@mappings end |
Instance Method Details
#mappings ⇒ Object
13 14 15 |
# File 'lib/sentiment_lib/analysis/strategies/financial_dict_strategy.rb', line 13 def mappings @@mappings end |
#weigh(tokens, opts = {}) ⇒ Object
weight is pure sum (not average)
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/sentiment_lib/analysis/strategies/financial_dict_strategy.rb', line 18 def weigh(tokens, opts={}) valid_tokens = tokens.delete_if { |token| mappings[token] == nil } return 0 if valid_tokens.length == 0 sum = 0 valid_tokens.each { |token| sum += mappings[token] } if opts[:average] == true sum / valid_tokens.length else sum end end |