Socket
Socket
Sign inDemoInstall

senti-media

Package Overview
Dependencies
138
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    senti-media

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/


Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

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

FAQs

Last updated on 12 Mar 2018

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc