Class: SentimentLib::Analyzer

Inherits:
Object
  • Object
show all
Defined in:
lib/sentiment_lib/analyzer.rb,
lib/sentiment_lib/analysis/sentiment_analyzer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Analyzer

Returns a new instance of Analyzer.



7
8
9
# File 'lib/sentiment_lib/analyzer.rb', line 7

def initialize(opts={})
  @strategy = opts[:strategy] || ::SentimentLib::Analysis::Strategies::FinancialDictStrategy.new
end

Instance Attribute Details

#strategyObject

Returns the value of attribute strategy.



5
6
7
# File 'lib/sentiment_lib/analyzer.rb', line 5

def strategy
  @strategy
end

Instance Method Details

#analyze(str, opts = {}) ⇒ Object



11
12
13
14
15
# File 'lib/sentiment_lib/analyzer.rb', line 11

def analyze(str, opts={})
  tokens = @strategy.tokenize(@strategy.normalize(str))

  @strategy.weigh(tokens)
end