airscore
Rate strings (tweets, texts and more) by your own custom criteria.
Install
$ npm install --save airscore
Usage
var Airscore = require('airscore');
var tweet = new Airscore();
tweet.set('text', 'Some good text example with some negative and positive words. This is a well defined example. But it also contains some not so nice words');
tweet.addTone('positive', [
{ word: 'good', weight: 1 },
{ word: 'positive', weight: 1 },
{ word: 'well', weight: 1 },
{ word: 'nice', weight: 1.5 }
]);
tweet.addTone('negative', [
{ word: 'bad', weight: 1.5 },
{ word: 'not', weight: 1 },
{ word: 'negative', weight: 1 }
]);
var score = tweet.getScore();
console.log(score);
score = tweet.getScore({ balance: 'strict' });
console.log(score);
score = tweet.getScore({ percent: true });
console.log(score);
score = tweet.getScore({ balance: 'strict', percent: true });
console.log(score);
score = tweet.getScore({ balance: 'strict', percent: true, decimals: 6 });
console.log(score);
API
instance.set(key, value)
- Sets the 'key' to 'value' in the instances attributes.
instance.set('text', 'Hello im a text.')
- Sets the instances words array to: ['Hello', 'im', 'a', 'text']
instance.set('words', ['Hello', 'text'])
- Sets the instances words array to: ['Hello', 'text']
instance.add('words', 'here')
- Updates the instances words array to: ['Hello', 'text', 'here']
instace.addTone(string, [Array of indicators])
- Adds one tone to the instance
- A tone has many indicators
- An indicator has the 'word' its identified by and a weight, the weight defaults to: 1
- 1 indicator looks like that:
{
word: 'Hello',
weight: 1
}
instance.getScore(options)
- Gets the score
- Accepts the following options:
- balance: fair/strict defaults to: fair
- decimals: the decimals for every result
- percent: true or false defaults to: false
License
MIT © Linus Gubenis