
Security News
New Website “Is It Really FOSS?” Tracks Transparency in Open Source Distribution Models
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.
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.
Security News
A new site reviews software projects to reveal if they’re truly FOSS, making complex licensing and distribution models easy to understand.
Security News
Astral unveils pyx, a Python-native package registry in beta, designed to speed installs, enhance security, and integrate deeply with uv.
Security News
The Latio podcast explores how static and runtime reachability help teams prioritize exploitable vulnerabilities and streamline AppSec workflows.