npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

senti-media

v1.0.7

Published

Senti is an extensible framework for sentiment analysis and NLP on media sources. It comes with providers for the [Twitter API](https://developer.twitter.com/) and [NewsAPI](https://newsapi.org). The framework uses [AWS Comprehend](https://aws.amazon.com/

Downloads

19

Readme

senti-media

Senti is an extensible framework for sentiment analysis and NLP on media sources. It comes with providers for the Twitter API and NewsAPI. The framework uses AWS Comprehend, along with compromise to extract key phrases and do sentiment analysis.

It is designed for use with node, and may have issues running in a browser.

Getting Started

Install with npm

npm install senti-media

Creating an instance of the Senti engine

const Engine = require('senti-media/engine');

const SentiEngine = new Engine({
    aws: {
        accessKeyId: '<YOUR_AWS_KEY>',
        secretAccessKey: '<YOUR_AWS_SECRET>',
        region: '<AWS_REGION>'
    }
});

Adding Providers

A provider is a media source that adheres to the pattern defined in the base Provider class (senti-media/providers/Provider). It exposes a search method that returns a Stream (senti-media/utilities/Stream). The Senti engine will call the Provider and listen for any updates before queuing them for analysis. Updates should be an array of object with each object containing a 'text' property, any other data will be retained but will not be used by the engine.

Senti comes with two pre-defined Providers: TwitterProvider and NewsProvider.

Providers can be passed in the configuration object, in the providers property, when the engine is instantiated or they can be added later using the provider method on the engine instance. Providers need to be added before the engine is started.

const { TwitterProvider, NewsProvider } = require('senti-media/providers');

SentiEngine.provider(new TwitterProvider({
    consumer_key: '<YOUR_TWITTER_CONSUMER_KEY>',
    consumer_secret: '<YOUR_TWITTER_CONSUMER_SECRET>'
    access_token_key: '<YOUR_TWITTER_ACCESS_TOKEN>'
    access_token_secret: '<YOUR_TWITTER_ACCESS_TOKEN_SECRET>'
}));

SentiEngine.provider(new NewsProvider({
    api_key: '<YOUR_NEWS_API_KEY>'
}));

Adding Middleware

Middleware functions run after the text analysis has been done and can apply postprocessing to the results. They are run in the order they are added to the engine, and can either be defined in the config passed to the engine on instantiation, in the middleware property, or can be added using the 'use' method on the engine. A middleware function should take two argument, the terms passed to the engine, and the results, and it should return the modified results object. It must be a syncronous function.

Senti supplies three simple middleware functions:

  • inference - this tries to determine to topic data by infering the context from previous text samples in the document
  • positivity - A helper to extract positive sentiment
  • negativity - A helper to extract negative sentiment
const { positivity, negativity, inference } = require('senti-media/middleware');

SentiEngine.use(inference());
SentiEngine.use(positivity());
SentiEngine.use(negativity());

Starting the engine

const SentiStream = SentiEngine.start('<search_term>', options);

SentiStream.take((update) => {
    console.log(update);
});

Starting the engine returns a Stream object. Conceptually the Stream object works similarly to a Promise, you can pass your update function to the take method on the Stream and it will receive updates for all media sources being run by the engine. Depending on the media type and the middleware used, this will include some metadata about the original source of the text.

A stream also has catch and finish methods which are called when exceptions occur or when the stream is terminated:

SentiStream.catch((exception) => {
    console.log(exception);
});

SentiStream.finish(() => {
    console.log('Stream terminated');
});

Author

John Millington

License

This project is licensed under the GNU General Public License - see the LICENSE.md file for details