Class: SentimentLib::Analyzer
- Inherits:
-
Object
- Object
- SentimentLib::Analyzer
- Defined in:
- lib/sentiment_lib/analyzer.rb,
lib/sentiment_lib/analysis/sentiment_analyzer.rb
Instance Attribute Summary collapse
-
#strategy ⇒ Object
Returns the value of attribute strategy.
Instance Method Summary collapse
- #analyze(str, opts = {}) ⇒ Object
-
#initialize(opts = {}) ⇒ Analyzer
constructor
A new instance of Analyzer.
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
#strategy ⇒ Object
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 |