airscore
Rate strings (tweets, texts and more) by your own custom criteria.
Install
$ npm install --save airscore
Usage
var Airscore = ; var tweet = ; // When setting a text, an internal array of words will automatically be parsed by airscoretweet; // You can also set the words directly yourself.// tweet.set('words', ['good', 'bad']); // Add the tones by which you want to rate your text // Every tone has a label/type and an array of words, each word has its own weight, the weight is optional and defaults to: 1tweet; tweet; // We can now call the method to get the individual scores.var score = tweet; // balance defaults to: 'fair'console; // returns: { positive: '0.18', negative: '0.08' } // The above example returns a 'fair' weight, counting every word of the text.// We could instead only take into account the positive and negative words.score = tweet;console; // returns: { positive: '4.50', negative: '2.00' } // Or in percent 'fair'score = tweet;console; // returns: { positive: '18.00%', negative: '8.00%' } // In percent 'strict'score = tweet;console; // returns: { positive: '69.23%', negative: '30.77%' } // You are in control of the decimals aswell. (percent or not..)score = tweet;console; // returns: { positive: '69.230769%', negative: '30.769231%' }
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