Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
sentimentjs
Advanced tools
A sentiment analysis library for tweet objects and strings
This sentiment library is used in our Crowd Parser app, which analyzes Twitter sentiment. Check it out here:
Our goal with sentimentjs
is to improve upon other sentiment libraries by including "layers" that check for factors that other sentiment libraries might ignore or miss.
For example, our "emoticons layer" specifically looks for emoticons in a string or tweet and gauges sentiment based upon its findings.
All Layers:
Our base word lists come from renowned researchers Minqing Hu and Bing Liu, who authored this paper
Minqing Hu and Bing Liu. "Mining and Summarizing Customer Reviews." Proceedings of the ACM SIGKDD International Conference on Knowledge Discovery and Data Mining (KDD-2004), Aug 22-25, 2004, Seattle, Washington, USA
npm install sentimentjs
var sentiment = require('sentimentjs');
var arrayOfStrings = ['I love deep dish pizza :)', 'I hate brussel sprouts >:('];
var sentimentStringsAnalysis = sentiment.stringsArray(arrayOfStrings);
console.log(sentimentStringsAnalysis);
Running the above will return an object that has this format:
{
stringsWithAnalyses: [
{
text: 'I love deep dish pizza :)',
baseLayerResults: {
positiveWords: ['love'],
negativeWords: [],
score: 1
},
emoticonLayerResults: {
positiveWords: [':)'],
negativeWords: [],
score: 1
},
overallResults: {
score: 2
}
},
{
text: 'I hate brussel sprouts >:(',
baseLayerResults: {
positiveWords: [],
negativeWords: ['hate'],
score: -1
},
emoticonLayerResults: {
positiveWords: [],
negativeWords: ['>:('],
score: -1
},
overallResults: {
score: -2
}
}
]
}
To analyze tweet objects, you will need to have Twitter API credentials (keys, token, and secret). The README for our Crowd Parser app contains instructions for setting this up.
To set up the Twitter API with a Node server, this is how we do it:
var Twit = require('twit');
var T = new Twit({
consumer_key: 'ENTER YOURS HERE',
consumer_secret: 'ENTER YOURS HERE',
access_token: 'ENTER YOURS HERE',
access_token_secret: 'ENTER YOURS HERE'
});
var sentiment = require('sentimentjs');
T.get('search/tweets', {q: 'football', count: 50, result_type: 'mixed'}, function(err, data) {
var sentimentTweetsAnalysis = sentiment.tweetsArray(data);
console.log(sentimentTweetsAnalysis);
});
Running the above will return an object that has this format:
{
tweetsWithAnalyses: [
{
created_at: ** DATE CREATED ** ,
id: ** TWEET ID **,
text: ** TWEET TEXT **,
username: ** USERNAME **,
followers_count: ** NUMBER OF FOLLOWERS **,
baseLayerResults: {
positiveWords: [ ** POSITIVE WORDS ** ],
negativeWords: [ ** NEGATIVE WORDS ** ],
score: 1
},
emoticonLayerResults: {
positiveWords: [ ** POSITIVE EMOTOCONS ** ],
negativeWords: [ ** NEGATIVE WORDS ** ],
score: -2
},
slangLayerResults: {
// SAME FORMAT AS ABOVE
},
overallResults: {
score: -1
}
},
{
// TWEET #2
// ** SAME AS ABOVE **
}
]
}
First, navigate to the example
directory.
cd example
Next, install dependencies:
npm install -g bower
npm install
bower install
Next, start the server:
node server
Finally, open http://localhost:3000
in your browser.
To test, edit the array of strings in server.js
. You can also try to use the tweetsArray
method and enter an array of tweets.
var results = allLayersAnalysis.stringsArray(['I love dogs. They are wonderful! 😍 😍', 'I hate brussel sprouts. They are terrible. 😾', 'This is great! But also bad.']);
Change the above array for testing. Again, the sample output can be displayed like this:
There is a function in index.html
to highlight the positive and negative words in the text.
We welcome you to join us in creating a better sentiment library! Our library is still in an infant stage, so contributions would be greatly appreciated!
FAQs
> A sentiment analysis library for tweet objects and strings
The npm package sentimentjs receives a total of 0 weekly downloads. As such, sentimentjs popularity was classified as not popular.
We found that sentimentjs 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.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.