
Product
Socket Now Protects the Chrome Extension Ecosystem
Socket is launching experimental protection for Chrome extensions, scanning for malware and risky permissions to prevent silent supply chain attacks.
A simple, extensible sentiment analysis gem.
Add this line to your application's Gemfile:
gem 'sentiment_lib'
And then execute:
$ bundle
Or install it yourself as:
$ gem install sentiment_lib
SentimentLib exposes simple sentiment analysis via SentimentLib::Analyzer.
example usage --
analyzer = SentimentLib::Analyzer.new
analyzer.analyze("I'm feeling confident and excited this morning!")
=> 2.0
The library ships with two analysis strategies (you will liklely want to add your own domain-specific strategies):
SentimentLib::Analysis::Strategies::BasicDictStrategy
and
SentimentLib::Analysis::Strategies::FinancialDictStrategy
The first (BasicDictStrategy) uses a dictionary file (at lib/sentiment_lib/data/analysis/basic_dict/words.txt) mapping words to decimal weights between -1.0 and 1.0. It's analysis is the average of word weights for the supplied string.
The second (FinancialDictStrategy) uses the Loughran and McDonald Financial Sentiment Dictionary with +1 and -1 weights mapped to the dictionary's positive and negative words, respectively. It's analysis is the sum of word weights for the supplied string.
The API for adding your own analysis strategies is straightforward:
create a subclass of SentimentLib::Analysis::Strategy
implement the following public instance methods (all but first optional):
required:
mappings
returns a hash mapping token strings to weights
ex:
{
happy => 1.0,
sad => -1.0
}
The supplied strategies both load text files with
word-weight mappings and parse them into a hash.
optional:
normalize(str)
Normalize the string to be analyzed (applied before tokenization - see below).
Default is to downcase and strip all alphanumeric characters.
tokenize(str)
Defines custom method for converting the string being analyzed (str) into
tokens (default splits on white space).
weigh(tokens)
Define custom method for weighing the collected tokens of the string
(default is to average token weights).
You can then pass your strategy to new instances of SentimentLib::Analyzer:
analyzer = SentimentLib::Analyzer.new(:strategy => MyCustomStrategy.new)
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)FAQs
Unknown package
We found that sentiment_lib demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket is launching experimental protection for Chrome extensions, scanning for malware and risky permissions to prevent silent supply chain attacks.
Product
Add secure dependency scanning to Claude Desktop with Socket MCP, a one-click extension that keeps your coding conversations safe from malicious packages.
Product
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.